[GH-ISSUE #81] Forms should grow underlying box's size #62

Closed
opened 2026-03-04 01:01:35 +03:00 by kerem · 1 comment
Owner

Originally created by @joegrasse on GitHub (Mar 15, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/81

From what I can tell, a Form is based off of a base Box. A base box has a size of w:15 h:10. Unless you draw a Form full size, the size of the form will be the base box size. It would be nice if the form would grow the base box size. This is so that you don't have to specifically set the Forms size, if you don't want it full screen.

Example:

package main

import (
	"github.com/rivo/tview"
)

func main() {

	app := tview.NewApplication()

	form := tview.NewForm().
		AddInputField("Item 1", "", 20, nil, nil).
		AddInputField("Item 2", "", 20, nil, nil).
		AddInputField("Item 3", "", 20, nil, nil).
		AddInputField("Item 4", "", 20, nil, nil).
		AddInputField("Item 5", "", 20, nil, nil).
		AddPasswordField("Password", "", 10, '*', nil).
		AddButton("Save", nil).
		AddButton("Quit", nil)

	form.SetBorder(true).SetTitle("Enter Tunnel Info").SetTitleAlign(tview.AlignLeft) // To actually see the full form I would need to do .SetRect(0, 0, 35, 18)

	if err := app.SetRoot(form, false).Run(); err != nil { // don't want form full screen
		panic(err)
	}
}

Originally created by @joegrasse on GitHub (Mar 15, 2018). Original GitHub issue: https://github.com/rivo/tview/issues/81 From what I can tell, a Form is based off of a base Box. A base box has a size of w:15 h:10. Unless you draw a Form full size, the size of the form will be the base box size. It would be nice if the form would grow the base box size. This is so that you don't have to specifically set the Forms size, if you don't want it full screen. Example: ```Go package main import ( "github.com/rivo/tview" ) func main() { app := tview.NewApplication() form := tview.NewForm(). AddInputField("Item 1", "", 20, nil, nil). AddInputField("Item 2", "", 20, nil, nil). AddInputField("Item 3", "", 20, nil, nil). AddInputField("Item 4", "", 20, nil, nil). AddInputField("Item 5", "", 20, nil, nil). AddPasswordField("Password", "", 10, '*', nil). AddButton("Save", nil). AddButton("Quit", nil) form.SetBorder(true).SetTitle("Enter Tunnel Info").SetTitleAlign(tview.AlignLeft) // To actually see the full form I would need to do .SetRect(0, 0, 35, 18) if err := app.SetRoot(form, false).Run(); err != nil { // don't want form full screen panic(err) } } ```
kerem closed this issue 2026-03-04 01:01:35 +03:00
Author
Owner

@rivo commented on GitHub (Mar 15, 2018):

Box positions/sizes (and therefore the positions of all primitives) are always specified top-down. This is not like HTML/CSS where the content size of an element is measured and can propagate up the hierarchy. I'm not planning on implementing a browser-like layout engine. This is quite complicated and will add tremendous complexity to tview (while breaking backwards compatibility).

You can set the second SetRoot() argument to true to use the entire screen. Alternatively, there is Flex and Grid which will adapt to screen size. I know that this requires you to estimate the size of your form yourself but in most cases, this should not be a problem.

<!-- gh-comment-id:373465614 --> @rivo commented on GitHub (Mar 15, 2018): `Box` positions/sizes (and therefore the positions of all primitives) are always specified top-down. This is not like HTML/CSS where the content size of an element is measured and can propagate up the hierarchy. I'm not planning on implementing a browser-like layout engine. This is quite complicated and will add tremendous complexity to `tview` (while breaking backwards compatibility). You can set the second `SetRoot()` argument to `true` to use the entire screen. Alternatively, there is `Flex` and `Grid` which will adapt to screen size. I know that this requires you to estimate the size of your form yourself but in most cases, this should not be a problem.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#62
No description provided.