So much work
This commit is contained in:
30
menu_item.go
30
menu_item.go
@@ -27,13 +27,14 @@ import (
|
||||
)
|
||||
|
||||
type MenuItem struct {
|
||||
id string
|
||||
label string
|
||||
style tcell.Style
|
||||
active bool
|
||||
visible bool
|
||||
x, y int
|
||||
w, h int
|
||||
id string
|
||||
label string
|
||||
style tcell.Style
|
||||
active bool
|
||||
visible bool
|
||||
tabbable bool
|
||||
x, y int
|
||||
w, h int
|
||||
|
||||
menuType MenuType
|
||||
cursor int
|
||||
@@ -72,6 +73,7 @@ func (w *MenuItem) Init(id string, style tcell.Style) {
|
||||
for i := range w.items {
|
||||
w.items[i].SetActive(i == w.cursor)
|
||||
}
|
||||
w.tabbable = true
|
||||
}
|
||||
func (w *MenuItem) Id() string { return w.id }
|
||||
func (w *MenuItem) HandleResize(ev *tcell.EventResize) {}
|
||||
@@ -101,7 +103,10 @@ func (w *MenuItem) Draw(screen tcell.Screen) {
|
||||
h.DrawText(x, y, h.PadR(w.label, wd), st, screen)
|
||||
y += 1
|
||||
if w.expanded {
|
||||
x += 2
|
||||
if len(w.items) > 0 {
|
||||
h.TitledBorderFilled(w.x-1, w.y, w.x+w.WantW(), w.y+w.WantH(), w.label, h.BRD_CSIMPLE, w.style, screen)
|
||||
}
|
||||
x += 1
|
||||
for i := range w.items {
|
||||
w.items[i].SetPos(Coord{X: x, Y: y})
|
||||
w.items[i].Draw(screen)
|
||||
@@ -122,6 +127,7 @@ func (w *MenuItem) SetX(x int) { w.x = x }
|
||||
func (w *MenuItem) SetY(y int) { w.y = y }
|
||||
func (w *MenuItem) GetX() int { return w.x }
|
||||
func (w *MenuItem) GetY() int { return w.y }
|
||||
func (w *MenuItem) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
|
||||
func (w *MenuItem) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
|
||||
func (w *MenuItem) SetW(x int) { w.w = x }
|
||||
func (w *MenuItem) SetH(y int) { w.h = y }
|
||||
@@ -132,7 +138,7 @@ func (w *MenuItem) WantW() int {
|
||||
if len(w.items) > 0 {
|
||||
for i := range w.items {
|
||||
if w.items[i].WantW() > ret {
|
||||
ret = w.items[i].WantW()
|
||||
ret = w.items[i].WantW() + 1
|
||||
// TODO: Figure offset of subitems
|
||||
}
|
||||
}
|
||||
@@ -149,8 +155,10 @@ func (w *MenuItem) WantH() int {
|
||||
}
|
||||
return ret
|
||||
}
|
||||
func (w *MenuItem) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
|
||||
func (w *MenuItem) Focusable() bool { return !w.disabled }
|
||||
func (w *MenuItem) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
|
||||
func (w *MenuItem) Focusable() bool { return !w.disabled }
|
||||
func (w *MenuItem) SetTabbable(b bool) { w.tabbable = b }
|
||||
func (w *MenuItem) Tabbable() bool { return w.tabbable }
|
||||
|
||||
// How much width this item wants
|
||||
func (w *MenuItem) Expand(e bool) {
|
||||
|
||||
Reference in New Issue
Block a user