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
f3a55a1127
commit
55c4c26772
@ -23,6 +23,10 @@ const HelpText = `
|
||||
arrow right: Next git repository
|
||||
`
|
||||
|
||||
const offscreen = -1000
|
||||
const modalWidth = 80
|
||||
const modalHeight = 7
|
||||
|
||||
type Widget struct {
|
||||
wtf.TextWidget
|
||||
|
||||
@ -131,11 +135,18 @@ func (widget *Widget) modalForm(lbl, text string) *tview.Form {
|
||||
return form
|
||||
}
|
||||
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.SetRect(offscreen, offscreen, modalWidth, modalHeight)
|
||||
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
|
||||
}
|
||||
|
@ -34,6 +34,10 @@ const HelpText = `
|
||||
space: Check the selected item on or off
|
||||
`
|
||||
|
||||
const offscreen = -1000
|
||||
const modalWidth = 80
|
||||
const modalHeight = 7
|
||||
|
||||
type Widget struct {
|
||||
wtf.TextWidget
|
||||
|
||||
@ -267,11 +271,18 @@ func (widget *Widget) modalForm(lbl, text string) *tview.Form {
|
||||
}
|
||||
|
||||
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.SetRect(offscreen, offscreen, modalWidth, modalHeight)
|
||||
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
|
||||
}
|
||||
|
@ -35,19 +35,19 @@ func NewBillboardModal(text string, closeFunc func()) *tview.Frame {
|
||||
textView.SetBackgroundColor(tview.Styles.ContrastBackgroundColor)
|
||||
textView.SetInputCapture(keyboardIntercept)
|
||||
|
||||
thing := tview.NewFrame(textView)
|
||||
thing.SetRect(offscreen, offscreen, modalWidth, modalHeight)
|
||||
frame := tview.NewFrame(textView)
|
||||
frame.SetRect(offscreen, offscreen, modalWidth, modalHeight)
|
||||
|
||||
drawFunc := func(screen tcell.Screen, x, y, width, height int) (int, int, int, int) {
|
||||
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
|
||||
}
|
||||
|
||||
thing.SetBackgroundColor(tview.Styles.ContrastBackgroundColor)
|
||||
thing.SetBorder(true)
|
||||
thing.SetBorders(1, 1, 0, 0, 1, 1)
|
||||
thing.SetDrawFunc(drawFunc)
|
||||
frame.SetBackgroundColor(tview.Styles.ContrastBackgroundColor)
|
||||
frame.SetBorder(true)
|
||||
frame.SetBorders(1, 1, 0, 0, 1, 1)
|
||||
frame.SetDrawFunc(drawFunc)
|
||||
|
||||
return thing
|
||||
return frame
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user