[GH-ISSUE #125] Changing Flex proportions #97

Closed
opened 2026-03-04 01:01:55 +03:00 by kerem · 3 comments
Owner

Originally created by @benweidig on GitHub (May 26, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/125

Hi,

in my app I want to change the Flex proprotions with the keyboard. So far I need to rebuild the complete Flex with the new proportion, because the flexItem array is private.

First I thought about just building a modified Flex exposing the necessary fields, but Box doesn't expose focus, so I needed to copy/paste Box, too.

What are your opinions on how to solve this? Rebuild the Flex every time, or extend Flex to expose the flexItem array in a non-breaking way? Or did I miss something?

Originally created by @benweidig on GitHub (May 26, 2018). Original GitHub issue: https://github.com/rivo/tview/issues/125 Hi, in my app I want to change the Flex proprotions with the keyboard. So far I need to rebuild the complete Flex with the new proportion, because the flexItem array is private. First I thought about just building a modified Flex exposing the necessary fields, but Box doesn't expose focus, so I needed to copy/paste Box, too. What are your opinions on how to solve this? Rebuild the Flex every time, or extend Flex to expose the flexItem array in a non-breaking way? Or did I miss something?
kerem closed this issue 2026-03-04 01:01:55 +03:00
Author
Owner

@rivo commented on GitHub (Jun 7, 2018):

Sorry for the late reply. You didn't miss something, it didn't exist. I've added a new function ResizeItem() to Flex which should do what you're trying to do. Let me know if this works for you.

<!-- gh-comment-id:395400394 --> @rivo commented on GitHub (Jun 7, 2018): Sorry for the late reply. You didn't miss something, it didn't exist. I've added a new function `ResizeItem()` to `Flex` which should do what you're trying to do. Let me know if this works for you.
Author
Owner

@benweidig commented on GitHub (Jun 9, 2018):

Thx for the update, but the code isn't working as intended.

The item provided by range is not pass-by-reference, it's pass-by-value. Only accessing an array by index is pass-by-reference. And to save it in a new variable we need to access it with &.

Proposed fix:

func (f *Flex) ResizeItem(p Primitive, fixedSize, proportion int) *Flex {
	for idx := range f.items {
		item := &f.items[idx]
		if item.Item == p {
			item.FixedSize = fixedSize
			item.Proportion = proportion
		}
	}
	return f
}
<!-- gh-comment-id:395971321 --> @benweidig commented on GitHub (Jun 9, 2018): Thx for the update, but the code isn't working as intended. The `item` provided by `range` is not pass-by-reference, it's pass-by-value. Only accessing an array by index is pass-by-reference. And to save it in a new variable we need to access it with `&`. Proposed fix: ```go func (f *Flex) ResizeItem(p Primitive, fixedSize, proportion int) *Flex { for idx := range f.items { item := &f.items[idx] if item.Item == p { item.FixedSize = fixedSize item.Proportion = proportion } } return f } ```
Author
Owner

@rivo commented on GitHub (Jun 9, 2018):

Good point. Actually, I think the items slice should be a slice of *flexItem's anyway. (Not sure why I didn't do it this way but this was one of the very early types so maybe it grew over time.)

The latest commit should have fixed it. Please let me know if it works for you now.

<!-- gh-comment-id:395995868 --> @rivo commented on GitHub (Jun 9, 2018): Good point. Actually, I think the `items` slice should be a slice of `*flexItem`'s anyway. (Not sure why I didn't do it this way but this was one of the very early types so maybe it grew over time.) The latest commit should have fixed it. Please let me know if it works for you now.
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#97
No description provided.