A few fixes
This commit is contained in:
@@ -41,6 +41,7 @@ type Alert struct {
|
||||
layout *LinearLayout
|
||||
title string
|
||||
message *Text
|
||||
btnLayout *LinearLayout
|
||||
btnOk, btnCancel *Button
|
||||
|
||||
keyMap KeyMap
|
||||
@@ -64,18 +65,18 @@ func (w *Alert) Init(id string, style tcell.Style) {
|
||||
w.message = NewText(fmt.Sprintf("%s-text", id), style)
|
||||
w.layout.Add(w.message)
|
||||
|
||||
btnLayout := NewLinearLayout("alertbtn-layout", tcell.StyleDefault)
|
||||
btnLayout.SetOrientation(LinLayH)
|
||||
w.layout.Add(btnLayout)
|
||||
w.btnLayout = NewLinearLayout("alertbtn-layout", tcell.StyleDefault)
|
||||
w.btnLayout.SetOrientation(LinLayH)
|
||||
w.layout.Add(w.btnLayout)
|
||||
|
||||
w.btnCancel = NewButton(fmt.Sprintf("%s-cancel", id), style)
|
||||
w.btnCancel.SetLabel("Cancel")
|
||||
btnLayout.Add(w.btnCancel)
|
||||
w.btnLayout.Add(w.btnCancel)
|
||||
|
||||
w.btnOk = NewButton(fmt.Sprintf("%s-select", id), style)
|
||||
w.btnOk.SetLabel("Ok")
|
||||
w.btnOk.SetActive(true)
|
||||
btnLayout.Add(w.btnOk)
|
||||
w.btnLayout.Add(w.btnOk)
|
||||
|
||||
w.keyMap = NewKeyMap(map[tcell.Key]func(ev *tcell.EventKey) bool{
|
||||
tcell.KeyTab: w.SelectNext,
|
||||
@@ -90,9 +91,14 @@ func (w *Alert) Init(id string, style tcell.Style) {
|
||||
func (w *Alert) Id() string { return w.id }
|
||||
func (w *Alert) 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())
|
||||
if w.w > w.MinW() {
|
||||
w.w = w.MinW()
|
||||
}
|
||||
if w.h > w.MinH() {
|
||||
w.h = w.MinH()
|
||||
}
|
||||
// Trim space for the borders and pass on the size to the layout
|
||||
w.layout.SetPos(Coord{X: 1, Y: 1})
|
||||
w.layout.HandleResize(tcell.NewEventResize(w.w-2, w.h-2))
|
||||
}
|
||||
|
||||
@@ -107,13 +113,10 @@ func (w *Alert) Draw(screen tcell.Screen) {
|
||||
if !w.visible {
|
||||
return
|
||||
}
|
||||
dS := w.style
|
||||
if !w.active {
|
||||
dS = dS.Dim(true)
|
||||
}
|
||||
dS := w.style.Dim(!w.active)
|
||||
|
||||
wh.TitledBorderFilled(w.x, w.y, w.x+w.w, w.y+w.h, w.title, wh.BRD_SIMPLE, w.style, screen)
|
||||
w.GetPos().DrawOffset(w, screen)
|
||||
wh.TitledBorderFilled(w.x, w.y, w.x+w.w, w.y+w.h, w.title, wh.BRD_SIMPLE, dS, screen)
|
||||
w.GetPos().DrawOffset(w.layout, screen)
|
||||
}
|
||||
|
||||
func (w *Alert) Active() bool { return w.active }
|
||||
@@ -144,12 +147,12 @@ func (w *Alert) WantH() int {
|
||||
|
||||
// Borders + Buttons
|
||||
func (w *Alert) MinW() int {
|
||||
return 2 + wh.Max(w.message.MinW(), (w.btnOk.MinW()+w.btnCancel.MinW()))
|
||||
return 5 + wh.Max(w.message.MinW(), (w.btnOk.MinW()+w.btnCancel.MinW()))
|
||||
}
|
||||
|
||||
// Borders + Buttons + 2 lines for message
|
||||
func (w *Alert) MinH() int {
|
||||
return 2 + w.message.MinH() + w.btnOk.MinH()
|
||||
return 5 + w.message.MinH() + w.btnOk.MinH()
|
||||
}
|
||||
|
||||
func (w *Alert) SetTitle(ttl string) { w.title = ttl }
|
||||
@@ -180,6 +183,7 @@ func (w *Alert) Do(ev *tcell.EventKey) bool {
|
||||
func (w *Alert) SetLogger(l func(string, ...any)) {
|
||||
w.logger = l
|
||||
w.layout.SetLogger(l)
|
||||
w.btnLayout.SetLogger(l)
|
||||
}
|
||||
|
||||
func (w *Alert) Log(txt string, args ...any) {
|
||||
|
||||
Reference in New Issue
Block a user