diff --git a/git/widget.go b/git/widget.go index 89aad5a2..894d71b5 100644 --- a/git/widget.go +++ b/git/widget.go @@ -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 } diff --git a/todo/widget.go b/todo/widget.go index f529f53e..e06c007c 100644 --- a/todo/widget.go +++ b/todo/widget.go @@ -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 } diff --git a/wtf/billboard_modal.go b/wtf/billboard_modal.go index 552ffb21..70137c2a 100644 --- a/wtf/billboard_modal.go +++ b/wtf/billboard_modal.go @@ -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 }