Wonkiness on layout

This commit is contained in:
2025-10-10 16:46:29 -05:00
parent 79a212e601
commit 7a1afd67ac
28 changed files with 362 additions and 156 deletions

View File

@@ -43,9 +43,10 @@ type SimpleList struct {
list []string
itemsStyle map[int]tcell.Style
onSelect func(int, string) bool
keyMap KeyMap
vimMode bool
onChange func(int, string) bool
onSelect func(int, string) bool
keyMap, customKeyMap KeyMap
vimMode bool
logger func(string, ...any)
}
@@ -84,22 +85,27 @@ func (w *SimpleList) Init(id string, style tcell.Style) {
}
return false
})
w.customKeyMap = BlankKeyMap()
w.itemsStyle = make(map[int]tcell.Style)
w.focusable = true
}
func (w *SimpleList) Id() string { return w.id }
func (w *SimpleList) HandleResize(ev *tcell.EventResize) {
w.w, w.h = ev.Size()
}
func (w *SimpleList) Id() string { return w.id }
func (w *SimpleList) HandleResize(ev *tcell.EventResize) { w.w, w.h = ev.Size() }
func (w *SimpleList) SetKeyMap(km KeyMap) { w.keyMap = km }
func (w *SimpleList) AddToKeyMap(km KeyMap) { w.keyMap.Merge(km) }
func (w *SimpleList) SetKeyMap(km KeyMap, def bool) {
if def {
w.keyMap = km
} else {
w.customKeyMap = km
}
}
func (w *SimpleList) AddToKeyMap(km KeyMap) { w.customKeyMap.Merge(km) }
func (w *SimpleList) RemoveFromKeyMap(km KeyMap) {
for k := range km.Keys {
w.keyMap.Remove(k)
w.customKeyMap.Remove(k)
}
for r := range km.Runes {
w.keyMap.RemoveRune(r)
w.customKeyMap.RemoveRune(r)
}
}
@@ -107,8 +113,10 @@ func (w *SimpleList) HandleKey(ev *tcell.EventKey) bool {
if !w.active || !w.focusable {
return false
}
return w.keyMap.Handle(ev)
b1, b2 := w.keyMap.Handle(ev), w.customKeyMap.Handle(ev)
return b1 || b2
}
func (w *SimpleList) HandleTime(ev *tcell.EventTime) {}
func (w *SimpleList) Draw(screen tcell.Screen) {
dS := w.style
@@ -192,9 +200,15 @@ func (w *SimpleList) SetCursorWrap(b bool) { w.cursorWrap = b }
func (w *SimpleList) MoveUp() bool {
if w.cursor > 0 {
w.cursor--
if w.onChange != nil {
w.onChange(w.cursor, w.list[w.cursor])
}
return true
} else if w.cursorWrap {
w.cursor = len(w.list) - 1
if w.onChange != nil {
w.onChange(w.cursor, w.list[w.cursor])
}
return true
}
return false
@@ -203,9 +217,15 @@ func (w *SimpleList) MoveUp() bool {
func (w *SimpleList) MoveDown() bool {
if w.cursor < len(w.list)-1 {
w.cursor++
if w.onChange != nil {
w.onChange(w.cursor, w.list[w.cursor])
}
return true
} else if w.cursorWrap {
w.cursor = 0
if w.onChange != nil {
w.onChange(w.cursor, w.list[w.cursor])
}
return true
}
return false
@@ -266,3 +286,7 @@ func (w *SimpleList) Log(txt string, args ...any) {
w.logger(txt, args...)
}
}
func (w *SimpleList) SetOnChange(c func(int, string) bool) { w.onChange = c }
func (w *SimpleList) GetAllItemStyles() map[int]tcell.Style { return w.itemsStyle }