Much Work
- Definable KeyMaps - Change 'Tabbable' to just use 'Focusable'
This commit is contained in:
53
wdgt_list.go
53
wdgt_list.go
@@ -33,7 +33,6 @@ type List struct {
|
||||
active bool
|
||||
visible bool
|
||||
focusable bool
|
||||
tabbable bool
|
||||
|
||||
x, y int
|
||||
w, h int
|
||||
@@ -86,13 +85,24 @@ func (w *List) Init(id string, style tcell.Style) {
|
||||
return false
|
||||
})
|
||||
w.itemsStyle = make(map[int]tcell.Style)
|
||||
w.tabbable = true
|
||||
w.focusable = true
|
||||
}
|
||||
func (w *List) Id() string { return w.id }
|
||||
func (w *List) 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) {
|
||||
for k := range km.Keys {
|
||||
w.keyMap.Remove(k)
|
||||
}
|
||||
for r := range km.Runes {
|
||||
w.keyMap.RemoveRune(r)
|
||||
}
|
||||
}
|
||||
|
||||
func (w *List) HandleKey(ev *tcell.EventKey) bool {
|
||||
if !w.active || !w.focusable {
|
||||
return false
|
||||
@@ -122,7 +132,7 @@ func (w *List) Draw(screen tcell.Screen) {
|
||||
rev = true
|
||||
}
|
||||
txt := w.list[i]
|
||||
if len(txt) > w.w-brdSz {
|
||||
if len(txt) > w.w-brdSz && w.w-brdSz >= 0 {
|
||||
txt = txt[:(w.w - brdSz)]
|
||||
}
|
||||
var ok bool
|
||||
@@ -135,24 +145,23 @@ 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) SetTabbable(b bool) { w.tabbable = b }
|
||||
func (w *List) Tabbable() bool { return w.tabbable }
|
||||
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 {
|
||||
lng := wh.Longest(w.list)
|
||||
if len(w.border) > 0 {
|
||||
@@ -179,8 +188,6 @@ func (w *List) MinW() int {
|
||||
|
||||
func (w *List) MinH() int { return 4 }
|
||||
|
||||
func (w *List) SetFocusable(f bool) { w.focusable = f }
|
||||
|
||||
func (w *List) SetCursorWrap(b bool) { w.cursorWrap = b }
|
||||
func (w *List) MoveUp(ev *tcell.EventKey) bool {
|
||||
if w.cursor > 0 {
|
||||
|
||||
Reference in New Issue
Block a user