mirror of https://github.com/adamdruppe/arsd.git
Add list option tag and getSelection
This commit is contained in:
parent
74f064f0bb
commit
cd927c156f
18
minigui.d
18
minigui.d
|
@ -4562,6 +4562,7 @@ class ListWidget : ListWidgetBase {
|
||||||
static struct Option {
|
static struct Option {
|
||||||
string label;
|
string label;
|
||||||
bool selected;
|
bool selected;
|
||||||
|
ptrdiff_t tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
/++
|
/++
|
||||||
|
@ -4580,6 +4581,19 @@ class ListWidget : ListWidgetBase {
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/++
|
||||||
|
Gets the index of the selected item. In case of multi select, the index of the first selected item is returned.
|
||||||
|
Returns -1 if nothing is selected.
|
||||||
|
+/
|
||||||
|
int getSelection()
|
||||||
|
{
|
||||||
|
foreach(i, opt; options) {
|
||||||
|
if (opt.selected)
|
||||||
|
return cast(int) i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
version(custom_widgets)
|
version(custom_widgets)
|
||||||
override void defaultEventHandler_click(ClickEvent event) {
|
override void defaultEventHandler_click(ClickEvent event) {
|
||||||
this.focus();
|
this.focus();
|
||||||
|
@ -4646,8 +4660,8 @@ class ListWidget : ListWidgetBase {
|
||||||
mixin OverrideStyle!Style;
|
mixin OverrideStyle!Style;
|
||||||
//mixin Padding!q{2};
|
//mixin Padding!q{2};
|
||||||
|
|
||||||
void addOption(string text) {
|
void addOption(string text, ptrdiff_t tag = 0) {
|
||||||
options ~= Option(text);
|
options ~= Option(text, false, tag);
|
||||||
version(win32_widgets) {
|
version(win32_widgets) {
|
||||||
WCharzBuffer buffer = WCharzBuffer(text);
|
WCharzBuffer buffer = WCharzBuffer(text);
|
||||||
SendMessageW(hwnd, LB_ADDSTRING, 0, cast(LPARAM) buffer.ptr);
|
SendMessageW(hwnd, LB_ADDSTRING, 0, cast(LPARAM) buffer.ptr);
|
||||||
|
|
Loading…
Reference in New Issue