Improving Grid's focus handling and primitive nil checks #1103
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey, love the library. I was playing around with the Grid view and noticed that the Grid.AddItem wouldn't respect the focus boolean sometimes. Then I checked the Draw method for the Grid and noticed that only the one element is picked for focus during a draw and it's not necessarily the latest one added.
A small sidequest: When a nil primitive is added to the Grid, it will panic when trying to deal with inputHandling. So I just added a check for p == nil to prevent nil primitives from being added to the table. This way, whomever is using this library can just insert things into the Grid without having to nil check all over the place.
You can test this by making a split pane grid and then adding two tables into each pane. It'll work the first time you call AddItem on any Primitive, but subsiquent AddItems call will mess up the focus. (maybe i'm using it wrong ?)
my test repo: https://github.com/zveinn/term-test
So I wrote a small loop to clear focus on all elements to force focus on the added item (only if focus is true)
I'm not sure if it's intended to have multiple elements within a grid that can have focus at the same time, if so then feel free to close the PR.