A few fixes

This commit is contained in:
2025-08-18 15:49:03 -05:00
parent 061bf1b37d
commit 599554a798
7 changed files with 117 additions and 117 deletions

View File

@@ -40,6 +40,8 @@ type LinearLayout struct {
layoutFlags map[Widget]LayoutFlag
layoutWeights map[Widget]int
totalWeight int
// Stacked makes the layout ignore weights and effectively shrink-wrap all fields
stacked bool
active bool
visible bool
@@ -81,14 +83,25 @@ func (w *LinearLayout) HandleResize(ev *tcell.EventResize) {
}
func (w *LinearLayout) HandleKey(ev *tcell.EventKey) bool {
w.Log("LinearLayout<%s>.HandleKey", w.Id())
if !w.active {
w.Log("LinearLayout<%s>.HandleKey - NOPE. Not Active.", w.Id())
return false
}
// First, see if the active widget handles the key
w.Log("LinearLayout<%s>.HandleKey: Checking Active Widget...", w.Id())
if len(w.widgets) > w.cursor {
w.Log("LinearLayout<%s>.HandleKey: Widget<%s>.HandleKey", w.Id(), w.widgets[w.cursor].Id())
if w.widgets[w.cursor].HandleKey(ev) {
return true
}
w.Log("LinearLayout<%s>.HandleKey: Widget<%s>.HandleKey Returns", w.Id(), w.widgets[w.cursor].Id())
}
w.Log("LinearLayout<%s>.HandleKey: Checking for Tab", w.Id())
if ev.Key() == tcell.KeyTab && !w.disableTab {
w.Log("LinearLayout<%s>.HandleKey: Handling Tab", w.Id())
return w.handleTab()
}
@@ -214,6 +227,18 @@ func (w *LinearLayout) Contains(n Widget) bool {
return w.IndexOf(n) >= 0
}
func (w *LinearLayout) Replace(n, with Widget) {
idx := w.IndexOf(n)
if idx == -1 {
// 'n' isn't in layout. Bail out.
return
}
pFlags, pWeight := w.layoutFlags[n], w.layoutWeights[n]
w.Delete(n)
w.Insert(with, idx)
w.layoutFlags[with], w.layoutWeights[with] = pFlags, pWeight
}
func (w *LinearLayout) Add(n Widget) {
if w.Contains(n) {
// If the widget is already in the layout, move it to the end
@@ -327,6 +352,9 @@ func (w *LinearLayout) updateWidgetLayouts() {
// We need to determine the allowed size of this widget so we can determine
// it's position
func (w *LinearLayout) updateLLVWidgetSize(wd Widget) {
if w.stacked {
return
}
rW := w.w
if wd == w.widgets[len(w.widgets)-1] {
wrk := float64(w.w) / float64(w.totalWeight)
@@ -338,6 +366,9 @@ func (w *LinearLayout) updateLLVWidgetSize(wd Widget) {
}
func (w *LinearLayout) updateLLHWidgetSize(wd Widget) {
if w.stacked {
return
}
rH := w.h
if wd == w.widgets[len(w.widgets)-1] {
wrk := float64(w.h) / float64(w.totalWeight)
@@ -461,6 +492,7 @@ func (w *LinearLayout) getWeightedW(wd Widget) int {
}
func (w *LinearLayout) handleTab() bool {
w.Log("%s - Handling Tab", w.Id())
beg := w.cursor
// Find the next tabbable widget
w.cursor = (w.cursor + 1) % len(w.widgets)
@@ -471,6 +503,8 @@ func (w *LinearLayout) handleTab() bool {
return w.cursor > 0 && w.cursor != beg
}
func (w *LinearLayout) SetStacked(s bool) { w.stacked = s }
func (w *LinearLayout) SetLogger(l func(string, ...any)) { w.logger = l }
func (w *LinearLayout) Log(txt string, args ...any) {
if w.logger != nil {