TreeWidget, part 1

This commit is contained in:
Vadim Lopatin 2014-11-28 11:35:26 +03:00
parent 54c67d9a0b
commit 257496b6f8
6 changed files with 176 additions and 57 deletions

View File

@ -89,7 +89,6 @@
<resfile />
<exefile>$(OutDir)\$(ProjectName).lib</exefile>
<useStdLibPath>1</useStdLibPath>
<cRuntime>2</cRuntime>
<additionalOptions />
<preBuildCommand />
<postBuildCommand />
@ -184,7 +183,6 @@
<resfile />
<exefile>$(OutDir)\$(ProjectName).lib</exefile>
<useStdLibPath>1</useStdLibPath>
<cRuntime>1</cRuntime>
<additionalOptions />
<preBuildCommand />
<postBuildCommand />
@ -337,8 +335,10 @@
<File path="src\dlangui\widgets\lists.d" />
<File path="src\dlangui\widgets\menu.d" />
<File path="src\dlangui\widgets\popup.d" />
<File path="src\dlangui\widgets\scroll.d" />
<File path="src\dlangui\widgets\styles.d" />
<File path="src\dlangui\widgets\tabs.d" />
<File path="src\dlangui\widgets\tree.d" />
<File path="src\dlangui\widgets\widget.d" />
</Folder>
<File path="src\dlangui\all.d" />

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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();
}
}
}

View File

@ -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);
}
}