From 48242a1af782b5856f07b94e1079eee78bcd8777 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Mon, 31 Mar 2014 18:22:29 +0400 Subject: [PATCH] tab widget --- dlanguilib.visualdproj | 1 + examples/example1/main.d | 12 ++++++++++++ examples/example1/res/close.png | Bin 0 -> 347 bytes examples/example1/res/tab_more.png | Bin 0 -> 333 bytes src/dlangui/all.d | 1 + src/dlangui/core/i18n.d | 19 ++++++++++++++++--- src/dlangui/widgets/controls.d | 12 ++++++------ src/dlangui/widgets/layouts.d | 2 +- src/dlangui/widgets/widget.d | 14 +++++++++++++- 9 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 examples/example1/res/close.png create mode 100644 examples/example1/res/tab_more.png diff --git a/dlanguilib.visualdproj b/dlanguilib.visualdproj index c53bae16..94f5d5d5 100644 --- a/dlanguilib.visualdproj +++ b/dlanguilib.visualdproj @@ -328,6 +328,7 @@ + diff --git a/examples/example1/main.d b/examples/example1/main.d index 8f2901d6..a0924eb3 100644 --- a/examples/example1/main.d +++ b/examples/example1/main.d @@ -48,6 +48,18 @@ extern (C) int UIAppMain(string[] args) { static if (true) { LinearLayout layout = new LinearLayout(); + + TabWidget tabs = new TabWidget("TABS"); + tabs.addTab("id1", "Tab 1"d); + tabs.addTab("id2", "Tab 2 label"d); + tabs.addTab("id3", "Tab 3 label"d); + tabs.addTab("id4", "Tab 4 label"d); + tabs.addTab("id5", "Tab 5 label"d); + tabs.addTab("id6", "Tab 6 label"d); + tabs.addTab("id7", "Tab 7 label"d); + tabs.addTab("id8", "Tab 8 label"d); + layout.addChild(tabs); + layout.addChild((new TextWidget()).textColor(0x00802000).text("Text widget 0")); layout.addChild((new TextWidget()).textColor(0x40FF4000).text("Text widget")); layout.addChild((new Button("BTN1")).textResource("EXIT")); //.textColor(0x40FF4000) diff --git a/examples/example1/res/close.png b/examples/example1/res/close.png new file mode 100644 index 0000000000000000000000000000000000000000..1aca4b793fc8008533b4f7ea0466c906f385b5f2 GIT binary patch literal 347 zcmeAS@N?(olHy`uVBq!ia0vp^{22>S z4={E+nQaFWEGuwK2hw1@49POW!az>4r;B5V#O36K1-D+2>JCl_554Y~O#nQ4`{HJHo)nF!P%39=zLKdq!Zu_%?n jF(p4KRlzeiF+DXXH8G{K@MNkDP!WTttDnm{r-UW|<7i~X literal 0 HcmV?d00001 diff --git a/examples/example1/res/tab_more.png b/examples/example1/res/tab_more.png new file mode 100644 index 0000000000000000000000000000000000000000..badc2a6a246f566b9b56ebb7d690cc7085481fd5 GIT binary patch literal 333 zcmeAS@N?(olHy`uVBq!ia0vp@Ak4uAB#T}@sR2@q#X;^)4C~IxyaaMM3p^r=85p=b zL736}HMk_TBssV-Wd%8G=Xq-<@P+&GNGB7ZRsPSa5 z8yg?~|IE&A*6lf4a^r>~?Z=l3-X+wsFf$)EPg`;0{BwT3HDc2@nj|GY4RO8x;qmX= zZ=dsBVFj90)AqX)XaW#FlxJpUZeAIDTg{A*F@8qde0#eb%gyUg$!ncIa^S!Rez7V8 z#$}g(uliH>|JR;*Ks^typFb~s?#=2?uI3Wr37bmh?+{rfP~CN48E5C;{zfSVhNIqY VHMY+2`+;6%@O1TaS?83{1OVpNgdqR` literal 0 HcmV?d00001 diff --git a/src/dlangui/all.d b/src/dlangui/all.d index aed7e822..5d271c0b 100644 --- a/src/dlangui/all.d +++ b/src/dlangui/all.d @@ -8,5 +8,6 @@ public import dlangui.widgets.widget; public import dlangui.widgets.controls; public import dlangui.widgets.layouts; public import dlangui.widgets.lists; +public import dlangui.widgets.tabs; public import dlangui.graphics.fonts; public import dlangui.core.i18n; diff --git a/src/dlangui/core/i18n.d b/src/dlangui/core/i18n.d index fa9b2e01..ee90466d 100644 --- a/src/dlangui/core/i18n.d +++ b/src/dlangui/core/i18n.d @@ -6,9 +6,21 @@ import std.utf; /// container for UI string - either raw value or string resource ID struct UIString { /// if not null, use it, otherwise lookup by id - dstring _value; + private dstring _value; /// id to find value in translator - string _id; + private string _id; + + /// create string with i18n resource id + this(string id) { + _id = id; + } + /// create string with raw value + this(dstring value) { + _value = value; + } + + + @property string id() const { return _id; } @property void id(string ID) { _id = ID; @@ -145,13 +157,14 @@ class UIStringList { } return count > 0; } + /// load strings from file (utf8, id=value lines) bool load(string filename) { import std.stream; import std.file; try { Log.d("Loading string resources from file ", filename); - if (!exists(filename) && isFile(filename)) { + if (!exists(filename) || !isFile(filename)) { Log.e("File does not exist: ", filename); return false; } diff --git a/src/dlangui/widgets/controls.d b/src/dlangui/widgets/controls.d index 51ee98b6..0891a03e 100644 --- a/src/dlangui/widgets/controls.d +++ b/src/dlangui/widgets/controls.d @@ -19,6 +19,12 @@ class TextWidget : Widget { requestLayout(); return this; } + /// set text to show + @property Widget text(ref UIString s) { + _text = s; + requestLayout(); + return this; + } /// set text resource ID to show @property Widget textResource(string s) { _text = s; @@ -575,9 +581,3 @@ class ScrollBar : AbstractSlider, OnClickHandler { } } -class TabItem { -} - -class TabWidget { - -} diff --git a/src/dlangui/widgets/layouts.d b/src/dlangui/widgets/layouts.d index 7b1cf9ca..9c716918 100644 --- a/src/dlangui/widgets/layouts.d +++ b/src/dlangui/widgets/layouts.d @@ -1,6 +1,6 @@ module dlangui.widgets.layouts; -import dlangui.widgets.widget; +public import dlangui.widgets.widget; /// helper for layouts struct LayoutItem { diff --git a/src/dlangui/widgets/widget.d b/src/dlangui/widgets/widget.d index df8f679b..ea389697 100644 --- a/src/dlangui/widgets/widget.d +++ b/src/dlangui/widgets/widget.d @@ -536,7 +536,7 @@ struct WidgetList { protected Widget[] _list; protected int _count; /// returns count of items - @property int count() { return _count; } + @property int count() const { return _count; } /// get item by index Widget get(int index) { assert(index >= 0 && index < _count, "child index out of range"); @@ -549,6 +549,18 @@ struct WidgetList { _list[_count++] = item; return item; } + /// add item to list + Widget insert(Widget item, int index = -1) { + if (index > _count || index < 0) + index = _count; + if (_list.length <= _count) // resize + _list.length = _list.length < 4 ? 4 : _list.length * 2; + for (int i = _count; i > index; i--) + _list[i] = _list[i - 1]; + _list[index] = item; + _count++; + return item; + } /// find child index for item, return -1 if not found int indexOf(Widget item) { for (int i = 0; i < _count; i++)