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

@@ -24,7 +24,7 @@ package widgets
import (
"fmt"
h "git.bullercodeworks.com/brian/tcell-widgets/helpers"
wh "git.bullercodeworks.com/brian/tcell-widgets/helpers"
"github.com/gdamore/tcell"
)
@@ -61,8 +61,8 @@ func (w *Field) Init(id string, style tcell.Style) {
w.style = style
w.visible = true
w.filter = func(ev *tcell.EventKey) bool {
return h.IsBS(*ev) ||
h.KeyIsDisplayable(*ev)
return wh.IsBS(*ev) ||
wh.KeyIsDisplayable(*ev)
}
w.keyMap = NewKeyMap(map[tcell.Key]func(ev *tcell.EventKey) bool{
tcell.KeyLeft: w.handleLeft,
@@ -74,13 +74,18 @@ func (w *Field) Init(id string, style tcell.Style) {
w.tabbable = true
}
func (w *Field) Id() string { return w.id }
func (w *Field) HandleResize(ev *tcell.EventResize) { w.w, w.h = ev.Size() }
func (w *Field) Id() string { return w.id }
func (w *Field) 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 *Field) HandleKey(ev *tcell.EventKey) bool {
if !w.active {
return false
}
if h.IsBS(*ev) {
if wh.IsBS(*ev) {
return w.handleBackspace(ev)
}
if ok := w.keyMap.Handle(ev); ok {
@@ -108,7 +113,7 @@ func (w *Field) Draw(screen tcell.Screen) {
x := w.x
labelW := len(w.label)
if labelW > 0 {
h.DrawText(w.x, w.y, w.label+": ", useStyle, screen)
wh.DrawText(w.x, w.y, w.label+": ", useStyle, screen)
x = x + labelW + 2
}
cursor := " "
@@ -121,15 +126,15 @@ func (w *Field) Draw(screen tcell.Screen) {
}
}
h.DrawText(x, w.y, pre, useStyle, screen)
wh.DrawText(x, w.y, pre, useStyle, screen)
x += len(pre)
if w.active {
h.DrawText(x, w.y, cursor, useStyle.Reverse(true).Blink(true), screen)
wh.DrawText(x, w.y, cursor, useStyle.Reverse(true).Blink(true), screen)
} else {
h.DrawText(x, w.y, cursor, useStyle, screen)
wh.DrawText(x, w.y, cursor, useStyle, screen)
}
x += 1
h.DrawText(x, w.y, post, useStyle, screen)
wh.DrawText(x, w.y, post, useStyle, screen)
}
func (w *Field) DrawOffset(c Coord, screen tcell.Screen) {
@@ -167,7 +172,7 @@ func (w *Field) MinW() int { return len(w.label) + 15 }
func (w *Field) MinH() int { return 1 }
/* Non-Widget-Interface Functions */
func (w *Field) handleBackspace(ev *tcell.EventKey) bool {
func (w *Field) handleBackspace(_ *tcell.EventKey) bool {
st := w.cursor
if w.cursor > 0 {
w.cursor--