Wonkiness on layout

This commit is contained in:
2025-10-10 16:46:29 -05:00
parent 79a212e601
commit 7a1afd67ac
28 changed files with 362 additions and 156 deletions

View File

@@ -56,7 +56,7 @@ type LinearLayout struct {
disableTab bool
insetBorder bool
keyMap KeyMap
keyMap, customKeyMap KeyMap
logger func(string, ...any)
}
@@ -98,6 +98,7 @@ func (w *LinearLayout) Init(id string, s tcell.Style) {
}
return w.ActivateNext()
})
w.customKeyMap = BlankKeyMap()
}
func (w *LinearLayout) Id() string { return w.id }
@@ -106,14 +107,20 @@ func (w *LinearLayout) HandleResize(ev *tcell.EventResize) {
w.updateWidgetLayouts()
}
func (w *LinearLayout) SetKeyMap(km KeyMap) { w.keyMap = km }
func (w *LinearLayout) AddToKeyMap(km KeyMap) { w.keyMap.Merge(km) }
func (w *LinearLayout) SetKeyMap(km KeyMap, def bool) {
if def {
w.keyMap = km
} else {
w.customKeyMap = km
}
}
func (w *LinearLayout) AddToKeyMap(km KeyMap) { w.customKeyMap.Merge(km) }
func (w *LinearLayout) RemoveFromKeyMap(km KeyMap) {
for k := range km.Keys {
w.keyMap.Remove(k)
w.customKeyMap.Remove(k)
}
for r := range km.Runes {
w.keyMap.RemoveRune(r)
w.customKeyMap.RemoveRune(r)
}
}
@@ -128,7 +135,8 @@ func (w *LinearLayout) HandleKey(ev *tcell.EventKey) bool {
return true
}
}
return w.keyMap.Handle(ev)
b1, b2 := w.keyMap.Handle(ev), w.customKeyMap.Handle(ev)
return b1 || b2
}
func (w *LinearLayout) GetActiveWidgetIdx() int { return w.findActiveIdx() }
@@ -494,6 +502,9 @@ func (w *LinearLayout) updateLLVWidgetPos(wd Widget) {
c := Coord{}
for i := range w.widgets {
if w.widgets[i] == wd {
if i > 0 {
c.Y += 1
}
break
}
if w.widgets[i].Visible() {
@@ -590,7 +601,11 @@ func (w *LinearLayout) getWeightedH(wd Widget) int {
} else if w.stacked {
return wd.MinH()
}
return int(float64(w.h)*(float64(w.GetWeight(wd))/float64(w.totalWeight))) - 1
use := int(float64(w.h)*(float64(w.GetWeight(wd))/float64(w.totalWeight))) - 1
if use < wd.MinH() {
return wd.MinH()
}
return use
}
func (w *LinearLayout) getWeightedW(wd Widget) int {
@@ -599,7 +614,11 @@ func (w *LinearLayout) getWeightedW(wd Widget) int {
} else if w.stacked {
return wd.MinW()
}
return int(float64(w.w)*(float64(w.GetWeight(wd))/float64(w.totalWeight))) - 1
use := int(float64(w.w)*(float64(w.GetWeight(wd))/float64(w.totalWeight))) - 1
if use < wd.MinW() {
return wd.MinW()
}
return use
}
func (w *LinearLayout) SetStacked(s bool) { w.stacked = s }