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)
| 60 | // given menu constructor function. If no name is provided, it defaults |
| 61 | // to "menu". If no menu items added, returns nil. |
| 62 | func 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 |
no test coverage detected