DrawOffset
This commit is contained in:
33
alert.go
33
alert.go
@@ -39,7 +39,7 @@ type Alert struct {
|
||||
visible bool
|
||||
tabbable bool
|
||||
|
||||
layout *AbsoluteLayout
|
||||
layout *LinearLayout
|
||||
title string
|
||||
message *Text
|
||||
btnOk, btnCancel *Button
|
||||
@@ -59,19 +59,25 @@ func (w *Alert) Init(id string, style tcell.Style) {
|
||||
w.id = id
|
||||
w.style = style
|
||||
|
||||
w.layout = NewAbsoluteLayout("alertlayout", tcell.StyleDefault)
|
||||
w.layout = NewLinearLayout("alertlayout", tcell.StyleDefault)
|
||||
|
||||
w.message = NewText(fmt.Sprintf("%s-text", id), style)
|
||||
w.layout.AddAnchored(w.message, Coord{X: 0, Y: 0}, AnchorC)
|
||||
w.layout.Add(w.message)
|
||||
|
||||
btnLayout := NewLinearLayout("alertbtn-layout", tcell.StyleDefault)
|
||||
btnLayout.SetOrientation(LinLayH)
|
||||
|
||||
w.btnCancel = NewButton(fmt.Sprintf("%s-cancel", id), style)
|
||||
w.btnCancel.SetLabel("Cancel")
|
||||
w.layout.Add(w.btnCancel)
|
||||
btnLayout.Add(w.btnCancel)
|
||||
|
||||
w.btnOk = NewButton(fmt.Sprintf("%s-select", id), style)
|
||||
w.btnOk.SetLabel("Ok")
|
||||
w.btnOk.SetActive(true)
|
||||
w.layout.AddAnchored(w.btnOk, Coord{X: -2, Y: 0}, AnchorBR)
|
||||
btnLayout.Add(w.btnOk)
|
||||
|
||||
w.btnCancel = NewButton(fmt.Sprintf("%s-cancel", id), style)
|
||||
w.btnCancel.SetLabel("Cancel")
|
||||
w.layout.AddAnchored(w.btnCancel, Coord{X: 2, Y: 0}, AnchorBL)
|
||||
w.layout.Add(btnLayout)
|
||||
|
||||
w.keyMap = NewKeyMap(map[tcell.Key]func(ev *tcell.EventKey) bool{
|
||||
tcell.KeyTab: w.SelectNext,
|
||||
@@ -130,11 +136,16 @@ func (w *Alert) Draw(screen tcell.Screen) {
|
||||
}
|
||||
|
||||
wh.TitledBorderFilled(w.x, w.y, w.x+w.w, w.y+w.h, w.title, wh.BRD_SIMPLE, w.style, screen)
|
||||
w.layout.Draw(screen)
|
||||
// w.message.Draw(screen)
|
||||
// w.btnOk.Draw(screen)
|
||||
// w.btnCancel.Draw(screen)
|
||||
w.layout.DrawOffset(w.GetPos(), screen)
|
||||
}
|
||||
|
||||
func (w *Alert) DrawOffset(c Coord, screen tcell.Screen) {
|
||||
p := w.GetPos()
|
||||
w.SetPos(p.Add(c))
|
||||
w.Draw(screen)
|
||||
w.SetPos(p)
|
||||
}
|
||||
|
||||
func (w *Alert) Active() bool { return w.active }
|
||||
func (w *Alert) SetActive(a bool) { w.active = a }
|
||||
func (w *Alert) Visible() bool { return w.visible }
|
||||
|
||||
Reference in New Issue
Block a user