mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Close #168. Modal dialogs now center onscreen properly
This commit is contained in:
parent
cca845d4ff
commit
5e13618813
@ -23,6 +23,10 @@ const HelpText = `
|
|||||||
arrow right: Next git repository
|
arrow right: Next git repository
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const offscreen = -1000
|
||||||
|
const modalWidth = 80
|
||||||
|
const modalHeight = 7
|
||||||
|
|
||||||
type Widget struct {
|
type Widget struct {
|
||||||
wtf.TextWidget
|
wtf.TextWidget
|
||||||
|
|
||||||
@ -131,11 +135,18 @@ func (widget *Widget) modalForm(lbl, text string) *tview.Form {
|
|||||||
return form
|
return form
|
||||||
}
|
}
|
||||||
func (widget *Widget) modalFrame(form *tview.Form) *tview.Frame {
|
func (widget *Widget) modalFrame(form *tview.Form) *tview.Frame {
|
||||||
_, _, w, h := widget.View.GetInnerRect()
|
|
||||||
|
|
||||||
frame := tview.NewFrame(form).SetBorders(0, 0, 0, 0, 0, 0)
|
frame := tview.NewFrame(form).SetBorders(0, 0, 0, 0, 0, 0)
|
||||||
|
frame.SetRect(offscreen, offscreen, modalWidth, modalHeight)
|
||||||
frame.SetBorder(true)
|
frame.SetBorder(true)
|
||||||
frame.SetRect(w+20, h+2, 80, 7)
|
frame.SetBorders(1, 1, 0, 0, 1, 1)
|
||||||
|
|
||||||
|
drawFunc := func(screen tcell.Screen, x, y, width, height int) (int, int, int, int) {
|
||||||
|
w, h := screen.Size()
|
||||||
|
frame.SetRect((w/2)-(width/2), (h/2)-(height/2), width, height)
|
||||||
|
return x, y, width, height
|
||||||
|
}
|
||||||
|
|
||||||
|
frame.SetDrawFunc(drawFunc)
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,10 @@ const HelpText = `
|
|||||||
space: Check the selected item on or off
|
space: Check the selected item on or off
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const offscreen = -1000
|
||||||
|
const modalWidth = 80
|
||||||
|
const modalHeight = 7
|
||||||
|
|
||||||
type Widget struct {
|
type Widget struct {
|
||||||
wtf.TextWidget
|
wtf.TextWidget
|
||||||
|
|
||||||
@ -267,11 +271,18 @@ func (widget *Widget) modalForm(lbl, text string) *tview.Form {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) modalFrame(form *tview.Form) *tview.Frame {
|
func (widget *Widget) modalFrame(form *tview.Form) *tview.Frame {
|
||||||
_, _, w, h := widget.View.GetInnerRect()
|
|
||||||
|
|
||||||
frame := tview.NewFrame(form).SetBorders(0, 0, 0, 0, 0, 0)
|
frame := tview.NewFrame(form).SetBorders(0, 0, 0, 0, 0, 0)
|
||||||
|
frame.SetRect(offscreen, offscreen, modalWidth, modalHeight)
|
||||||
frame.SetBorder(true)
|
frame.SetBorder(true)
|
||||||
frame.SetRect(w+20, h+2, 80, 7)
|
frame.SetBorders(1, 1, 0, 0, 1, 1)
|
||||||
|
|
||||||
|
drawFunc := func(screen tcell.Screen, x, y, width, height int) (int, int, int, int) {
|
||||||
|
w, h := screen.Size()
|
||||||
|
frame.SetRect((w/2)-(width/2), (h/2)-(height/2), width, height)
|
||||||
|
return x, y, width, height
|
||||||
|
}
|
||||||
|
|
||||||
|
frame.SetDrawFunc(drawFunc)
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
}
|
}
|
||||||
|
@ -35,19 +35,19 @@ func NewBillboardModal(text string, closeFunc func()) *tview.Frame {
|
|||||||
textView.SetBackgroundColor(tview.Styles.ContrastBackgroundColor)
|
textView.SetBackgroundColor(tview.Styles.ContrastBackgroundColor)
|
||||||
textView.SetInputCapture(keyboardIntercept)
|
textView.SetInputCapture(keyboardIntercept)
|
||||||
|
|
||||||
thing := tview.NewFrame(textView)
|
frame := tview.NewFrame(textView)
|
||||||
thing.SetRect(offscreen, offscreen, modalWidth, modalHeight)
|
frame.SetRect(offscreen, offscreen, modalWidth, modalHeight)
|
||||||
|
|
||||||
drawFunc := func(screen tcell.Screen, x, y, width, height int) (int, int, int, int) {
|
drawFunc := func(screen tcell.Screen, x, y, width, height int) (int, int, int, int) {
|
||||||
w, h := screen.Size()
|
w, h := screen.Size()
|
||||||
thing.SetRect((w/2)-(width/2), (h/2)-(height/2), width, height)
|
frame.SetRect((w/2)-(width/2), (h/2)-(height/2), width, height)
|
||||||
return x, y, width, height
|
return x, y, width, height
|
||||||
}
|
}
|
||||||
|
|
||||||
thing.SetBackgroundColor(tview.Styles.ContrastBackgroundColor)
|
frame.SetBackgroundColor(tview.Styles.ContrastBackgroundColor)
|
||||||
thing.SetBorder(true)
|
frame.SetBorder(true)
|
||||||
thing.SetBorders(1, 1, 0, 0, 1, 1)
|
frame.SetBorders(1, 1, 0, 0, 1, 1)
|
||||||
thing.SetDrawFunc(drawFunc)
|
frame.SetDrawFunc(drawFunc)
|
||||||
|
|
||||||
return thing
|
return frame
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user