Really figuring some things out

This commit is contained in:
2025-08-07 11:18:03 -05:00
parent 7c96fbb187
commit b476c74683
23 changed files with 737 additions and 249 deletions

View File

@@ -25,7 +25,7 @@ import (
"fmt"
"strings"
h "git.bullercodeworks.com/brian/tcell-widgets/helpers"
wh "git.bullercodeworks.com/brian/tcell-widgets/helpers"
"github.com/gdamore/tcell"
)
@@ -58,8 +58,12 @@ func (w *Button) Init(id string, style tcell.Style) {
w.onPressed = func() bool { return false }
w.tabbable = true
}
func (w *Button) Id() string { return w.id }
func (w *Button) HandleResize(ev *tcell.EventResize) { w.w, w.h = ev.Size() }
func (w *Button) Id() string { return w.id }
func (w *Button) HandleResize(ev *tcell.EventResize) {
w.w, w.h = ev.Size()
w.w = wh.Min(w.w, w.WantW())
w.h = wh.Min(w.h, w.WantH())
}
func (w *Button) HandleKey(ev *tcell.EventKey) bool {
if !w.active {
@@ -79,38 +83,39 @@ func (w *Button) Draw(screen tcell.Screen) {
if w.active {
dStyle = w.style.Bold(true)
}
if w.h == 1 {
switch w.h {
case 1:
lbl := w.label
if w.w < len(lbl) {
lbl = lbl[:w.w]
} else if w.w == len(w.label)+2 {
lbl = fmt.Sprintf("[%s]", lbl)
} else if w.w > len(w.label)+2 {
lbl = fmt.Sprintf("[%s]", h.Center(lbl, w.w-2))
lbl = fmt.Sprintf("[%s]", wh.Center(lbl, w.w-2))
}
h.DrawText(w.x, w.y, lbl, dStyle, screen)
} else if w.h == 2 {
wh.DrawText(w.x, w.y, lbl, dStyle, screen)
case 2:
lbl := w.label
if w.w < len(lbl) {
lbl = lbl[:w.w]
} else if w.w == len(lbl)+2 {
lbl = fmt.Sprintf("╭%s╮", lbl)
}
h.DrawText(w.x, w.y, lbl, dStyle, screen)
h.DrawText(w.x, w.y+1, fmt.Sprintf("╰%s╯", strings.Repeat("─", len(lbl)-2)), dStyle, screen)
wh.DrawText(w.x, w.y, lbl, dStyle, screen)
wh.DrawText(w.x, w.y+1, fmt.Sprintf("╰%s╯", strings.Repeat("─", len(lbl)-2)), dStyle, screen)
return
}
if w.w < 2 {
h.DrawText(w.x, w.y, "╬", dStyle, screen)
wh.DrawText(w.x, w.y, "╬", dStyle, screen)
return
} else if w.w == 2 {
h.DrawText(w.x, w.y, "[]", dStyle, screen)
wh.DrawText(w.x, w.y, "[]", dStyle, screen)
return
}
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+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)
lbl := wh.Center(w.label, w.w-2)
wh.DrawText(w.x, w.y, fmt.Sprintf("╭%s╮", strings.Repeat("─", w.w-2)), dStyle, screen)
wh.DrawText(w.x, w.y+1, fmt.Sprintf("│%s│", wh.Center(lbl, w.w-2)), dStyle, screen)
wh.DrawText(w.x, w.y+2, fmt.Sprintf("╰%s╯", strings.Repeat("─", w.w-2)), dStyle, screen)
}
func (w *Button) DrawOffset(c Coord, screen tcell.Screen) {