mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 21:35:54 +03:00
[GH-ISSUE #311] Named primitives for fast access with a single widget instance #235
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#235
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 @lenormf on GitHub (Jun 17, 2019).
Original GitHub issue: https://github.com/rivo/tview/issues/311
Hi,
It'd be nice to be able to get a widget instance from one of its ancestors. When creating an intricate layout with e.g. a
Flex, code that needs to operate on the children widgets must have access to the variable that stores said widgets:It would be more convenient (and scalable) to be able to assign a name/tag (as a string) to widgets, and be able to get their instance using only the parent:
HTH.
@rivo commented on GitHub (Jun 18, 2019):
I'm not going to rule this out completely for the far future but I find that how users organize widgets is very individual and I'm not sure your suggestion (or any other in that vein) will cover most users' needs. I also don't like that
SetName()would need to be added to all primitives (likely conflicting with page names) andGetWidget()would always require a cast to do anything useful.In your specific case, it probably won't require much code to come up with a structure like this. A simple
mapcould do the trick already:@lenormf commented on GitHub (Jun 19, 2019):
I came up with the function names off the top of my head to describe the problem as well as possible, they can be changed.
Since widgets can have different types, a cast is inevitable.
As for storing the instances in a global object, it would be redundant with the framework itself, as the widgets are already stored by it, all we need is a function that returns a given instance.