Fix TopMenu
Add Shrinkwrap
This commit is contained in:
@@ -72,14 +72,32 @@ func (s *UiScreen) Init(ui *Ui) {
|
||||
ll.Add(btnL)
|
||||
ll.AddFlag(btnL, w.LFAlignVBottom)
|
||||
|
||||
dw := w.NewDebugWidget("debug", ui.style)
|
||||
dw.SetWidget(ll)
|
||||
dw.SetSize(w.Coord{X: 20, Y: 30})
|
||||
dw.SetActive(true)
|
||||
s.widget = dw
|
||||
ml := w.NewTopMenuLayout("menu", ui.style)
|
||||
m := ml.Menu()
|
||||
m.SetLabel("Widget Example")
|
||||
ml.AddMenuItems(
|
||||
m.CreateMenuItem("File", nil,
|
||||
m.CreateMenuItem("Exit", func() bool {
|
||||
s.ui.stop()
|
||||
return true
|
||||
}),
|
||||
),
|
||||
)
|
||||
ml.SetLogger(s.log.Log)
|
||||
ml.SetWidget(ll)
|
||||
ml.SetActive(true)
|
||||
s.widget = ml
|
||||
/*
|
||||
dw := w.NewDebugWidget("debug", ui.style)
|
||||
dw.SetWidget(ll)
|
||||
dw.SetSize(w.Coord{X: 20, Y: 30})
|
||||
dw.SetActive(true)
|
||||
s.widget = dw
|
||||
*/
|
||||
ll.Add(s.log)
|
||||
|
||||
s.widgets = append(s.widgets, dw)
|
||||
s.widgets = append(s.widgets, s.log)
|
||||
// s.widgets = append(s.widgets, ml)
|
||||
// s.widgets = append(s.widgets, s.log)
|
||||
}
|
||||
|
||||
func (s *UiScreen) HandleResize(ev *tcell.EventResize) {
|
||||
@@ -95,34 +113,12 @@ func (s *UiScreen) HandleKey(ev *tcell.EventKey) bool {
|
||||
// Ctrl+J is the keypad 'Enter'
|
||||
ev = tcell.NewEventKey(tcell.KeyEnter, 0, 0)
|
||||
}
|
||||
|
||||
if s.cursor < len(s.widgets) {
|
||||
if s.widgets[s.cursor].HandleKey(ev) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
if ev.Key() == tcell.KeyTab {
|
||||
s.cursor = (s.cursor + 1) % len(s.widgets)
|
||||
if s.cursor == 0 {
|
||||
s.widget.SetActive(true)
|
||||
s.log.SetActive(false)
|
||||
} else {
|
||||
s.widget.SetActive(false)
|
||||
s.log.SetActive(true)
|
||||
}
|
||||
return true
|
||||
}
|
||||
if s.cursor == 0 {
|
||||
return s.widget.HandleKey(ev)
|
||||
} else {
|
||||
return s.log.HandleKey(ev)
|
||||
}
|
||||
return s.widget.HandleKey(ev)
|
||||
}
|
||||
func (s *UiScreen) HandleTime(ev *tcell.EventTime) {}
|
||||
func (s *UiScreen) Draw() {
|
||||
s.widget.Draw(s.ui.tScreen)
|
||||
s.log.Draw(s.ui.tScreen)
|
||||
// s.log.Draw(s.ui.tScreen)
|
||||
}
|
||||
func (s *UiScreen) Log(txt string, args ...any) {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user