Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How do I display form above the grid? #359

Closed
skanehira opened this issue Oct 30, 2019 · 4 comments
Closed

[Question] How do I display form above the grid? #359

skanehira opened this issue Oct 30, 2019 · 4 comments

Comments

@skanehira
Copy link

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?

@rivo
Copy link
Owner

rivo commented 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?

@skanehira
Copy link
Author

skanehira commented 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?

@rivo rivo closed this as completed in 82b05c9 Nov 29, 2019
@rivo
Copy link
Owner

rivo commented 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.

@skanehira
Copy link
Author

@rivo Thanks :)
Now it works fine :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants