From 1b9933447b74b8346a92c60fae457a90204a6183 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Mon, 26 May 2014 14:52:14 +0400 Subject: [PATCH] grid widget, continue --- src/dlangui/widgets/grid.d | 106 +++++++++++++++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 5 deletions(-) diff --git a/src/dlangui/widgets/grid.d b/src/dlangui/widgets/grid.d index d9176508..13ea833a 100644 --- a/src/dlangui/widgets/grid.d +++ b/src/dlangui/widgets/grid.d @@ -82,6 +82,107 @@ class StringGridAdapter : GridAdapter { Widget colHeader(int col) { return null; } } +class GridWidgetBase : WidgetGroup { + @property abstract int cols(); + @property abstract GridWidgetBase cols(int c); + @property abstract int rows(); + @property abstract GridWidgetBase rows(int r); + /// flag to enable column headers + @property abstract bool showColHeaders(); + @property abstract GridWidgetBase showColHeaders(bool show); + /// flag to enable row headers + @property abstract bool showRowHeaders(); + @property abstract GridWidgetBase showRowHeaders(bool show); + this(string ID) { + super(ID); + } +} + +/** + * Grid view with string data shown. All rows are of the same height. + */ +class StringGridWidget : GridWidgetBase { + protected int _cols; + protected int _rows; + protected dstring[][] _data; + protected dstring[] _rowTitles; + protected dstring[] _colTitles; + protected bool _showColHeaders; + protected bool _showRowHeaders; + this(string ID) { + super(ID); + } + @property override int cols() { + return _cols; + } + @property override GridWidgetBase cols(int c) { + resize(c, _rows); + return this; + } + @property override int rows() { + return _rows; + } + @property override GridWidgetBase rows(int r) { + resize(_cols, r); + return this; + } + /// get cell text + dstring cellText(int col, int row) { + return _data[row][col]; + } + /// flag to enable column headers + @property override bool showColHeaders() { + return _showColHeaders; + } + @property override GridWidgetBase showColHeaders(bool show) { + _showColHeaders = show; + return this; + } + /// flag to enable row headers + @property override bool showRowHeaders() { + return _showRowHeaders; + } + @property override GridWidgetBase showRowHeaders(bool show) { + _showRowHeaders = show; + return this; + } + /// set cell text + GridWidgetBase setCellText(int col, int row, dstring text) { + _data[row][col] = text; + return this; + } + /// set new size + void resize(int cols, int rows) { + if (cols == _cols && rows == _rows) + return; + _cols = cols; + _rows = rows; + _data.length = _rows; + for (int y = 0; y < _rows; y++) + _data[y].length = _cols; + _colTitles.length = _cols; + _rowTitles.length = _rows; + } + /// returns row header title + dstring rowTitle(int row) { + return _rowTitles[row]; + } + /// set row header title + GridWidgetBase setRowTitle(int row, dstring title) { + _rowTitles[row] = title; + return this; + } + /// returns row header title + dstring colTitle(int col) { + return _colTitles[col]; + } + /// set col header title + GridWidgetBase setColTitle(int col, dstring title) { + _colTitles[col] = title; + return this; + } +} + /** * Multicolumn multirow view. */ @@ -115,8 +216,3 @@ class GridWidget : WidgetGroup { } } -/** - * Grid view with string data shown. All rows are of the same height. - */ -class StringGridWidget : GridWidget { -}