diff --git a/dlanguilib.visualdproj b/dlanguilib.visualdproj
index 4495839e..058132fa 100644
--- a/dlanguilib.visualdproj
+++ b/dlanguilib.visualdproj
@@ -89,7 +89,6 @@
$(OutDir)\$(ProjectName).lib
1
- 2
@@ -184,7 +183,6 @@
$(OutDir)\$(ProjectName).lib
1
- 1
@@ -337,8 +335,10 @@
+
+
diff --git a/examples/example1/src/main.d b/examples/example1/src/main.d
index 06c9018d..29b89759 100644
--- a/examples/example1/src/main.d
+++ b/examples/example1/src/main.d
@@ -571,6 +571,13 @@ extern (C) int UIAppMain(string[] args) {
grid.autoFit();
tabs.addTab(grid, "Grid"d);
+ //==========================================================================
+ // tree view example
+ TreeWidget tree = new TreeWidget("TREE1");
+ tree.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
+ tabs.addTab(tree, "Tree"d);
+
+
//==========================================================================
contentLayout.addChild(tabs);
diff --git a/src/dlangui/all.d b/src/dlangui/all.d
index dfb3cfbe..c89d0d29 100644
--- a/src/dlangui/all.d
+++ b/src/dlangui/all.d
@@ -29,10 +29,10 @@ extern (C) int UIAppMain(string[] args) {
// create window
Window window = Platform.instance.createWindow("My Window", null);
- // create some widget to show in window
+ // create some widget to show in window
window.mainWidget = (new Button()).text("Hello world"d);
- // show window
- window.show();
+ // show window
+ window.show();
// run message loop
return Platform.instance.enterMessageLoop();
}
@@ -58,5 +58,6 @@ public import dlangui.widgets.tabs;
public import dlangui.widgets.menu;
public import dlangui.widgets.editors;
public import dlangui.widgets.grid;
+public import dlangui.widgets.tree;
public import dlangui.graphics.fonts;
public import dlangui.core.i18n;
diff --git a/src/dlangui/widgets/grid.d b/src/dlangui/widgets/grid.d
index 076a1c70..8b05f44b 100644
--- a/src/dlangui/widgets/grid.d
+++ b/src/dlangui/widgets/grid.d
@@ -2,6 +2,7 @@ module dlangui.widgets.grid;
import dlangui.widgets.widget;
import dlangui.widgets.controls;
+import dlangui.widgets.scroll;
import std.conv;
/**
@@ -149,7 +150,7 @@ enum GridActions : int {
SelectDocumentEnd,
}
-class GridWidgetBase : WidgetGroup, OnScrollHandler {
+class GridWidgetBase : ScrollWidget {
/// column count (including header columns and fixed columns)
protected int _cols;
/// row count (including header rows and fixed rows)
@@ -178,10 +179,6 @@ class GridWidgetBase : WidgetGroup, OnScrollHandler {
protected int _col;
/// selected cell row
protected int _row;
- /// vertical scrollbar control
- protected ScrollBar _vscrollbar;
- /// horizontal scrollbar control
- protected ScrollBar _hscrollbar;
/// inner area, excluding additional controls like scrollbars
protected Rect _clientRect;
/// when true, allows to select only whole row
@@ -378,19 +375,24 @@ class GridWidgetBase : WidgetGroup, OnScrollHandler {
return false;
}
+ /// update horizontal scrollbar widget position
+ override protected void updateHScrollBar() {
+ _hscrollbar.setRange(0, _fullScrollableArea.width);
+ _hscrollbar.pageSize(_visibleScrollableArea.width);
+ _hscrollbar.position(_visibleScrollableArea.left - _fullScrollableArea.left);
+ }
+
+ /// update verticat scrollbar widget position
+ override protected void updateVScrollBar() {
+ _vscrollbar.setRange(0, _fullScrollableArea.height);
+ _vscrollbar.pageSize(_visibleScrollableArea.height);
+ _vscrollbar.position(_visibleScrollableArea.top - _fullScrollableArea.top);
+ }
+
/// update scrollbar positions
- protected void updateScrollBars() {
+ override protected void updateScrollBars() {
calcScrollableAreaPos();
- if (_hscrollbar) {
- _hscrollbar.setRange(0, _fullScrollableArea.width);
- _hscrollbar.pageSize(_visibleScrollableArea.width);
- _hscrollbar.position(_visibleScrollableArea.left - _fullScrollableArea.left);
- }
- if (_vscrollbar) {
- _vscrollbar.setRange(0, _fullScrollableArea.height);
- _vscrollbar.pageSize(_visibleScrollableArea.height);
- _vscrollbar.position(_visibleScrollableArea.top - _fullScrollableArea.top);
- }
+ super.updateScrollBars();
}
/// column by X, ignoring scroll position
@@ -455,36 +457,36 @@ class GridWidgetBase : WidgetGroup, OnScrollHandler {
return oldx != _scrollCol || oldy != _scrollRow;
}
- /// handle scroll event
- override bool onScrollEvent(AbstractSlider source, ScrollEvent event) {
- if (source.compareId("hscrollbar")) {
- if (event.action == ScrollAction.SliderMoved || event.action == ScrollAction.SliderReleased) {
- int col = colByAbsoluteX(event.position + _fullScrollableArea.left);
- scrollTo(col, _scrollRow + _headerRows + _fixedRows);
- } else if (event.action == ScrollAction.PageUp) {
- handleAction(new Action(GridActions.ScrollPageLeft));
- } else if (event.action == ScrollAction.PageDown) {
- handleAction(new Action(GridActions.ScrollPageRight));
- } else if (event.action == ScrollAction.LineUp) {
- handleAction(new Action(GridActions.ScrollLeft));
- } else if (event.action == ScrollAction.LineDown) {
- handleAction(new Action(GridActions.ScrollRight));
- }
- return true;
- } else if (source.compareId("vscrollbar")) {
- if (event.action == ScrollAction.SliderMoved || event.action == ScrollAction.SliderReleased) {
- int row = rowByAbsoluteY(event.position + _fullScrollableArea.top);
- scrollTo(_scrollCol + _headerCols + _fixedCols, row);
- } else if (event.action == ScrollAction.PageUp) {
- handleAction(new Action(GridActions.ScrollPageUp));
- } else if (event.action == ScrollAction.PageDown) {
- handleAction(new Action(GridActions.ScrollPageDown));
- } else if (event.action == ScrollAction.LineUp) {
- handleAction(new Action(GridActions.ScrollUp));
- } else if (event.action == ScrollAction.LineDown) {
- handleAction(new Action(GridActions.ScrollDown));
- }
- return true;
+ /// process horizontal scrollbar event
+ override bool onHScroll(ScrollEvent event) {
+ if (event.action == ScrollAction.SliderMoved || event.action == ScrollAction.SliderReleased) {
+ int col = colByAbsoluteX(event.position + _fullScrollableArea.left);
+ scrollTo(col, _scrollRow + _headerRows + _fixedRows);
+ } else if (event.action == ScrollAction.PageUp) {
+ handleAction(new Action(GridActions.ScrollPageLeft));
+ } else if (event.action == ScrollAction.PageDown) {
+ handleAction(new Action(GridActions.ScrollPageRight));
+ } else if (event.action == ScrollAction.LineUp) {
+ handleAction(new Action(GridActions.ScrollLeft));
+ } else if (event.action == ScrollAction.LineDown) {
+ handleAction(new Action(GridActions.ScrollRight));
+ }
+ return true;
+ }
+
+ /// process vertical scrollbar event
+ override bool onVScroll(ScrollEvent event) {
+ if (event.action == ScrollAction.SliderMoved || event.action == ScrollAction.SliderReleased) {
+ int row = rowByAbsoluteY(event.position + _fullScrollableArea.top);
+ scrollTo(_scrollCol + _headerCols + _fixedCols, row);
+ } else if (event.action == ScrollAction.PageUp) {
+ handleAction(new Action(GridActions.ScrollPageUp));
+ } else if (event.action == ScrollAction.PageDown) {
+ handleAction(new Action(GridActions.ScrollPageDown));
+ } else if (event.action == ScrollAction.LineUp) {
+ handleAction(new Action(GridActions.ScrollUp));
+ } else if (event.action == ScrollAction.LineDown) {
+ handleAction(new Action(GridActions.ScrollDown));
}
return true;
}
@@ -1051,12 +1053,6 @@ class GridWidgetBase : WidgetGroup, OnScrollHandler {
this(string ID = null) {
super(ID);
- _vscrollbar = new ScrollBar("vscrollbar", Orientation.Vertical);
- _hscrollbar = new ScrollBar("hscrollbar", Orientation.Horizontal);
- _hscrollbar.onScrollEventListener = this;
- _vscrollbar.onScrollEventListener = this;
- addChild(_vscrollbar);
- addChild(_hscrollbar);
_headerCols = 1;
_headerRows = 1;
_defRowHeight = 20;
diff --git a/src/dlangui/widgets/scroll.d b/src/dlangui/widgets/scroll.d
new file mode 100644
index 00000000..7d5a2582
--- /dev/null
+++ b/src/dlangui/widgets/scroll.d
@@ -0,0 +1,64 @@
+module dlangui.widgets.scroll;
+
+import dlangui.widgets.widget;
+import dlangui.widgets.controls;
+import std.conv;
+
+class ScrollWidget : WidgetGroup, OnScrollHandler {
+ /// vertical scrollbar control
+ protected ScrollBar _vscrollbar;
+ /// horizontal scrollbar control
+ protected ScrollBar _hscrollbar;
+
+ this(string ID = null) {
+ super(ID);
+ _vscrollbar = new ScrollBar("vscrollbar", Orientation.Vertical);
+ _hscrollbar = new ScrollBar("hscrollbar", Orientation.Horizontal);
+ _hscrollbar.onScrollEventListener = this;
+ _vscrollbar.onScrollEventListener = this;
+ addChild(_vscrollbar);
+ addChild(_hscrollbar);
+ }
+
+ /// process horizontal scrollbar event
+ bool onHScroll(ScrollEvent event) {
+ return true;
+ }
+
+ /// process vertical scrollbar event
+ bool onVScroll(ScrollEvent event) {
+ return true;
+ }
+
+ /// handle scroll event
+ override bool onScrollEvent(AbstractSlider source, ScrollEvent event) {
+ if (source.compareId("hscrollbar")) {
+ return onHScroll(event);
+ } else if (source.compareId("vscrollbar")) {
+ return onVScroll(event);
+ }
+ return true;
+ }
+
+ /// update horizontal scrollbar widget position
+ protected void updateHScrollBar() {
+ // override it
+ }
+
+ /// update verticat scrollbar widget position
+ protected void updateVScrollBar() {
+ // override it
+ }
+
+ /// update scrollbar positions
+ protected void updateScrollBars() {
+ if (_hscrollbar) {
+ updateHScrollBar();
+ }
+ if (_vscrollbar) {
+ updateVScrollBar();
+ }
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/dlangui/widgets/tree.d b/src/dlangui/widgets/tree.d
new file mode 100644
index 00000000..d88bd37e
--- /dev/null
+++ b/src/dlangui/widgets/tree.d
@@ -0,0 +1,51 @@
+module dlangui.widgets.tree;
+
+import dlangui.widgets.widget;
+import dlangui.widgets.controls;
+import dlangui.widgets.scroll;
+import std.conv;
+
+class TreeWidgetBase : ScrollWidget {
+ /// vertical scrollbar control
+ protected ScrollBar _vscrollbar;
+ /// horizontal scrollbar control
+ protected ScrollBar _hscrollbar;
+
+ this(string ID = null) {
+ super(ID);
+ _vscrollbar = new ScrollBar("vscrollbar", Orientation.Vertical);
+ _hscrollbar = new ScrollBar("hscrollbar", Orientation.Horizontal);
+ _hscrollbar.onScrollEventListener = this;
+ _vscrollbar.onScrollEventListener = this;
+ addChild(_vscrollbar);
+ addChild(_hscrollbar);
+ }
+
+ /// process horizontal scrollbar event
+ override bool onHScroll(ScrollEvent event) {
+ return true;
+ }
+
+ /// process vertical scrollbar event
+ override bool onVScroll(ScrollEvent event) {
+ return true;
+ }
+
+ /// update horizontal scrollbar widget position
+ override protected void updateHScrollBar() {
+ // override it
+ }
+
+ /// update verticat scrollbar widget position
+ override protected void updateVScrollBar() {
+ // override it
+ }
+
+
+}
+
+class TreeWidget : ScrollWidget {
+ this(string ID = null) {
+ super(ID);
+ }
+}