mirror of https://github.com/buggins/dlangui.git
TreeWidget, part 1
This commit is contained in:
parent
54c67d9a0b
commit
257496b6f8
|
@ -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" />
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 scrollbar positions
|
||||
protected void updateScrollBars() {
|
||||
calcScrollableAreaPos();
|
||||
if (_hscrollbar) {
|
||||
/// update horizontal scrollbar widget position
|
||||
override protected void updateHScrollBar() {
|
||||
_hscrollbar.setRange(0, _fullScrollableArea.width);
|
||||
_hscrollbar.pageSize(_visibleScrollableArea.width);
|
||||
_hscrollbar.position(_visibleScrollableArea.left - _fullScrollableArea.left);
|
||||
}
|
||||
if (_vscrollbar) {
|
||||
|
||||
/// 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
|
||||
override protected void updateScrollBars() {
|
||||
calcScrollableAreaPos();
|
||||
super.updateScrollBars();
|
||||
}
|
||||
|
||||
/// column by X, ignoring scroll position
|
||||
|
@ -455,9 +457,8 @@ class GridWidgetBase : WidgetGroup, OnScrollHandler {
|
|||
return oldx != _scrollCol || oldy != _scrollRow;
|
||||
}
|
||||
|
||||
/// handle scroll event
|
||||
override bool onScrollEvent(AbstractSlider source, ScrollEvent event) {
|
||||
if (source.compareId("hscrollbar")) {
|
||||
/// 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);
|
||||
|
@ -471,7 +472,10 @@ class GridWidgetBase : WidgetGroup, OnScrollHandler {
|
|||
handleAction(new Action(GridActions.ScrollRight));
|
||||
}
|
||||
return true;
|
||||
} else if (source.compareId("vscrollbar")) {
|
||||
}
|
||||
|
||||
/// 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);
|
||||
|
@ -486,8 +490,6 @@ class GridWidgetBase : WidgetGroup, OnScrollHandler {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// ensure that cell is visible (scroll if necessary)
|
||||
void makeCellVisible(int col, int row) {
|
||||
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue