MCPcopy Create free account
hub / github.com/cogentcore/core / NewMenuFromStrings

Function NewMenuFromStrings

core/menu.go:184–196  ·  view source on GitHub ↗

NewMenuFromStrings constructs a new menu from given list of strings, calling the given function with the index of the selected string. if string == sel, that menu item is selected initially.

(strs []string, sel string, fun func(idx int))

Source from the content-addressed store, hash-verified

182// calling the given function with the index of the selected string.
183// if string == sel, that menu item is selected initially.
184func NewMenuFromStrings(strs []string, sel string, fun func(idx int)) *Scene {
185 return newMenuScene(func(m *Scene) {
186 for i, s := range strs {
187 b := NewButton(m).SetText(s)
188 b.OnClick(func(e events.Event) {
189 fun(i)
190 })
191 if s == sel {
192 b.SetSelected(true)
193 }
194 }
195 })
196}

Callers 1

pasteHistoryMethod · 0.92

Calls 5

newMenuSceneFunction · 0.85
NewButtonFunction · 0.85
SetTextMethod · 0.45
OnClickMethod · 0.45
SetSelectedMethod · 0.45

Tested by

no test coverage detected