From fbc30ab5c89a8cab47f04cf8db2e71580090a3c8 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Sun, 23 Mar 2014 14:24:10 +0400 Subject: [PATCH] scrollbar control, part 1 --- examples/example1/res/scrollbar_btn_down.png | Bin 0 -> 356 bytes examples/example1/res/scrollbar_btn_left.png | Bin 0 -> 359 bytes examples/example1/res/scrollbar_btn_right.png | Bin 0 -> 349 bytes examples/example1/res/scrollbar_btn_up.png | Bin 0 -> 356 bytes src/dlangui/widgets/controls.d | 53 +++++++++++++++++- src/dlangui/widgets/layouts.d | 5 -- src/dlangui/widgets/widget.d | 9 ++- 7 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 examples/example1/res/scrollbar_btn_down.png create mode 100644 examples/example1/res/scrollbar_btn_left.png create mode 100644 examples/example1/res/scrollbar_btn_right.png create mode 100644 examples/example1/res/scrollbar_btn_up.png diff --git a/examples/example1/res/scrollbar_btn_down.png b/examples/example1/res/scrollbar_btn_down.png new file mode 100644 index 0000000000000000000000000000000000000000..a0e7db766aca78397adb2620cbac0e049c6a64f0 GIT binary patch literal 356 zcmeAS@N?(olHy`uVBq!ia0vp@Ak4uAB#T}@sR2@q#X;^)4C~IxyaaMM3p^r=85p=b zL736}vTCc0uN&`1_BNHv*Vgq&b(#h zDZp_iO(5rg)!8Q@!Xg|;COO_!VA;CFe}eAq>OJ$*Z+&@px_ob#6Gx+c+avjf3{D(> zROVdU!`N|RhQv4d#+N&pcEsqF#I|?T81Wr=TlTod&fZs%<=b!D{^QM?bUGJh=*V1q z{naZpG-GY&V+mEIH)Ym6h7sABx69Zn-fz6NDMCl1i)pEdQO}Vu3=FYv^zz|^YboFyt=akR{07B}O AYybcN literal 0 HcmV?d00001 diff --git a/examples/example1/res/scrollbar_btn_left.png b/examples/example1/res/scrollbar_btn_left.png new file mode 100644 index 0000000000000000000000000000000000000000..8e9749ca5bcff3cd9aa1afc2e9728336978cc5aa GIT binary patch literal 359 zcmeAS@N?(olHy`uVBq!ia0vp@Ak4uAB#T}@sR2@q#X;^)4C~IxyaaMM3p^r=85p=b zL736}1B-M2y%<~r1FoA!PJ386&+wVJr;EnvN!MSy&RQnJ z*B%vk|C?l@B@Y3d%8G=Xq<1IWZ2zeAkZ3r#LIQ#rcE0J zPKRiU{CPU9sk_%qOe{(A?UoJ&mNQ|T+sk)-KV|;;tV+M4mu74Hu65kgQXhIQTXZuu zG9Xm6@9~ch`HH&NOBI*8TsD~y)FkkU-DHB^uYLWSbQD`0Zg2aae+X3t3qT}nKM85CPS<|{50;ZU5hjPv!brXa5K zpL_D{8Rrz2#J204p0MoY=lLcZa;4+ei$AhpTl&Sai1*F!zFq4C+Y}{|@9R6gw(+;< rYqmL`czc`VH^D1+-`+L-cSZUlU;9Ir_CgDw*BLxr{an^LB{Ts5L+Xn; literal 0 HcmV?d00001 diff --git a/examples/example1/res/scrollbar_btn_up.png b/examples/example1/res/scrollbar_btn_up.png new file mode 100644 index 0000000000000000000000000000000000000000..b591185298470f4a251e78600c7f4f0eb50feea7 GIT binary patch literal 356 zcmeAS@N?(olHy`uVBq!ia0vp@Ak4uAB#T}@sR2@q#X;^)4C~IxyaaMM3p^r=85p=b zL736}vtPZOtH~@vddAc};Xq=xrX=7hgfPm|H38_pTQB!$G zMb4@5z8bzJW-P+eLa*FCIWnBTM7?~Z7xCuhy*qa*CtD{^I>Ix_V6$cCRrAA6`zwVV z?tk~b)bDv|cX4QFN~Bxt_4+N_Gp*_aMPl^C4;d`c@jmz5IPII^I`)LLp2sI%mK?Hl zmpSed=n{Kf#P#6YGUdKxoAb;ER9;r?EwYf2XlqpQn&IImNGb`Azy#VPo?2Yu@cJ-^(78 za(3NW+WK!@_4-HJ6D*gVoGH1j#O;2>NB()b`P(P_cXqM?h5&=7tDnm{r-UW|vw@OS literal 0 HcmV?d00001 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