Menu tweaks
Spinner?
This commit is contained in:
@@ -22,6 +22,9 @@ THE SOFTWARE.
|
||||
package widgets
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
wh "git.bullercodeworks.com/brian/tcell-widgets/helpers"
|
||||
"github.com/gdamore/tcell"
|
||||
)
|
||||
@@ -36,7 +39,7 @@ type MenuItem struct {
|
||||
x, y int
|
||||
w, h int
|
||||
|
||||
menuType MenuType
|
||||
menuType MenuType // TODO: Handle Horizontal
|
||||
cursor int
|
||||
items []*MenuItem
|
||||
onPressed func() bool
|
||||
@@ -112,22 +115,33 @@ func (w *MenuItem) Draw(screen tcell.Screen) {
|
||||
if !w.visible {
|
||||
return
|
||||
}
|
||||
st := w.style.Reverse(w.active).Dim(w.disabled).Italic(w.disabled)
|
||||
st := w.style.Dim(w.disabled).Italic(w.disabled)
|
||||
// st := w.style.Reverse(w.active).Dim(w.disabled).Italic(w.disabled)
|
||||
x, y := w.x, w.y
|
||||
wd := w.w
|
||||
wh.DrawText(x, y, wh.PadR(w.label, wd), st, screen)
|
||||
y += 1
|
||||
// wd := w.w
|
||||
if w.expanded {
|
||||
if len(w.items) > 0 {
|
||||
wh.TitledBorderFilled(w.x-1, w.y, w.x+w.WantW(), w.y+w.WantH(), w.label, wh.BRD_CSIMPLE, w.style, screen)
|
||||
}
|
||||
x += 1
|
||||
for i := range w.items {
|
||||
// TODO: Use DrawOffset
|
||||
w.items[i].SetPos(Coord{X: x, Y: y})
|
||||
w.items[i].Draw(screen)
|
||||
y++
|
||||
wh.DrawText(x, y, fmt.Sprintf("╭%s╮", w.label), st, screen)
|
||||
wh.DrawText(x+1, y, fmt.Sprintf("%s", w.label), st.Reverse(true), screen)
|
||||
y += 1
|
||||
if len(w.items) > 0 {
|
||||
wh.TitledBorderFilled(w.x-1, y, w.x+w.WantW(), y+w.WantH(), fmt.Sprintf("╯%s╰", strings.Repeat(" ", len(w.label))), wh.BRD_CSIMPLE, w.style, screen)
|
||||
}
|
||||
x += 1
|
||||
y += 1
|
||||
// pos := w.GetPos()
|
||||
for i := range w.items {
|
||||
// TODO: Use DrawOffset
|
||||
// pos.DrawOffset(w.items[i], screen)
|
||||
w.items[i].SetPos(Coord{X: x, Y: y})
|
||||
w.items[i].Draw(screen)
|
||||
y++
|
||||
}
|
||||
} else {
|
||||
wh.DrawText(x, y, fmt.Sprintf(" %s ", w.label), st.Reverse(true), screen)
|
||||
}
|
||||
} else {
|
||||
wh.DrawText(x, y, fmt.Sprintf(" %s ", w.label), st, screen)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +171,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() + 1
|
||||
ret = w.items[i].WantW() + 2
|
||||
// TODO: Figure offset of subitems
|
||||
}
|
||||
}
|
||||
@@ -184,6 +198,7 @@ func (w *MenuItem) Expand(e bool) {
|
||||
w.expanded = e
|
||||
}
|
||||
}
|
||||
func (w *MenuItem) Expanded() bool { return w.expanded }
|
||||
|
||||
func (w *MenuItem) updateActive() {
|
||||
for i := range w.items {
|
||||
@@ -192,6 +207,9 @@ func (w *MenuItem) updateActive() {
|
||||
}
|
||||
|
||||
func (w *MenuItem) MoveUp(ev *tcell.EventKey) bool {
|
||||
if len(w.items) == 0 {
|
||||
return false
|
||||
}
|
||||
// Look for a previous enabled item
|
||||
st := w.cursor
|
||||
i := (w.cursor - 1 + len(w.items)) % len(w.items)
|
||||
@@ -206,6 +224,9 @@ func (w *MenuItem) MoveUp(ev *tcell.EventKey) bool {
|
||||
}
|
||||
|
||||
func (w *MenuItem) MoveDown(ev *tcell.EventKey) bool {
|
||||
if len(w.items) == 0 {
|
||||
return false
|
||||
}
|
||||
// Look for next enabled item
|
||||
st := w.cursor
|
||||
i := (st + 1) % len(w.items)
|
||||
@@ -218,6 +239,7 @@ func (w *MenuItem) MoveDown(ev *tcell.EventKey) bool {
|
||||
w.updateActive()
|
||||
return true
|
||||
}
|
||||
func (w *MenuItem) Label() string { return w.label }
|
||||
func (w *MenuItem) SetLabel(lbl string) { w.label = lbl }
|
||||
func (w *MenuItem) SetDisabled(d bool) { w.disabled = d }
|
||||
func (w *MenuItem) IsDisabled() bool { return w.disabled }
|
||||
|
||||
Reference in New Issue
Block a user