texus / TGUI

Cross-platform modern c++ GUI

Home Page:https://tgui.eu

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enabling keyboard navigation in tree views?

ethindp opened this issue · comments

Is there a way I can make the tree view select an item when the arrow keys are used within the tree view, similar to how tree views function in retained-mode GUIs? I can't seem to interact with the tree view with the keyboard, only focus it.

I'll see if I can add it in the next few days. It's just missing because nobody asked for it until now and I personally never used a keyboard to navigate a tree view.

I tested on a linux and windows computer and found slightly different tree view behavior (e.g. on linux the left arrow never collapsed the tree), so I'll just implement it in the way that makes the most sense to me (the windows behavior in case of the left arrow).

The following is what I would implement:

  • Up arrow: Select node above (irrelevant of hierarchy). Does nothing if root item is selected.
  • Down arrow: Select node below (irrelevant of hierarchy). Does nothing if most bottom item is selected, even if the selected item is a collapsed node.
  • Right arrow: Expands node if it was collapsed, otherwise moves to first child if it has one. If a leaf node is selected then do the same as pressing bottom arrow.
  • Left arrow: Collapses node if it was expanded, otherwise move to parent item. Does nothing if root item is selected.

Technically I should also implement some behavior when ctrl or shift is pressed, but I noticed that I can't do that since the tree view in TGUI only supports selecting a single item at a time.

List boxes and list views already supported arrow keys.
Combo boxes don't seem to have a proper focus state (at least the renderer doesn't support changing the looks of it), so there isn't a moment where it makes sense for it to respond to arrow keys in the current implementation. The list that is opened when pressing a combo box is actually just a ListBox widget, so using arrow keys should also work in that list.

Feel free to report other places where keyboard navigation is missing when you come across them though.