Working some things out

This commit is contained in:
2025-08-14 14:21:19 -05:00
parent a74cf9fe61
commit acfe8be93d
9 changed files with 193 additions and 104 deletions

View File

@@ -77,16 +77,12 @@ func (w *LinearLayout) Init(id string, s tcell.Style) {
func (w *LinearLayout) Id() string { return w.id }
func (w *LinearLayout) HandleResize(ev *tcell.EventResize) {
w.w, w.h = ev.Size()
// w.w = wh.Max(w.w, w.WantW())
// w.h = wh.Max(w.h, w.WantH())
w.updateWidgetLayouts()
}
func (w *LinearLayout) HandleKey(ev *tcell.EventKey) bool {
// First, see if the active widget handles the key
w.Log("LL: Handling Event: %s", ev.Name())
if len(w.widgets) > w.cursor {
w.Log("LL: Pushing to Widget: %s", w.widgets[w.cursor].Id())
if w.widgets[w.cursor].HandleKey(ev) {
return true
}
@@ -135,6 +131,7 @@ func (w *LinearLayout) GetW() int { return w.w }
func (w *LinearLayout) GetH() int { return w.h }
func (w *LinearLayout) SetW(wd int) { w.w = wd }
func (w *LinearLayout) SetH(h int) { w.h = h }
func (w *LinearLayout) getSize() Coord { return Coord{X: w.w, Y: w.h} }
func (w *LinearLayout) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *LinearLayout) WantW() int {
var wantW int
@@ -144,7 +141,7 @@ func (w *LinearLayout) WantW() int {
// Find the highest want of all widgets
wantW = wh.Max(wd.WantW(), wantW)
case LinLayH:
// Find the sum of all widget widgets wants
// Find the sum of all widgets wants
wantW = wantW + wd.WantW()
}
}
@@ -156,7 +153,7 @@ func (w *LinearLayout) WantH() int {
for _, wd := range w.widgets {
switch w.orientation {
case LinLayV:
// Find the sum of all widget widgets wants
// Find the sum of all widgets wants
wantH = wantH + wd.WantH()
case LinLayH:
// Find the highest want of all widgets
@@ -198,13 +195,7 @@ func (w *LinearLayout) MinH() int {
// All others to inactive
// If this layout is not active, everything is inactive
func (w *LinearLayout) updateActive() {
if !w.active {
w.Log("LL: Not Active")
}
for i, wd := range w.widgets {
if i == w.cursor {
w.Log("LL: Setting Active: %s", w.widgets[i].Id())
}
wd.SetActive(i == w.cursor && w.active)
}
}
@@ -264,6 +255,8 @@ func (w *LinearLayout) Delete(n Widget) {
for i := 0; i < len(w.widgets); i++ {
if w.widgets[i] == n {
w.DeleteIndex(i)
delete(w.layoutFlags, n)
delete(w.layoutWeights, n)
return
}
}
@@ -310,6 +303,7 @@ func (w *LinearLayout) updateTotalWeight() {
for _, v := range w.layoutWeights {
w.totalWeight += v
}
w.HandleResize(w.getSize().ResizeEvent())
}
func (w *LinearLayout) updateWidgetLayouts() {
@@ -333,11 +327,25 @@ 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) {
wd.HandleResize((&Coord{X: w.w, Y: w.getWeightedH(wd)}).ResizeEvent())
rW := w.w
if wd == w.widgets[len(w.widgets)-1] {
wrk := float64(w.w) / float64(w.totalWeight)
if wrk == float64((w.w / w.totalWeight)) {
rW -= 1
}
}
wd.HandleResize((&Coord{X: rW, Y: w.getWeightedH(wd)}).ResizeEvent())
}
func (w *LinearLayout) updateLLHWidgetSize(wd Widget) {
wd.HandleResize((&Coord{X: w.getWeightedW(wd), Y: w.h}).ResizeEvent())
rH := w.h
if wd == w.widgets[len(w.widgets)-1] {
wrk := float64(w.h) / float64(w.totalWeight)
if wrk == float64((w.h / w.totalWeight)) {
rH -= 1
}
}
wd.HandleResize((&Coord{X: w.getWeightedW(wd), Y: rH}).ResizeEvent())
}
// The Layout should have a static Size set at this point that we can use
@@ -373,7 +381,11 @@ func (w *LinearLayout) updateLLVWidgetPos(wd Widget) {
c.Y += (w.getWeightedH(wd) / 2) - (wd.GetH() / 2)
}
}
c.X = int((float64(w.w) / 2) - (float64(wd.GetW()) / 2))
if wd.GetW() < w.w {
c.X = int((float64(w.w) / 2) - (float64(wd.GetW()) / 2))
} else {
c.X = 0
}
wd.SetPos(c)
}
@@ -381,10 +393,14 @@ func (w *LinearLayout) updateLLHWidgetPos(wd Widget) {
c := Coord{}
for i := range w.widgets {
if w.widgets[i] == wd {
if i > 0 {
c.X += 1
}
break
}
c.X += w.getWeightedW(w.widgets[i])
}
// Do we have a layout flag for this widget?
var ok bool
var flgs LayoutFlag
@@ -402,25 +418,12 @@ func (w *LinearLayout) updateLLHWidgetPos(wd Widget) {
c.X += (w.getWeightedW(wd) / 2) - (wd.GetW() / 2)
}
}
c.Y = int((float64(w.h) / 2) - (float64(wd.GetH()) / 2))
wd.SetPos(c)
}
func (w *LinearLayout) updateWidgetPos(wd Widget) {
prevP, prevS := 0, 0
for _, wrk := range w.widgets {
c := Coord{}
switch w.orientation {
case LinLayV:
c.X, c.Y = 0, prevP+prevS
prevP, prevS = c.Y, wrk.GetH()
case LinLayH:
c.X, c.Y = prevP+prevS, 0
prevP, prevS = c.X, wrk.GetW()
}
wd.SetPos(c)
if wd.GetW() < w.h {
c.Y = int((float64(w.h) / 2) - (float64(wd.GetH()) / 2))
} else {
c.Y = 0
}
wd.SetPos(c)
}
func (w *LinearLayout) getWeightedH(wd Widget) int {
@@ -431,8 +434,13 @@ func (w *LinearLayout) getWeightedH(wd Widget) int {
if wght == 0 {
wght = 1
}
ret := int(float64(w.h) * (float64(wght) / float64(w.totalWeight)))
return ret
retF := float64(w.h) * (float64(wght) / float64(w.totalWeight))
retI := int(retF)
if retF-float64(retI) >= 0.5 {
return retI + 1
} else {
return retI
}
}
func (w *LinearLayout) getWeightedW(wd Widget) int {
@@ -443,7 +451,13 @@ func (w *LinearLayout) getWeightedW(wd Widget) int {
if wght == 0 {
wght = 1
}
return int(float64(w.w) * (float64(wght) / float64(w.totalWeight)))
retF := float64(w.w) * (float64(wght) / float64(w.totalWeight))
retI := int(retF)
if retF-float64(retI) >= 0.5 {
return retI + 1
} else {
return retI
}
}
func (w *LinearLayout) handleTab() bool {