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,8 +36,9 @@ type Button struct {
x, y int
w, h int
active bool
visible bool
active bool
visible bool
tabbable bool
onPressed func() bool
}
@@ -55,9 +56,11 @@ func (w *Button) Init(id string, style tcell.Style) {
w.style = style
w.visible = true
w.onPressed = func() bool { return false }
w.tabbable = true
}
func (w *Button) Id() string { return w.id }
func (w *Button) HandleResize(ev *tcell.EventResize) {}
func (w *Button) HandleResize(ev *tcell.EventResize) { w.w, w.h = ev.Size() }
func (w *Button) HandleKey(ev *tcell.EventKey) bool {
if !w.active {
return false
@@ -106,26 +109,31 @@ func (w *Button) Draw(screen tcell.Screen) {
}
lbl := h.Center(w.label, w.w-2)
h.DrawText(w.x, w.y, fmt.Sprintf("╭%s╮", strings.Repeat("─", w.w-2)), dStyle, screen)
h.DrawText(w.x, w.y, fmt.Sprintf("│%s│", h.Center(lbl, w.w-2)), dStyle, screen)
h.DrawText(w.x, w.y, fmt.Sprintf("╰%s╯", strings.Repeat("─", w.w-2)), dStyle, screen)
h.DrawText(w.x, w.y+1, fmt.Sprintf("│%s│", h.Center(lbl, w.w-2)), dStyle, screen)
h.DrawText(w.x, w.y+2, fmt.Sprintf("╰%s╯", strings.Repeat("─", w.w-2)), dStyle, screen)
}
func (w *Button) Active() bool { return w.active }
func (w *Button) SetActive(a bool) { w.active = a }
func (w *Button) Visible() bool { return w.visible }
func (w *Button) SetVisible(a bool) { w.visible = a }
func (w *Button) SetX(x int) { w.x = x }
func (w *Button) SetY(y int) { w.y = y }
func (w *Button) GetX() int { return w.x }
func (w *Button) GetY() int { return w.y }
func (w *Button) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *Button) SetW(x int) { w.w = x }
func (w *Button) SetH(y int) { w.h = y }
func (w *Button) GetW() int { return w.w }
func (w *Button) GetH() int { return w.y }
func (w *Button) WantW() int { return 2 + len(w.label) }
func (w *Button) WantH() int { return 3 }
func (w *Button) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *Button) Focusable() bool { return true }
func (w *Button) Active() bool { return w.active }
func (w *Button) SetActive(a bool) { w.active = a }
func (w *Button) Visible() bool { return w.visible }
func (w *Button) SetVisible(a bool) { w.visible = a }
func (w *Button) SetX(x int) { w.x = x }
func (w *Button) SetY(y int) { w.y = y }
func (w *Button) GetX() int { return w.x }
func (w *Button) GetY() int { return w.y }
func (w *Button) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
func (w *Button) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *Button) SetW(x int) { w.w = x }
func (w *Button) SetH(y int) { w.h = y }
func (w *Button) GetW() int { return w.w }
func (w *Button) GetH() int { return w.y }
func (w *Button) WantW() int { return 4 + len(w.label) }
func (w *Button) WantH() int { return 3 }
func (w *Button) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *Button) Focusable() bool { return true }
func (w *Button) SetTabbable(b bool) { w.tabbable = b }
func (w *Button) Tabbable() bool { return w.tabbable }
func (w *Button) MinW() int { return len(w.label) + 2 }
func (w *Button) MinH() int { return 1 }
func (w *Button) SetLabel(l string) { w.label = l }
func (w *Button) SetOnPressed(p func() bool) { w.onPressed = p }