tview icon indicating copy to clipboard operation
tview copied to clipboard

Is there a simple way to switch whether the widget in flex is fullscreen in flex?

Open hleft opened this issue 1 year ago • 3 comments

I didn't find an easy way, so when I have two widgets, I do this, but if I add more widgets, the judgment seems to be troublesome.

boxRight := tview.NewFlex().SetDirection(tview.FlexRow).AddItem(conversationView, 0, 3, false).AddItem(inputField, 0, 1, true)

_, _, _, fullheight := boxRight.GetInnerRect()

for i := 0; i < boxRight.GetItemCount(); i++ {
		item := boxRight.GetItem(i)
		_, _, _, height := item.GetRect()
		if item.HasFocus() {
			if height < fullheight-2 {
				boxRight.ResizeItem(item, 0, 999)
			} else {
				if item == inputField {
					boxRight.ResizeItem(item, 0, 1)
				}
				if item == conversationView {
					boxRight.ResizeItem(item, 0, 3)
				}
			}
		}
}

Another related question is I want to get Proportion, but didn't find a way..

type flexItem struct {
	Item       Primitive // The item to be positioned. May be nil for an empty item.
	FixedSize  int       // The item's fixed size which may not be changed, 0 if it has no fixed size.
	Proportion int       // The item's proportion.
	Focus      bool      // Whether or not this item attracts the layout's focus.
}

hleft avatar Mar 23 '23 15:03 hleft

To be honest, I don't really understand what you're trying to achieve. Maybe you'll want to provide a graphic which illustrates the layout you're trying to create, along with more detailed explanations? From the code you provided, I don't know what the goal is.

Given the title of this issue, I can say that no, there is no simple way in Flex to switch to full-screen. I would suggest that you use a Pages element which contains the element to be "magnified" and temporarily put it in the front.

rivo avatar Mar 25 '23 21:03 rivo

@rivo Sorry for not expressing clearly, what I think is, when I create a flex layout, add some items into it, and then focus on any of the items, can this part be simply full screen

sideBar      := tview.NewList()
mainBox    := tview.NewFlex().SetDirection(tview.FlexRow).AddItem(conversation, 0, 3, false).AddItem(inputField, 0, 1, true)
box := tview.NewFlex().
		AddItem(mainBox, 0, 4, true).
		AddItem(sideBar, 0, 1, false)

for example, when I focus sidebar or conversation or inputField , I want to toggle whether it is full screen or not

hleft avatar Mar 26 '23 01:03 hleft

@hleft Rather than try and handle it with the flex. I would have the flex with your items in a tview.Pages.

The first or back will be the layout/original flex. When they focus a sidebar/input then you add that widget/item to the tview.Pages and specify resize:true and when it switches to it/brings to front. it will be fullscreened. This way you can eliminate dealing with the flex resizing, and the pages widget can handle displaying it full screen without needing to remove/fuck with it in the flex.

Unfocusing the item or whatever will simply RemovePage or HidePage it to reveal the original flex.

digitallyserviced avatar Apr 02 '23 22:04 digitallyserviced