From d2d0a5ca2cf8ad94c020c4d0c85de7a530dd3b7f Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Tue, 9 Jun 2020 15:51:28 -0700 Subject: [PATCH] Add Modal.GetForm and Modal.GetFrame --- modal.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/modal.go b/modal.go index f534113..7ecff34 100644 --- a/modal.go +++ b/modal.go @@ -6,7 +6,8 @@ import ( // Modal is a centered message window used to inform the user or prompt them // for an immediate decision. It needs to have at least one button (added via -// AddButtons()) or it will never disappear. +// AddButtons()) or it will never disappear. You may embed primitives within a +// Modal by adding them to the Form returned by GetForm. // // See https://github.com/rivo/tview/wiki/Modal for an example. type Modal struct { @@ -95,6 +96,16 @@ func (m *Modal) SetText(text string) *Modal { return m } +// GetForm returns the form embedded in the window. +func (m *Modal) GetForm() *Form { + return m.form +} + +// GetFrame returns the frame embedded in the window. +func (m *Modal) GetFrame() *Frame { + return m.frame +} + // AddButtons adds buttons to the window. There must be at least one button and // a "done" handler so the window can be closed again. func (m *Modal) AddButtons(labels []string) *Modal { @@ -144,6 +155,8 @@ func (m *Modal) HasFocus() bool { // Draw draws this primitive onto the screen. func (m *Modal) Draw(screen tcell.Screen) { + formItemCount := m.form.GetFormItemCount() + // Calculate the width of this modal. buttonsWidth := 0 for _, button := range m.form.buttons { @@ -165,7 +178,7 @@ func (m *Modal) Draw(screen tcell.Screen) { } // Set the modal's position and size. - height := len(lines) + 6 + height := len(lines) + (formItemCount * 2) + 6 width += 4 x := (screenWidth - width) / 2 y := (screenHeight - height) / 2