Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d4ec3f210c | |||
| 18ead7b486 |
@@ -36,7 +36,6 @@ type Alert struct {
|
||||
w, h int
|
||||
active bool
|
||||
visible bool
|
||||
focusable bool
|
||||
|
||||
layout *LinearLayout
|
||||
title string
|
||||
@@ -90,7 +89,6 @@ func (w *Alert) Init(id string, style tcell.Style) {
|
||||
NewKey(BuildEK(tcell.KeyUp), w.SelectNext),
|
||||
NewKey(BuildEK(tcell.KeyEnter), w.Do),
|
||||
)
|
||||
w.focusable = true
|
||||
}
|
||||
func (w *Alert) Id() string { return w.id }
|
||||
func (w *Alert) HandleResize(ev *tcell.EventResize) {
|
||||
@@ -144,10 +142,15 @@ func (w *Alert) SetH(y int) { w.h = y }
|
||||
func (w *Alert) GetW() int { return w.w }
|
||||
func (w *Alert) GetH() int { return w.y }
|
||||
func (w *Alert) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
|
||||
func (w *Alert) Focusable() bool { return w.focusable }
|
||||
func (w *Alert) SetFocusable(b bool) { w.focusable = b }
|
||||
func (w *Alert) WantW() int {
|
||||
return 4 + wh.Max(w.message.WantW(), (w.btnOk.WantW()+w.btnCancel.WantW()))
|
||||
var okW, cancelW int
|
||||
if !w.btnOk.Visible() {
|
||||
okW = w.btnOk.WantW()
|
||||
}
|
||||
if !w.btnCancel.Visible() {
|
||||
cancelW = w.btnCancel.WantW()
|
||||
}
|
||||
return 4 + wh.Max(w.message.WantW(), (okW+cancelW))
|
||||
}
|
||||
|
||||
func (w *Alert) WantH() int {
|
||||
@@ -167,13 +170,11 @@ func (w *Alert) SetMessage(msg string) { w.message.SetText(msg) }
|
||||
|
||||
func (w *Alert) SetOkPressed(b func() bool) {
|
||||
w.btnOk.SetVisible(b != nil)
|
||||
w.btnOk.SetFocusable(b != nil)
|
||||
w.btnOk.SetOnPressed(b)
|
||||
}
|
||||
|
||||
func (w *Alert) SetCancelPressed(b func() bool) {
|
||||
w.btnCancel.SetVisible(b != nil)
|
||||
w.btnCancel.SetFocusable(b != nil)
|
||||
w.btnCancel.SetOnPressed(b)
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ type Button struct {
|
||||
|
||||
active bool
|
||||
visible bool
|
||||
focusable bool
|
||||
keyMap *KeyMap
|
||||
|
||||
onPressed func() bool
|
||||
@@ -59,7 +58,6 @@ func (w *Button) Init(id string, style tcell.Style) {
|
||||
w.visible = true
|
||||
w.keyMap = NewKeyMap(NewKey(BuildEK(tcell.KeyEnter), func(ev *tcell.EventKey) bool { return w.onPressed() }))
|
||||
w.onPressed = func() bool { return false }
|
||||
w.focusable = true
|
||||
}
|
||||
func (w *Button) Id() string { return w.id }
|
||||
func (w *Button) HandleResize(ev *tcell.EventResize) {
|
||||
@@ -81,16 +79,20 @@ func (w *Button) Draw(screen tcell.Screen) {
|
||||
if !w.visible {
|
||||
return
|
||||
}
|
||||
dStyle := w.style.Dim(!w.active)
|
||||
dStyle := w.style.Dim(!w.active).Bold(w.active)
|
||||
lbl := w.label
|
||||
switch w.h {
|
||||
case 1:
|
||||
lbl := w.label
|
||||
lb, rb := "[", "]"
|
||||
if w.active {
|
||||
lb, rb = ">", "<"
|
||||
}
|
||||
if w.w < len(lbl) {
|
||||
lbl = lbl[:w.w]
|
||||
} else if w.w == len(w.label)+2 {
|
||||
lbl = fmt.Sprintf("[%s]", lbl)
|
||||
lbl = fmt.Sprintf("%s%s%s", lb, lbl, rb)
|
||||
} else if w.w > len(w.label)+2 {
|
||||
lbl = fmt.Sprintf("[%s]", wh.Center(lbl, w.w-2))
|
||||
lbl = fmt.Sprintf("%s%s%s", lb, wh.Center(lbl, w.w-2), rb)
|
||||
}
|
||||
wh.DrawText(w.x, w.y, lbl, dStyle, screen)
|
||||
return
|
||||
@@ -113,7 +115,7 @@ func (w *Button) Draw(screen tcell.Screen) {
|
||||
wh.DrawText(w.x, w.y, "[]", dStyle, screen)
|
||||
return
|
||||
}
|
||||
lbl := wh.Center(w.label, w.w-2)
|
||||
lbl = wh.Center(w.label, w.w-2)
|
||||
wh.DrawText(w.x, w.y, fmt.Sprintf("╭%s╮", strings.Repeat("─", w.w-2)), dStyle, screen)
|
||||
wh.DrawText(w.x, w.y+1, fmt.Sprintf("│%s│", wh.Center(lbl, w.w-2)), dStyle, screen)
|
||||
wh.DrawText(w.x, w.y+2, fmt.Sprintf("╰%s╯", strings.Repeat("─", w.w-2)), dStyle, screen)
|
||||
@@ -140,8 +142,6 @@ func (w *Button) GetH() int { return w.h }
|
||||
func (w *Button) WantW() int { return 4 + len(w.label) }
|
||||
func (w *Button) WantH() int { return 3 }
|
||||
func (w *Button) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
|
||||
func (w *Button) Focusable() bool { return w.focusable }
|
||||
func (w *Button) SetFocusable(b bool) { w.focusable = b }
|
||||
func (w *Button) MinW() int { return len(w.label) + 2 }
|
||||
func (w *Button) MinH() int { return 1 }
|
||||
|
||||
|
||||
@@ -78,33 +78,33 @@ func (w *TopMenuLayout) Init(id string, s tcell.Style) {
|
||||
)
|
||||
}
|
||||
|
||||
func (w *TopMenuLayout) HideMenu() bool {
|
||||
if w.menu == nil {
|
||||
return false
|
||||
}
|
||||
w.menu.SetActive(false)
|
||||
func (w *TopMenuLayout) ToggleMenu() bool {
|
||||
if w.menu != nil {
|
||||
w.menu.SetActive(!w.menu.Active())
|
||||
if w.widget != nil {
|
||||
w.widget.SetActive(true)
|
||||
w.widget.SetActive(!w.menu.Active())
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (w *TopMenuLayout) ShowMenu() bool {
|
||||
if w.menu == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
func (w *TopMenuLayout) ShowMenu() bool {
|
||||
if w.menu != nil {
|
||||
w.menu.SetActive(true)
|
||||
if w.widget != nil {
|
||||
w.widget.SetActive(false)
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (w *TopMenuLayout) ToggleMenu() bool {
|
||||
func (w *TopMenuLayout) HideMenu() bool {
|
||||
if w.menu != nil {
|
||||
w.menu.SetActive(!w.menu.Active())
|
||||
w.menu.SetActive(false)
|
||||
if w.widget != nil {
|
||||
w.widget.SetActive(!w.menu.Active())
|
||||
w.widget.SetActive(true)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user