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.focusable = true
w.keyMap = NewKeyMap(map[tcell.Key]func(ev *tcell.EventKey) bool{
tcell.KeyEnter: func(_ *tcell.EventKey) bool {
if w.state == CHECKBOX_ON {
w.state = CHECKBOX_OFF
} else {
w.state = CHECKBOX_ON
}
return true
},
tcell.KeyEnter: w.ToggleState,
})
w.AddToKeyMap(NewRuneMap(map[rune]func(ev *tcell.EventKey) bool{
' ': w.ToggleState,
}))
}
func (w *Checkbox) Id() string { return w.id }
func (w *Checkbox) HandleResize(ev *tcell.EventResize) {
@@ -105,7 +101,7 @@ func (w *Checkbox) Draw(screen tcell.Screen) {
if w.active {
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 }
@@ -152,3 +148,12 @@ func (w *Checkbox) SetStateRunes(runes []rune) {
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
fileList *List
fileList *SimpleList
btnSelect, btnCancel *Button
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].SetPos(Coord{X: x, Y: y})
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) SetData(data []string) {
// w.data = data
w.Log("%s: Setting Searcher (filtered)Data (%d length)", w.Id(), len(data))
w.data = data
w.filteredData = data
w.updateFilter()
@@ -287,7 +286,6 @@ func (w *Searcher) updateFilter() {
var selVal string
data := []string{}
copy(data, w.filteredData)
w.Log("%s: Setting Searcher Data (%d length)", w.Id(), len(data))
if len(data) > 0 && len(data) > w.cursor {
selVal = data[w.cursor]
}

View File

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

View File

@@ -91,7 +91,6 @@ func (w *TopMenuLayout) HandleResize(ev *tcell.EventResize) {
if w.widget != nil {
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
switch w.layoutFlags.AlignH() {