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

Function newMenuScene

core/menu.go:62–96  ·  view source on GitHub ↗

newMenuScene constructs a [Scene] for displaying a menu, using the given menu constructor function. If no name is provided, it defaults to "menu". If no menu items added, returns nil.

(menu func(m *Scene), name ...string)

Source from the content-addressed store, hash-verified

60// given menu constructor function. If no name is provided, it defaults
61// to "menu". If no menu items added, returns nil.
62func newMenuScene(menu func(m *Scene), name ...string) *Scene {
63 nm := "menu"
64 if len(name) > 0 {
65 nm = name[0] + "-menu"
66 }
67 msc := NewScene(nm)
68 StyleMenuScene(msc)
69 menu(msc)
70 if !msc.HasChildren() {
71 return nil
72 }
73
74 hasSelected := false
75 msc.WidgetWalkDown(func(cw Widget, cwb *WidgetBase) bool {
76 if cw == msc {
77 return tree.Continue
78 }
79 if bt := AsButton(cw); bt != nil {
80 if bt.Menu == nil {
81 bt.handleClickDismissMenu()
82 }
83 }
84 if !hasSelected && cwb.StateIs(states.Selected) {
85 // fmt.Println("start focus sel:", wb)
86 msc.Events.SetStartFocus(cwb)
87 hasSelected = true
88 }
89 return tree.Continue
90 })
91 if !hasSelected && msc.HasChildren() {
92 // fmt.Println("start focus first:", msc.Child(0).(Widget))
93 msc.Events.SetStartFocus(msc.Child(0).(Widget))
94 }
95 return msc
96}
97
98// NewMenuStage returns a new Menu stage with given scene contents,
99// in connection with given widget, which provides key context

Callers 2

NewMenuFunction · 0.85
NewMenuFromStringsFunction · 0.85

Calls 9

StyleMenuSceneFunction · 0.85
AsButtonFunction · 0.85
WidgetWalkDownMethod · 0.80
StateIsMethod · 0.80
SetStartFocusMethod · 0.80
ChildMethod · 0.80
NewSceneFunction · 0.70
HasChildrenMethod · 0.45

Tested by

no test coverage detected