So much work

This commit is contained in:
2025-08-06 16:15:08 -05:00
parent 1474caffaa
commit 81c7ec8324
20 changed files with 1386 additions and 376 deletions

View File

@@ -36,6 +36,7 @@ type Table struct {
active bool
visible bool
focusable bool
tabbable bool
header []string
footer []string
@@ -82,6 +83,7 @@ func (w *Table) Init(id string, style tcell.Style) {
w.style = style
w.visible = true
w.border = h.BRD_CSIMPLE
w.tabbable = true
}
func (w *Table) Id() string { return w.id }
func (w *Table) HandleResize(ev *tcell.EventResize) {}
@@ -147,6 +149,7 @@ func (w *Table) SetX(x int) { w.x = x }
func (w *Table) SetY(y int) { w.y = y }
func (w *Table) GetX() int { return w.x }
func (w *Table) GetY() int { return w.y }
func (w *Table) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
func (w *Table) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *Table) SetW(x int) { w.w = x }
func (w *Table) SetH(y int) { w.h = y }
@@ -198,8 +201,55 @@ func (w *Table) WantH() int {
return datLen
}
func (w *Table) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *Table) Focusable() bool { return w.focusable }
func (w *Table) MinW() int {
if w.minimized {
return len(fmt.Sprintf("├%s (%d rows)┤", w.title, len(w.data)))
}
// For each column, find the longest (in header, data, and footer)
var totalW int
colCnt := h.Max(len(w.header), len(w.footer))
for i := range w.data {
colCnt = h.Max(colCnt, len(w.data[i]))
}
for i := 0; i < colCnt; i++ {
var cols []int
if len(w.header) > i {
cols = append(cols, len(w.header[i]))
}
for j := range w.data {
if len(w.data[j]) > i {
cols = append(cols, len(w.data[j][i]))
}
}
if len(w.footer) > i {
cols = append(cols, len(w.footer[i]))
}
totalW += h.Max(cols...)
}
return totalW
}
func (w *Table) MinH() int {
if w.minimized {
return 1
}
datLen := h.Min(len(w.data)+2, 7) // Data length + Border
if len(w.header) > 0 {
datLen += len(w.header) + 1 // Header length + separator
}
if datLen == 0 {
datLen = 1
}
if len(w.footer) > 0 {
datLen += len(w.footer) + 1 // Footer length + separator
}
return datLen
}
func (w *Table) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *Table) Focusable() bool { return w.focusable }
func (w *Table) SetTabbable(b bool) { w.tabbable = b }
func (w *Table) Tabbable() bool { return w.tabbable }
func (w *Table) SetTitle(ttl string) { w.title = ttl }
func (w *Table) SetFocusable(f bool) { w.focusable = f }