Some Updates

This commit is contained in:
2025-09-14 16:13:24 -05:00
parent 10bdd958d4
commit 592fffd601
6 changed files with 67 additions and 65 deletions

View File

@@ -64,15 +64,11 @@ func (w *Checkbox) Init(id string, style tcell.Style) {
w.stateRunes = []rune{'X', ' ', '-'} w.stateRunes = []rune{'X', ' ', '-'}
w.focusable = true w.focusable = true
w.keyMap = NewKeyMap(map[tcell.Key]func(ev *tcell.EventKey) bool{ w.keyMap = NewKeyMap(map[tcell.Key]func(ev *tcell.EventKey) bool{
tcell.KeyEnter: func(_ *tcell.EventKey) bool { tcell.KeyEnter: w.ToggleState,
if w.state == CHECKBOX_ON {
w.state = CHECKBOX_OFF
} else {
w.state = CHECKBOX_ON
}
return true
},
}) })
w.AddToKeyMap(NewRuneMap(map[rune]func(ev *tcell.EventKey) bool{
' ': w.ToggleState,
}))
} }
func (w *Checkbox) Id() string { return w.id } func (w *Checkbox) Id() string { return w.id }
func (w *Checkbox) HandleResize(ev *tcell.EventResize) { func (w *Checkbox) HandleResize(ev *tcell.EventResize) {
@@ -105,7 +101,7 @@ func (w *Checkbox) Draw(screen tcell.Screen) {
if w.active { if w.active {
dStyle = w.style.Bold(true) dStyle = w.style.Bold(true)
} }
wh.DrawText(w.x, w.y, fmt.Sprintf("[%s] %s", string(w.state), w.label), dStyle, screen) wh.DrawText(w.x, w.y, fmt.Sprintf("[%s] %s", string(w.stateRunes[w.state]), w.label), dStyle, screen)
} }
func (w *Checkbox) Active() bool { return w.active } func (w *Checkbox) Active() bool { return w.active }
@@ -152,3 +148,12 @@ func (w *Checkbox) SetStateRunes(runes []rune) {
w.stateRunes[i] = runes[i] w.stateRunes[i] = runes[i]
} }
} }
func (w *Checkbox) ToggleState(_ *tcell.EventKey) bool {
if w.state == CHECKBOX_ON {
w.state = CHECKBOX_OFF
} else {
w.state = CHECKBOX_ON
}
return true
}

View File

@@ -47,7 +47,7 @@ type FilePicker struct {
layout *RelativeLayout layout *RelativeLayout
fileList *List fileList *SimpleList
btnSelect, btnCancel *Button btnSelect, btnCancel *Button
keyMap KeyMap keyMap KeyMap

View File

@@ -183,7 +183,7 @@ func (w *Menu) drawHMenu(screen tcell.Screen) {
w.items[i].SetActive(w.active && w.cursor == i) w.items[i].SetActive(w.active && w.cursor == i)
w.items[i].SetPos(Coord{X: x, Y: y}) w.items[i].SetPos(Coord{X: x, Y: y})
w.items[i].Draw(screen) w.items[i].Draw(screen)
x += w.items[i].WantW() + 2 x += len(w.items[i].Label()) + 2
} }
} }
} }

View File

@@ -277,7 +277,6 @@ func (w *Searcher) SetHideOnSelect(t bool) { w.hideOnSelect = t }
func (w *Searcher) SetTitle(ttl string) { w.title = ttl } func (w *Searcher) SetTitle(ttl string) { w.title = ttl }
func (w *Searcher) SetData(data []string) { func (w *Searcher) SetData(data []string) {
// w.data = data // w.data = data
w.Log("%s: Setting Searcher (filtered)Data (%d length)", w.Id(), len(data))
w.data = data w.data = data
w.filteredData = data w.filteredData = data
w.updateFilter() w.updateFilter()
@@ -287,7 +286,6 @@ func (w *Searcher) updateFilter() {
var selVal string var selVal string
data := []string{} data := []string{}
copy(data, w.filteredData) copy(data, w.filteredData)
w.Log("%s: Setting Searcher Data (%d length)", w.Id(), len(data))
if len(data) > 0 && len(data) > w.cursor { if len(data) > 0 && len(data) > w.cursor {
selVal = data[w.cursor] selVal = data[w.cursor]
} }

View File

@@ -26,7 +26,7 @@ import (
"github.com/gdamore/tcell" "github.com/gdamore/tcell"
) )
type List struct { type SimpleList struct {
id string id string
title string title string
style tcell.Style style tcell.Style
@@ -50,15 +50,15 @@ type List struct {
logger func(string, ...any) logger func(string, ...any)
} }
var _ Widget = (*List)(nil) var _ Widget = (*SimpleList)(nil)
func NewList(id string, style tcell.Style) *List { func NewSimpleList(id string, style tcell.Style) *SimpleList {
ret := &List{style: style} ret := &SimpleList{style: style}
ret.Init(id, style) ret.Init(id, style)
return ret return ret
} }
func (w *List) Init(id string, style tcell.Style) { func (w *SimpleList) Init(id string, style tcell.Style) {
w.id = id w.id = id
w.style = style w.style = style
w.focusable = true w.focusable = true
@@ -87,14 +87,14 @@ func (w *List) Init(id string, style tcell.Style) {
w.itemsStyle = make(map[int]tcell.Style) w.itemsStyle = make(map[int]tcell.Style)
w.focusable = true w.focusable = true
} }
func (w *List) Id() string { return w.id } func (w *SimpleList) Id() string { return w.id }
func (w *List) HandleResize(ev *tcell.EventResize) { func (w *SimpleList) HandleResize(ev *tcell.EventResize) {
w.w, w.h = ev.Size() w.w, w.h = ev.Size()
} }
func (w *List) SetKeyMap(km KeyMap) { w.keyMap = km } func (w *SimpleList) SetKeyMap(km KeyMap) { w.keyMap = km }
func (w *List) AddToKeyMap(km KeyMap) { w.keyMap.Merge(km) } func (w *SimpleList) AddToKeyMap(km KeyMap) { w.keyMap.Merge(km) }
func (w *List) RemoveFromKeyMap(km KeyMap) { func (w *SimpleList) RemoveFromKeyMap(km KeyMap) {
for k := range km.Keys { for k := range km.Keys {
w.keyMap.Remove(k) w.keyMap.Remove(k)
} }
@@ -103,14 +103,14 @@ func (w *List) RemoveFromKeyMap(km KeyMap) {
} }
} }
func (w *List) HandleKey(ev *tcell.EventKey) bool { func (w *SimpleList) HandleKey(ev *tcell.EventKey) bool {
if !w.active || !w.focusable { if !w.active || !w.focusable {
return false return false
} }
return w.keyMap.Handle(ev) return w.keyMap.Handle(ev)
} }
func (w *List) HandleTime(ev *tcell.EventTime) {} func (w *SimpleList) HandleTime(ev *tcell.EventTime) {}
func (w *List) Draw(screen tcell.Screen) { func (w *SimpleList) Draw(screen tcell.Screen) {
dS := w.style dS := w.style
if !w.active { if !w.active {
dS = dS.Dim(true) dS = dS.Dim(true)
@@ -145,24 +145,24 @@ func (w *List) Draw(screen tcell.Screen) {
} }
} }
func (w *List) Active() bool { return w.active } func (w *SimpleList) Active() bool { return w.active }
func (w *List) SetActive(a bool) { w.active = a } func (w *SimpleList) SetActive(a bool) { w.active = a }
func (w *List) Visible() bool { return w.visible } func (w *SimpleList) Visible() bool { return w.visible }
func (w *List) SetVisible(a bool) { w.visible = a } func (w *SimpleList) SetVisible(a bool) { w.visible = a }
func (w *List) SetX(x int) { w.x = x } func (w *SimpleList) SetX(x int) { w.x = x }
func (w *List) SetY(y int) { w.y = y } func (w *SimpleList) SetY(y int) { w.y = y }
func (w *List) GetX() int { return w.x } func (w *SimpleList) GetX() int { return w.x }
func (w *List) GetY() int { return w.y } func (w *SimpleList) GetY() int { return w.y }
func (w *List) GetPos() Coord { return Coord{X: w.x, Y: w.y} } func (w *SimpleList) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
func (w *List) SetPos(c Coord) { w.x, w.y = c.X, c.Y } func (w *SimpleList) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *List) SetW(x int) { w.w = x } func (w *SimpleList) SetW(x int) { w.w = x }
func (w *List) SetH(y int) { w.h = y } func (w *SimpleList) SetH(y int) { w.h = y }
func (w *List) GetW() int { return w.w } func (w *SimpleList) GetW() int { return w.w }
func (w *List) GetH() int { return w.y } func (w *SimpleList) GetH() int { return w.y }
func (w *List) SetSize(c Coord) { w.w, w.h = c.X, c.Y } func (w *SimpleList) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *List) Focusable() bool { return w.focusable } func (w *SimpleList) Focusable() bool { return w.focusable }
func (w *List) SetFocusable(b bool) { w.focusable = b } func (w *SimpleList) SetFocusable(b bool) { w.focusable = b }
func (w *List) WantW() int { func (w *SimpleList) WantW() int {
lng := wh.Longest(w.list) lng := wh.Longest(w.list)
if len(w.border) > 0 { if len(w.border) > 0 {
return lng + 2 return lng + 2
@@ -170,7 +170,7 @@ func (w *List) WantW() int {
return lng return lng
} }
func (w *List) WantH() int { func (w *SimpleList) WantH() int {
lng := len(w.list) lng := len(w.list)
if len(w.border) > 0 { if len(w.border) > 0 {
return lng + 2 return lng + 2
@@ -178,7 +178,7 @@ func (w *List) WantH() int {
return lng return lng
} }
func (w *List) MinW() int { func (w *SimpleList) MinW() int {
lng := wh.Longest(w.list) lng := wh.Longest(w.list)
if lng > 80 { if lng > 80 {
lng = 80 lng = 80
@@ -186,10 +186,10 @@ func (w *List) MinW() int {
return 2 + lng return 2 + lng
} }
func (w *List) MinH() int { return 4 } func (w *SimpleList) MinH() int { return 4 }
func (w *List) SetCursorWrap(b bool) { w.cursorWrap = b } func (w *SimpleList) SetCursorWrap(b bool) { w.cursorWrap = b }
func (w *List) MoveUp() bool { func (w *SimpleList) MoveUp() bool {
if w.cursor > 0 { if w.cursor > 0 {
w.cursor-- w.cursor--
return true return true
@@ -200,7 +200,7 @@ func (w *List) MoveUp() bool {
return false return false
} }
func (w *List) MoveDown() bool { func (w *SimpleList) MoveDown() bool {
if w.cursor < len(w.list)-1 { if w.cursor < len(w.list)-1 {
w.cursor++ w.cursor++
return true return true
@@ -210,11 +210,11 @@ func (w *List) MoveDown() bool {
} }
return false return false
} }
func (w *List) SetTitle(ttl string) { w.title = ttl } func (w *SimpleList) SetTitle(ttl string) { w.title = ttl }
func (w *List) SetList(l []string) { w.list = l } func (w *SimpleList) SetList(l []string) { w.list = l }
func (w *List) Clear() { w.list = []string{} } func (w *SimpleList) Clear() { w.list = []string{} }
func (w *List) Add(l string) { w.list = append(w.list, l) } func (w *SimpleList) Add(l string) { w.list = append(w.list, l) }
func (w *List) Remove(l string) { func (w *SimpleList) Remove(l string) {
var idx int var idx int
var found bool var found bool
for idx = range w.list { for idx = range w.list {
@@ -228,7 +228,7 @@ func (w *List) Remove(l string) {
} }
} }
func (w *List) SetBorder(brd []rune) { func (w *SimpleList) SetBorder(brd []rune) {
if len(brd) == 0 { if len(brd) == 0 {
w.border = wh.BRD_SIMPLE w.border = wh.BRD_SIMPLE
} else { } else {
@@ -236,19 +236,19 @@ func (w *List) SetBorder(brd []rune) {
} }
} }
func (w *List) SetItemStyle(idx int, s tcell.Style) { w.itemsStyle[idx] = s } func (w *SimpleList) SetItemStyle(idx int, s tcell.Style) { w.itemsStyle[idx] = s }
func (w *List) SetItem(idx int, txt string) { func (w *SimpleList) SetItem(idx int, txt string) {
if len(w.list) < idx { if len(w.list) < idx {
w.list[idx] = txt w.list[idx] = txt
} }
} }
func (w *List) SelectedIndex() int { return w.cursor } func (w *SimpleList) SelectedIndex() int { return w.cursor }
func (w *List) ClearBorder() { w.border = []rune{} } func (w *SimpleList) ClearBorder() { w.border = []rune{} }
func (w *List) SetOnSelect(s func(int, string) bool) { w.onSelect = s } func (w *SimpleList) SetOnSelect(s func(int, string) bool) { w.onSelect = s }
func (w *List) SetVimMode(b bool) { w.vimMode = b } func (w *SimpleList) SetVimMode(b bool) { w.vimMode = b }
func (w *List) SetLogger(l func(string, ...any)) { w.logger = l } func (w *SimpleList) SetLogger(l func(string, ...any)) { w.logger = l }
func (w *List) Log(txt string, args ...any) { func (w *SimpleList) Log(txt string, args ...any) {
if w.logger != nil { if w.logger != nil {
w.logger(txt, args...) w.logger(txt, args...)
} }

View File

@@ -91,7 +91,6 @@ func (w *TopMenuLayout) HandleResize(ev *tcell.EventResize) {
if w.widget != nil { if w.widget != nil {
w.widget.HandleResize(tcell.NewEventResize(w.w, w.h-1)) w.widget.HandleResize(tcell.NewEventResize(w.w, w.h-1))
w.Log("Widget Size: %d,%d", w.widget.GetW(), w.widget.GetH())
x, y := 0, 1 x, y := 0, 1
switch w.layoutFlags.AlignH() { switch w.layoutFlags.AlignH() {