From bc0820bce7156b7c5059faf3aa23d96163f48244 Mon Sep 17 00:00:00 2001 From: gucio321 Date: Wed, 25 Oct 2023 11:10:47 +0200 Subject: [PATCH] ListBoxWidget: fix ID handling don't require id argument in ListBox method, use AutoID instead --- ExtraWidgets.go | 9 +++++++-- examples/widgets/widgets.go | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ExtraWidgets.go b/ExtraWidgets.go index e8eef248..f031583d 100644 --- a/ExtraWidgets.go +++ b/ExtraWidgets.go @@ -239,9 +239,9 @@ type ListBoxWidget struct { } // ListBox creates new ListBoxWidget. -func ListBox(id string, items []string) *ListBoxWidget { +func ListBox(items []string) *ListBoxWidget { return &ListBoxWidget{ - id: id, + id: GenAutoID("##ListBox"), width: 0, height: 0, border: true, @@ -253,6 +253,11 @@ func ListBox(id string, items []string) *ListBoxWidget { } } +func (l *ListBoxWidget) ID(id string) *ListBoxWidget { + l.id = id + return l +} + func (l *ListBoxWidget) SelectedIndex(i *int32) *ListBoxWidget { l.selectedIndex = i return l diff --git a/examples/widgets/widgets.go b/examples/widgets/widgets.go index e449b2e3..86db33f2 100644 --- a/examples/widgets/widgets.go +++ b/examples/widgets/widgets.go @@ -203,7 +203,7 @@ func loop() { Size(g.Auto, g.Auto), ), g.TabItem("ListBox").Layout( - g.ListBox("ListBox1", []string{"List item 1", "List item 2", "List item 3"}), + g.ListBox([]string{"List item 1", "List item 2", "List item 3"}), ), g.TabItem("Table").Layout( g.Table().