[GH-ISSUE #359] [Question] How do I display form above the grid? #267

Closed
opened 2026-03-04 01:03:28 +03:00 by kerem · 4 comments
Owner

Originally created by @skanehira on GitHub (Oct 30, 2019).
Original GitHub issue: https://github.com/rivo/tview/issues/359

Previously, in #264 you could use "pages" to display the form in the grid, but now it seems that you can't.

demo

Is there a way to display the form while displaying the grid?

Originally created by @skanehira on GitHub (Oct 30, 2019). Original GitHub issue: https://github.com/rivo/tview/issues/359 Previously, in #264 you could use "pages" to display the form in the grid, but now it seems that you can't. ![demo](https://user-images.githubusercontent.com/7888591/67858794-6d8d0700-fb5d-11e9-8d1d-20a6692bf81d.gif) Is there a way to display the form while displaying the grid?
kerem closed this issue 2026-03-04 01:03:28 +03:00
Author
Owner

@rivo commented on GitHub (Nov 27, 2019):

I don't think anything has changed in how Pages renders pages. You can still display two primitives at the same time. Here's some example code:

package main

import "github.com/rivo/tview"

func main() {
	grid := tview.NewGrid()
	grid.AddItem(tview.NewBox().SetTitle("Box1").SetBorder(true), 0, 0, 1, 1, 0, 0, false)
	grid.AddItem(tview.NewBox().SetTitle("Box2").SetBorder(true), 1, 0, 1, 1, 0, 0, false)

	form := tview.NewForm()
	form.AddInputField("Input:", "", 20, nil, nil)
	form.AddButton("Click me", nil)
	form.SetBorder(true)

	pages := tview.NewPages()
	pages.AddPage("grid", grid, true, true)
	pages.AddPage("form", form, false, true)

	if err := tview.NewApplication().SetRoot(pages, true).Run(); err != nil {
		panic(err)
	}
}

And what it looks like:

image

I guess the question is, what function are you using to display your form?

<!-- gh-comment-id:559135062 --> @rivo commented on GitHub (Nov 27, 2019): I don't think anything has changed in how `Pages` renders pages. You can still display two primitives at the same time. Here's some example code: ```go package main import "github.com/rivo/tview" func main() { grid := tview.NewGrid() grid.AddItem(tview.NewBox().SetTitle("Box1").SetBorder(true), 0, 0, 1, 1, 0, 0, false) grid.AddItem(tview.NewBox().SetTitle("Box2").SetBorder(true), 1, 0, 1, 1, 0, 0, false) form := tview.NewForm() form.AddInputField("Input:", "", 20, nil, nil) form.AddButton("Click me", nil) form.SetBorder(true) pages := tview.NewPages() pages.AddPage("grid", grid, true, true) pages.AddPage("form", form, false, true) if err := tview.NewApplication().SetRoot(pages, true).Run(); err != nil { panic(err) } } ``` And what it looks like: ![image](https://user-images.githubusercontent.com/480930/69736508-e9fe1000-1132-11ea-9663-4d08874ad9e2.png) I guess the question is, what function are you using to display your form?
Author
Owner

@skanehira commented on GitHub (Nov 28, 2019):

@rivo My sample code is following.
I use Grid to show form or some primitive in center.

package main

import "github.com/rivo/tview"

func main() {
    grid := tview.NewGrid()
    grid.AddItem(tview.NewBox().SetTitle("Box1").SetBorder(true), 0, 0, 1, 1, 0, 0, false)
    grid.AddItem(tview.NewBox().SetTitle("Box2").SetBorder(true), 1, 0, 1, 1, 0, 0, false)

    form := tview.NewForm()
    form.AddInputField("Input:", "", 20, nil, nil)
    form.AddButton("Click me", nil)
    form.SetBorder(true)

    pages := tview.NewPages()
    pages.AddPage("grid", grid, true, true)

    pages.AddPage("form", modal(form), true, true).ShowPage("grid")

    if err := tview.NewApplication().SetRoot(pages, true).Run(); err != nil {
        panic(err)
    }
}

func modal(p tview.Primitive) tview.Primitive {
    return tview.NewGrid().SetColumns(0, 0, 0).SetRows(0, 0, 0).AddItem(p, 1, 1, 1, 1, 0, 0, true)
}

image

When I use github.com/rivo/tview v0.0.0-20190324182152-8a9e26fab0ff with go modules, my sample code will work good.
But github.com/rivo/tview v0.0.0-20191127181827-9c225ecd5722 is doesn't work fine.

Is there any other way to put primitives such as form in the center of the screen?

<!-- gh-comment-id:559455497 --> @skanehira commented on GitHub (Nov 28, 2019): @rivo My sample code is following. I use `Grid` to show form or some primitive in center. ```go package main import "github.com/rivo/tview" func main() { grid := tview.NewGrid() grid.AddItem(tview.NewBox().SetTitle("Box1").SetBorder(true), 0, 0, 1, 1, 0, 0, false) grid.AddItem(tview.NewBox().SetTitle("Box2").SetBorder(true), 1, 0, 1, 1, 0, 0, false) form := tview.NewForm() form.AddInputField("Input:", "", 20, nil, nil) form.AddButton("Click me", nil) form.SetBorder(true) pages := tview.NewPages() pages.AddPage("grid", grid, true, true) pages.AddPage("form", modal(form), true, true).ShowPage("grid") if err := tview.NewApplication().SetRoot(pages, true).Run(); err != nil { panic(err) } } func modal(p tview.Primitive) tview.Primitive { return tview.NewGrid().SetColumns(0, 0, 0).SetRows(0, 0, 0).AddItem(p, 1, 1, 1, 1, 0, 0, true) } ``` ![image](https://user-images.githubusercontent.com/7888591/69802625-4c333f80-121d-11ea-9b28-86bbdc82cfdc.png) When I use `github.com/rivo/tview v0.0.0-20190324182152-8a9e26fab0ff` with go modules, my sample code will work good. But `github.com/rivo/tview v0.0.0-20191127181827-9c225ecd5722` is doesn't work fine. Is there any other way to put primitives such as form in the center of the screen?
Author
Owner

@rivo commented on GitHub (Nov 29, 2019):

Right. Thanks for this additional info. This one line in the Grid code that was missing made me think it was a bug when I worked on fixing something else. But it wasn't. It's back in there now so it should work as before.

<!-- gh-comment-id:559680122 --> @rivo commented on GitHub (Nov 29, 2019): Right. Thanks for this additional info. This one line in the `Grid` code that was missing made me think it was a bug when I worked on fixing something else. But it wasn't. It's back in there now so it should work as before.
Author
Owner

@skanehira commented on GitHub (Nov 29, 2019):

@rivo Thanks :)
Now it works fine :)

<!-- gh-comment-id:559693741 --> @skanehira commented on GitHub (Nov 29, 2019): @rivo Thanks :) Now it works fine :)
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#267
No description provided.