func (l *DropDownList) Init(outer DropDownListOuter, theme gxui.Theme) { l.outer = outer l.Container.Init(outer, theme) l.BackgroundBorderPainter.Init(outer) l.Focusable.Init(outer) l.theme = theme l.list = theme.CreateList() l.list.OnSelectionChanged(func(item gxui.AdapterItem) { l.outer.RemoveAll() adapter := l.list.Adapter() if item != nil && adapter != nil { l.selected = l.AddChild(adapter.Create(l.theme, adapter.ItemIndex(item))) } else { l.selected = nil } l.Relayout() }) l.list.OnItemClicked(func(gxui.MouseEvent, gxui.AdapterItem) { l.HideList() }) l.list.OnKeyPress(func(ev gxui.KeyboardEvent) { switch ev.Key { case gxui.KeyEnter, gxui.KeyEscape: l.HideList() } }) l.list.OnLostFocus(l.HideList) l.OnDetach(l.HideList) l.SetMouseEventTarget(true) // Interface compliance test _ = gxui.DropDownList(l) }
// Color picker uses the customAdapter for driving a list func colorPicker(theme gxui.Theme) gxui.Control { layout := theme.CreateLinearLayout() layout.SetDirection(gxui.TopToBottom) label0 := theme.CreateLabel() label0.SetText("Color palette:") layout.AddChild(label0) adapter := &customAdapter{} list := theme.CreateList() list.SetAdapter(adapter) list.SetOrientation(gxui.Horizontal) layout.AddChild(list) label1 := theme.CreateLabel() label1.SetMargin(math.Spacing{T: 30}) label1.SetText("Selected color:") layout.AddChild(label1) selected := theme.CreateImage() selected.SetExplicitSize(math.Size{W: 32, H: 32}) layout.AddChild(selected) list.OnSelectionChanged(func(item gxui.AdapterItem) { if item != nil { control := list.ItemControl(item) selected.SetBackgroundBrush(control.(gxui.Image).BackgroundBrush()) } }) return layout }
func NewProjectsPane(driver gxui.Driver, theme gxui.Theme, projFrame gxui.Control) *Projects { pane := &Projects{ theme: theme, projectFrame: projFrame, button: createIconButton(driver, theme, "projects.png"), projects: theme.CreateList(), projectsAdapter: gxui.CreateDefaultAdapter(), } pane.projectsAdapter.SetItems(settings.Projects()) pane.projects.SetAdapter(pane.projectsAdapter) return pane }
// Number picker uses the gxui.DefaultAdapter for driving a list func numberPicker(theme gxui.Theme, overlay gxui.BubbleOverlay) gxui.Control { items := []string{ "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty", } adapter := gxui.CreateDefaultAdapter() adapter.SetItems(items) layout := theme.CreateLinearLayout() layout.SetDirection(gxui.TopToBottom) label0 := theme.CreateLabel() label0.SetText("Numbers:") layout.AddChild(label0) dropList := theme.CreateDropDownList() dropList.SetAdapter(adapter) dropList.SetBubbleOverlay(overlay) layout.AddChild(dropList) list := theme.CreateList() list.SetAdapter(adapter) list.SetOrientation(gxui.Vertical) layout.AddChild(list) label1 := theme.CreateLabel() label1.SetMargin(math.Spacing{T: 30}) label1.SetText("Selected number:") layout.AddChild(label1) selected := theme.CreateLabel() layout.AddChild(selected) dropList.OnSelectionChanged(func(item gxui.AdapterItem) { if list.Selected() != item { list.Select(item) } }) list.OnSelectionChanged(func(item gxui.AdapterItem) { if dropList.Selected() != item { dropList.Select(item) } selected.SetText(fmt.Sprintf("%s - %d", item, adapter.ItemIndex(item))) }) return layout }