[GH-ISSUE #385] Make items in Flex public #283

Closed
opened 2026-03-04 01:03:37 +03:00 by kerem · 2 comments
Owner

Originally created by @esell on GitHub (Jan 13, 2020).
Original GitHub issue: https://github.com/rivo/tview/issues/385

Does it make sense to expose the items variable in the Flex primitive (https://github.com/rivo/tview/blob/master/flex.go#L31) ?

The reason I am asking is I have a simple 4 column layout where I would like to cycle through each column when a certain key is pressed. Right now I've setup a SetInputCapture() to listen for the key press and then SetFocus() on the next item, effectively moving the focus from column to column. The problem with this method is that I need to hard code the primitive that should get focus next. It would be awesome to be able to just use something like flex.Items[n+1] or something similar. Since the data is already there in the items variable, it seems like a great data source for something like this.

Originally created by @esell on GitHub (Jan 13, 2020). Original GitHub issue: https://github.com/rivo/tview/issues/385 Does it make sense to expose the `items` variable in the Flex primitive (https://github.com/rivo/tview/blob/master/flex.go#L31) ? The reason I am asking is I have a simple 4 column layout where I would like to cycle through each column when a certain key is pressed. Right now I've setup a `SetInputCapture()` to listen for the key press and then `SetFocus()` on the next item, effectively moving the focus from column to column. The problem with this method is that I need to hard code the primitive that should get focus next. It would be awesome to be able to just use something like `flex.Items[n+1]` or something similar. Since the data is already there in the `items` variable, it seems like a great data source for something like this.
kerem closed this issue 2026-03-04 01:03:37 +03:00
Author
Owner

@tslocum commented on GitHub (Jan 16, 2020):

Hey @esell, does a Flex.GetItem method which returns the primitive at that index solve your use case? I will submit a PR adding it if so.

<!-- gh-comment-id:575379792 --> @tslocum commented on GitHub (Jan 16, 2020): Hey @esell, does a `Flex.GetItem` method which returns the primitive at that index solve your use case? I will submit a PR adding it if so.
Author
Owner

@esell commented on GitHub (Jan 16, 2020):

Good timing @tslocum :). I actually just swapped out for your cview and used the Flex.GetChildren (https://godoc.org/git.sr.ht/~tslocum/cview#Flex.GetChildren) function, it was exactly what I was looking for.
Before that I was just keeping track of everything in a slice I created.

<!-- gh-comment-id:575388604 --> @esell commented on GitHub (Jan 16, 2020): Good timing @tslocum :). I actually just swapped out for your cview and used the Flex.GetChildren (https://godoc.org/git.sr.ht/~tslocum/cview#Flex.GetChildren) function, it was exactly what I was looking for. Before that I was just keeping track of everything in a slice I created.
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#283
No description provided.