mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 21:35:54 +03:00
[GH-ISSUE #285] Understanding Flex & Layouts #220
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#220
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @joshuamcginnis on GitHub (May 29, 2019).
Original GitHub issue: https://github.com/rivo/tview/issues/285
I'm struggling with understanding the various layout options. For example, I'm trying to implement a basic "Main Menu" for a little app I'm experimenting with.
From what I can gather, I should create a "Page" that the user can switch to during the app lifecycle. And this Page will need to contain the necessary layout primitives that implement the menu itself.
However; for what I want to do above, a regular Modal won't work. Nor will a text box since a TextBox cannot have a title and a primitive (List) cannot be added inside of the box. I'll need to do some degree of nesting of layouts and elements.
The wiki shows this example for how to create a more robust modal-like box that is centered:
I understand why the top-level
AddItemsare doing; creating three rows which the middle row being 2x relative sizing to the top and bottomnilprimitive rows. But why does the innerFlexrow also haveniltop and bottom rows?In general, do you have any tips for approaching layout and developing a more thorough understanding of how to layout the various components of an app?
When taking in account the various layout types, the need to often nest them, keeping track of explicit vs. proportional sizing, ordering of rows / cols - I'm finding the the cognitive load builds rather quickly.
I'd appreciate any thoughts on this.
@rivo commented on GitHub (Jun 2, 2019):
The Wiki example you mentioned starts with centering a primitive using
Flexbut further down, there is a simpler example that usesGridwhich, in my opinion, is the better choice as you don't need to nest twoFlexitems to achieve the same effect.The
Modalclass is not very flexible. It is meant to be used to display simple messages or confirmation prompts.For your menu example, you could wrap a
Listinto aFrame(see also the Wiki for an example). TheListcould be used to handle the menu options. TheFramecould be used to display a title etc.If all of your pages have this layout, it makes sense to wrap this into a function or class that automatically generates the
Pageobject given title, menu options, and so on. I'm taking this approach my applications as well as in the presentation demo:github.com/rivo/tview@29b0d3cfbf/demos/presentation/main.go (L23-L26)Each slide in the presentation then implements this function type, which makes it very easy to switch between slides.
Let me know if this helps you.
@joshuamcginnis commented on GitHub (Jun 3, 2019):
@rivo I really appreciate you taking the time to read through my issue and provide a thoughtful response with many pointers. 🙏 Thanks for that.
It would be awesome if you could share the source for your demo (presuming we're talking about the one in the main project readme). I think seeing many examples of more complex workflows would really help me to best understand how to lay out my project.
@rivo commented on GitHub (Jun 9, 2019):
I can't release my private applications but the presentation demo is part of the repo. You'll find it in the
demos/presentation/folder.