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

@@ -22,7 +22,7 @@ THE SOFTWARE.
package widgets
import (
h "git.bullercodeworks.com/brian/tcell-widgets/helpers"
wh "git.bullercodeworks.com/brian/tcell-widgets/helpers"
"github.com/gdamore/tcell"
)
@@ -48,6 +48,8 @@ type MenuItem struct {
keyMap KeyMap
}
var _ Widget = (*MenuItem)(nil)
func NewMenuItem(id string, style tcell.Style) *MenuItem {
ret := &MenuItem{}
ret.Init(id, style)
@@ -75,8 +77,15 @@ func (w *MenuItem) Init(id string, style tcell.Style) {
}
w.tabbable = true
}
func (w *MenuItem) Id() string { return w.id }
func (w *MenuItem) HandleResize(ev *tcell.EventResize) {}
func (w *MenuItem) Id() string { return w.id }
func (w *MenuItem) 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())
// TODO: Trickle-down HandleResize
}
func (w *MenuItem) HandleKey(ev *tcell.EventKey) bool {
if !w.active {
return false
@@ -100,11 +109,11 @@ func (w *MenuItem) Draw(screen tcell.Screen) {
x, y := w.x, w.y
wd := w.w
h.DrawText(x, y, h.PadR(w.label, wd), st, screen)
wh.DrawText(x, y, wh.PadR(w.label, wd), st, screen)
y += 1
if w.expanded {
if len(w.items) > 0 {
h.TitledBorderFilled(w.x-1, w.y, w.x+w.WantW(), w.y+w.WantH(), w.label, h.BRD_CSIMPLE, w.style, screen)
wh.TitledBorderFilled(w.x-1, w.y, w.x+w.WantW(), w.y+w.WantH(), w.label, wh.BRD_CSIMPLE, w.style, screen)
}
x += 1
for i := range w.items {
@@ -141,6 +150,8 @@ func (w *MenuItem) SetW(x int) { w.w = x }
func (w *MenuItem) SetH(y int) { w.h = y }
func (w *MenuItem) GetW() int { return w.w }
func (w *MenuItem) GetH() int { return w.y }
func (w *MenuItem) MinW() int { return w.w }
func (w *MenuItem) MinH() int { return w.y }
func (w *MenuItem) WantW() int {
ret := len(w.label) + 2
if len(w.items) > 0 {