diff --git a/examples/example1/res/scrollbar_btn_down.png b/examples/example1/res/scrollbar_btn_down.png new file mode 100644 index 00000000..a0e7db76 Binary files /dev/null and b/examples/example1/res/scrollbar_btn_down.png differ diff --git a/examples/example1/res/scrollbar_btn_left.png b/examples/example1/res/scrollbar_btn_left.png new file mode 100644 index 00000000..8e9749ca Binary files /dev/null and b/examples/example1/res/scrollbar_btn_left.png differ diff --git a/examples/example1/res/scrollbar_btn_right.png b/examples/example1/res/scrollbar_btn_right.png new file mode 100644 index 00000000..1cfc95f6 Binary files /dev/null and b/examples/example1/res/scrollbar_btn_right.png differ diff --git a/examples/example1/res/scrollbar_btn_up.png b/examples/example1/res/scrollbar_btn_up.png new file mode 100644 index 00000000..b5911852 Binary files /dev/null and b/examples/example1/res/scrollbar_btn_up.png differ diff --git a/src/dlangui/widgets/controls.d b/src/dlangui/widgets/controls.d index b1c60e69..873ef4fc 100644 --- a/src/dlangui/widgets/controls.d +++ b/src/dlangui/widgets/controls.d @@ -53,8 +53,9 @@ class ImageWidget : Widget { protected string _drawableId; protected DrawableRef _drawable; - this(string ID = null) { + this(string ID = null, string drawableId = null) { super(ID); + _drawableId = drawableId; } /// get drawable image id @@ -110,6 +111,14 @@ class ImageWidget : Widget { } } +/// button with image only +class ImageButton : ImageWidget { + this(string ID = null, string drawableId = null) { + super(ID); + styleId = "BUTTON"; + } +} + class Button : Widget { protected dstring _text; override @property dstring text() { return _text; } @@ -118,6 +127,7 @@ class Button : Widget { super(ID); styleId = "BUTTON"; } + override void measure(int parentWidth, int parentHeight) { FontRef font = font(); Point sz = font.textSize(text); @@ -138,3 +148,44 @@ class Button : Widget { } } + +/// scroll bar - either vertical or horizontal +class ScrollBar : WidgetGroup { + protected ImageButton _btnBack; + protected ImageButton _btnForward; + + protected Orientation _orientation = Orientation.Vertical; + /// returns scrollbar orientation (Vertical, Horizontal) + @property Orientation orientation() { return _orientation; } + /// sets scrollbar orientation + @property ScrollBar orientation(Orientation value) { + if (_orientation != value) { + _orientation = value; + _btnBack.drawableId = _orientation == Orientation.Vertical ? "scrollbar_btn_up" : "scrollbar_btn_left"; + _btnForward.drawableId = _orientation == Orientation.Vertical ? "scrollbar_btn_down" : "scrollbar_btn_right"; + requestLayout(); + } + return this; + } + + this(string ID = null, Orientation orientation = Orientation.Vertical) { + super(ID); + styleId = "BUTTON"; + _orientation = orientation; + _btnBack = new ImageButton("BACK", _orientation == Orientation.Vertical ? "scrollbar_btn_up" : "scrollbar_btn_left"); + _btnForward = new ImageButton("FORWARD", _orientation == Orientation.Vertical ? "scrollbar_btn_down" : "scrollbar_btn_right"); + } + + override void measure(int parentWidth, int parentHeight) { + Point sz; + _btnBack.measure(parentWidth, parentHeight); + _btnForward.measure(parentWidth, parentHeight); + if (_orientation == Orientation.Vertical) { + // vertical + } else { + // horizontal + + } + measuredContent(parentWidth, parentHeight, sz.x, sz.y); + } +} diff --git a/src/dlangui/widgets/layouts.d b/src/dlangui/widgets/layouts.d index a7ff553d..7b1cf9ca 100644 --- a/src/dlangui/widgets/layouts.d +++ b/src/dlangui/widgets/layouts.d @@ -2,11 +2,6 @@ module dlangui.widgets.layouts; import dlangui.widgets.widget; -enum Orientation : ubyte { - Vertical, - Horizontal -} - /// helper for layouts struct LayoutItem { Widget _widget; diff --git a/src/dlangui/widgets/widget.d b/src/dlangui/widgets/widget.d index a46cd903..0fb89841 100644 --- a/src/dlangui/widgets/widget.d +++ b/src/dlangui/widgets/widget.d @@ -26,6 +26,11 @@ enum Visibility : ubyte { Gone } +enum Orientation : ubyte { + Vertical, + Horizontal +} + class Widget { /// widget id protected string _id; @@ -480,7 +485,7 @@ class Widget { /// returns parent widget, null for top level widget @property Widget parent() { return _parent; } /// sets parent for widget - @property void parent(Widget parent) { _parent = parent; } + @property Widget parent(Widget parent) { _parent = parent; return this; } /// returns window (if widget or its parent is attached to window) @property Window window() { Widget p = this; @@ -558,7 +563,7 @@ class WidgetGroup : Widget { /// returns child by index override Widget child(int index) { return _children.get(index); } /// adds child, returns added item - override Widget addChild(Widget item) { return _children.add(item); } + override Widget addChild(Widget item) { return _children.add(item).parent(this); } /// removes child, returns added item override Widget removeChild(int index) { return _children.remove(index); } /// returns index of widget in child list, -1 if passed widget is not a child of this widget