mirror of https://github.com/buggins/dlangui.git
grid widget, continue
This commit is contained in:
parent
05c33f9e59
commit
1b9933447b
|
@ -82,6 +82,107 @@ class StringGridAdapter : GridAdapter {
|
||||||
Widget colHeader(int col) { return null; }
|
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.
|
* 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 {
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue