Several Fixes
This commit is contained in:
@@ -50,10 +50,11 @@ type LinearLayout struct {
|
||||
// fields
|
||||
stacked bool
|
||||
|
||||
active bool
|
||||
visible bool
|
||||
tabbable bool
|
||||
disableTab bool
|
||||
active bool
|
||||
visible bool
|
||||
tabbable bool
|
||||
disableTab bool
|
||||
insetBorder bool
|
||||
|
||||
logger func(string, ...any)
|
||||
}
|
||||
@@ -93,24 +94,19 @@ func (w *LinearLayout) HandleKey(ev *tcell.EventKey) bool {
|
||||
if !w.active || w.disableTab {
|
||||
return false
|
||||
}
|
||||
|
||||
active := w.findActive()
|
||||
if active != nil {
|
||||
if active.HandleKey(ev) {
|
||||
w.Log("%s.HandleKey %s <- Consumed by %s", w.Id(), ev.Name(), active.Id())
|
||||
return true
|
||||
}
|
||||
w.Log("%s.HandleKey Not handled by active (%s)", w.Id(), active.Id())
|
||||
}
|
||||
if ev.Key() == tcell.KeyTab {
|
||||
w.Log("%s-> Activating Next (current: %s)", w.Id(), w.findActive().Id())
|
||||
ret := w.activateNext()
|
||||
if ret {
|
||||
w.Log("%s<- Activated: %s", w.Id(), w.findActive().Id())
|
||||
} else {
|
||||
w.Log("%s<- Nothing Activated", w.Id())
|
||||
if active == nil && len(w.widgets) > 0 {
|
||||
// No widget is active
|
||||
w.widgets[0].SetActive(true)
|
||||
return true
|
||||
}
|
||||
return ret
|
||||
return w.activateNext()
|
||||
}
|
||||
|
||||
return false
|
||||
@@ -128,13 +124,25 @@ func (w *LinearLayout) Draw(screen tcell.Screen) {
|
||||
return
|
||||
}
|
||||
pos := w.GetPos()
|
||||
if w.insetBorder {
|
||||
wh.Border(pos.X, pos.Y, pos.X+w.w, pos.Y+w.h, wh.BRD_CSIMPLE, w.style, screen)
|
||||
}
|
||||
|
||||
for _, wd := range w.widgets {
|
||||
pos.DrawOffset(wd, screen)
|
||||
}
|
||||
}
|
||||
|
||||
func (w *LinearLayout) Active() bool { return w.active }
|
||||
func (w *LinearLayout) SetActive(a bool) { w.active = a }
|
||||
func (w *LinearLayout) Active() bool { return w.active }
|
||||
func (w *LinearLayout) SetActive(a bool) {
|
||||
w.active = a
|
||||
if w.active {
|
||||
act := w.findActiveOrFirst()
|
||||
if act != nil {
|
||||
act.SetActive(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
func (w *LinearLayout) Visible() bool { return w.visible }
|
||||
func (w *LinearLayout) SetVisible(a bool) { w.visible = a }
|
||||
func (w *LinearLayout) Focusable() bool { return true }
|
||||
@@ -217,6 +225,13 @@ func (w *LinearLayout) findActive() Widget {
|
||||
return w.widgets[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *LinearLayout) findActiveOrFirst() Widget {
|
||||
if act := w.findActive(); act != nil {
|
||||
return act
|
||||
}
|
||||
// Didn't find one, return the first
|
||||
if len(w.widgets) > 0 {
|
||||
return w.widgets[0]
|
||||
@@ -227,7 +242,7 @@ func (w *LinearLayout) findActive() Widget {
|
||||
func (w *LinearLayout) activateNext() bool {
|
||||
var found bool
|
||||
for i := range w.widgets {
|
||||
if found {
|
||||
if found && w.widgets[i].Tabbable() {
|
||||
w.Log("%s.activeNext Setting Next Active: %s", w.Id(), w.widgets[i].Id())
|
||||
w.widgets[i].SetActive(true)
|
||||
return true
|
||||
@@ -537,6 +552,8 @@ func (w *LinearLayout) getWeightedW(wd Widget) int {
|
||||
|
||||
func (w *LinearLayout) SetStacked(s bool) { w.stacked = s }
|
||||
|
||||
func (w *LinearLayout) SetBordered(b bool) { w.insetBorder = b }
|
||||
|
||||
func (w *LinearLayout) SetLogger(l func(string, ...any)) { w.logger = l }
|
||||
func (w *LinearLayout) Log(txt string, args ...any) {
|
||||
if w.logger != nil {
|
||||
|
||||
Reference in New Issue
Block a user