Some work

This commit is contained in:
2026-02-18 19:12:13 -06:00
parent 4b51c5b00f
commit 18ead7b486
3 changed files with 67 additions and 70 deletions

View File

@@ -32,11 +32,10 @@ type Alert struct {
id string
style tcell.Style
x, y int
w, h int
active bool
visible bool
focusable bool
x, y int
w, h int
active bool
visible 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) {
@@ -131,23 +129,28 @@ func (w *Alert) SetActive(a bool) bool {
w.active = a
return w.active
}
func (w *Alert) Visible() bool { return w.visible }
func (w *Alert) SetVisible(a bool) { w.visible = a }
func (w *Alert) SetX(x int) { w.x = x }
func (w *Alert) SetY(y int) { w.y = y }
func (w *Alert) GetX() int { return w.x }
func (w *Alert) GetY() int { return w.y }
func (w *Alert) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
func (w *Alert) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *Alert) SetW(x int) { w.w = x }
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) Visible() bool { return w.visible }
func (w *Alert) SetVisible(a bool) { w.visible = a }
func (w *Alert) SetX(x int) { w.x = x }
func (w *Alert) SetY(y int) { w.y = y }
func (w *Alert) GetX() int { return w.x }
func (w *Alert) GetY() int { return w.y }
func (w *Alert) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
func (w *Alert) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *Alert) SetW(x int) { w.w = x }
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) 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)
}