From c31d60951b2059fe0fa6690b7b7f7fe36992a4ca Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Sun, 6 Dec 2015 09:27:18 +0300 Subject: [PATCH] StringListWinget --- dlangui-monod-linux.sln | 4 +- .../spreadsheet/spreadsheet-monod-linux.dproj | 2 + src/dlangui/widgets/lists.d | 58 +++++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/dlangui-monod-linux.sln b/dlangui-monod-linux.sln index ba4bb0e6..ddb60713 100644 --- a/dlangui-monod-linux.sln +++ b/dlangui-monod-linux.sln @@ -80,8 +80,8 @@ Global {54BDE028-6064-4CA9-B6CA-4C0BEEE70F24}.UnittestMinimal|Any CPU.Build.0 = UnittestMinimal|x64 {54BDE028-6064-4CA9-B6CA-4C0BEEE70F24}.UnittestX11|Any CPU.ActiveCfg = UnittestX11|x64 {54BDE028-6064-4CA9-B6CA-4C0BEEE70F24}.UnittestX11|Any CPU.Build.0 = UnittestX11|x64 - {5BD82AA8-4026-44C2-8957-B4E2932542F0}.Debug|Any CPU.ActiveCfg = DebugX11|x64 - {5BD82AA8-4026-44C2-8957-B4E2932542F0}.Debug|Any CPU.Build.0 = DebugX11|x64 + {5BD82AA8-4026-44C2-8957-B4E2932542F0}.Debug|Any CPU.ActiveCfg = Debug|x64 + {5BD82AA8-4026-44C2-8957-B4E2932542F0}.Debug|Any CPU.Build.0 = Debug|x64 {5BD82AA8-4026-44C2-8957-B4E2932542F0}.DebugMinimal|Any CPU.ActiveCfg = DebugMinimal|x64 {5BD82AA8-4026-44C2-8957-B4E2932542F0}.DebugMinimal|Any CPU.Build.0 = DebugMinimal|x64 {5BD82AA8-4026-44C2-8957-B4E2932542F0}.DebugX11|Any CPU.ActiveCfg = DebugX11|x64 diff --git a/examples/spreadsheet/spreadsheet-monod-linux.dproj b/examples/spreadsheet/spreadsheet-monod-linux.dproj index 2a676cfe..89c668f1 100644 --- a/examples/spreadsheet/spreadsheet-monod-linux.dproj +++ b/examples/spreadsheet/spreadsheet-monod-linux.dproj @@ -218,6 +218,7 @@ Executable true 0 + obj/ReleaseX11 bin\UnittestX11 @@ -241,6 +242,7 @@ Executable true 0 + obj/UnittestX11 diff --git a/src/dlangui/widgets/lists.d b/src/dlangui/widgets/lists.d index f46f519a..812ae10e 100644 --- a/src/dlangui/widgets/lists.d +++ b/src/dlangui/widgets/lists.d @@ -1126,3 +1126,61 @@ class ListWidget : WidgetGroup, OnScrollHandler, OnAdapterChangeHandler { } +class StringListWidget : ListWidget { + this(string ID = null) { + super(ID); + styleId = STYLE_EDIT_BOX; + } + + this(string ID, string[] items) { + super(ID); + styleId = STYLE_EDIT_BOX; + adapter = new StringListAdapter(items); + } + + this(string ID, dstring[] items) { + super(ID); + styleId = STYLE_EDIT_BOX; + adapter = new StringListAdapter(items); + } + + this(string ID, StringListValue[] items) { + super(ID); + styleId = STYLE_EDIT_BOX; + adapter = new StringListAdapter(items); + } + + @property void items(string[] itemResourceIds) { + adapter = new StringListAdapter(itemResourceIds); + if(itemResourceIds.length > 0) { + selectedItemIndex = 0; + } + requestLayout(); + } + + @property void items(dstring[] items) { + adapter = new StringListAdapter(items); + if(items.length > 0) { + selectedItemIndex = 0; + } + requestLayout(); + } + + @property void items(StringListValue[] items) { + adapter = new StringListAdapter(items); + if(items.length > 0) { + selectedItemIndex = 0; + } + requestLayout(); + } + + /// get selected item as text + @property dstring selectedItem() { + if (_selectedItemIndex < 0 || _selectedItemIndex >= _adapter.itemCount) + return ""; + return (cast(StringListAdapter)adapter).items.get(_selectedItemIndex); + } +} + +import dlangui.widgets.metadata; +mixin(registerWidgets!(ListWidget, StringListWidget)());