Really figuring some things out
This commit is contained in:
30
list.go
30
list.go
@@ -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"
|
||||
)
|
||||
|
||||
@@ -35,9 +35,8 @@ type List struct {
|
||||
focusable bool
|
||||
tabbable bool
|
||||
|
||||
x, y int
|
||||
w, h int
|
||||
wantW, wantH int
|
||||
x, y int
|
||||
w, h int
|
||||
|
||||
border []rune
|
||||
cursor int
|
||||
@@ -86,8 +85,13 @@ func (w *List) Init(id string, style tcell.Style) {
|
||||
w.itemsStyle = make(map[int]tcell.Style)
|
||||
w.tabbable = true
|
||||
}
|
||||
func (w *List) Id() string { return w.id }
|
||||
func (w *List) HandleResize(ev *tcell.EventResize) {}
|
||||
func (w *List) Id() string { return w.id }
|
||||
func (w *List) 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())
|
||||
}
|
||||
|
||||
func (w *List) HandleKey(ev *tcell.EventKey) bool {
|
||||
if !w.active || !w.focusable {
|
||||
@@ -106,9 +110,9 @@ func (w *List) Draw(screen tcell.Screen) {
|
||||
if len(w.border) > 0 {
|
||||
brdSz = 2
|
||||
if len(w.title) > 0 {
|
||||
h.TitledBorderFilled(x, y, x+w.w, y+w.h, w.title, w.border, dS, screen)
|
||||
wh.TitledBorderFilled(x, y, x+w.w, y+w.h, w.title, w.border, dS, screen)
|
||||
} else {
|
||||
h.BorderFilled(x, y, x+w.w, y+w.h, w.border, dS, screen)
|
||||
wh.BorderFilled(x, y, x+w.w, y+w.h, w.border, dS, screen)
|
||||
}
|
||||
}
|
||||
x, y = x+1, y+1
|
||||
@@ -126,7 +130,7 @@ func (w *List) Draw(screen tcell.Screen) {
|
||||
if s, ok = w.itemsStyle[i]; !ok {
|
||||
s = dS
|
||||
}
|
||||
h.DrawText(x, y, txt, s.Reverse(rev), screen)
|
||||
wh.DrawText(x, y, txt, s.Reverse(rev), screen)
|
||||
y += 1
|
||||
}
|
||||
}
|
||||
@@ -156,7 +160,7 @@ 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) WantW() int {
|
||||
lng := h.Longest(w.list)
|
||||
lng := wh.Longest(w.list)
|
||||
if len(w.border) > 0 {
|
||||
return lng + 2
|
||||
}
|
||||
@@ -172,7 +176,7 @@ func (w *List) WantH() int {
|
||||
}
|
||||
|
||||
func (w *List) MinW() int {
|
||||
lng := h.Longest(w.list)
|
||||
lng := wh.Longest(w.list)
|
||||
if lng > 80 {
|
||||
lng = 80
|
||||
}
|
||||
@@ -224,9 +228,9 @@ func (w *List) Remove(l string) {
|
||||
|
||||
func (w *List) SetBorder(brd []rune) {
|
||||
if len(brd) == 0 {
|
||||
w.border = h.BRD_SIMPLE
|
||||
w.border = wh.BRD_SIMPLE
|
||||
} else {
|
||||
w.border = h.ValidateBorder(brd)
|
||||
w.border = wh.ValidateBorder(brd)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user