Some Updates

This commit is contained in:
2025-08-21 14:25:17 -05:00
parent a9c059b987
commit e4405a8d6b
5 changed files with 95 additions and 57 deletions

View File

@@ -41,6 +41,7 @@ type Button struct {
tabbable bool
onPressed func() bool
logger func(string, ...any)
}
var _ Widget = (*Button)(nil)
@@ -75,6 +76,7 @@ func (w *Button) HandleKey(ev *tcell.EventKey) bool {
return false
}
func (w *Button) HandleTime(ev *tcell.EventTime) {}
func (w *Button) Draw(screen tcell.Screen) {
if !w.visible {
return
@@ -96,6 +98,7 @@ func (w *Button) Draw(screen tcell.Screen) {
lbl = fmt.Sprintf("[%s]", wh.Center(lbl, w.w-2))
}
wh.DrawText(w.x, w.y, lbl, dStyle, screen)
return
case 2:
lbl := w.label
if w.w < len(lbl) {
@@ -133,7 +136,7 @@ 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) GetH() int { return w.h }
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 }
@@ -145,3 +148,10 @@ 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 }
func (w *Button) SetLogger(l func(string, ...any)) { w.logger = l }
func (w *Button) Log(txt string, args ...any) {
if w.logger != nil {
w.logger(txt, args...)
}
}