I'm creating a React app that has a "SplitPane" component that is basically a div split horizontally or vertcally (The divider in the middle can be dragged for resizing):
____ _________ _________
| | | | | | | |
|____| |____|____| |__|______|
| |
|____|
These can be nested recursively, forming structure like the following:
_____________
| |___| |
| |___|___|
|_____|_____|_|
| | |
|_______|_____|
|_______|_____|
Or any other such arbitrary combination.
I would like the user to be able to reasonably switch between the cells with the arrow keys, but being that this is a component tree, it will look something like this in memory:
H
/ \
H V
/ \ / \
* * H *
/ \
* H
/ \
* *
Where:
- 'H' := horizontally split panes
- 'V' := vertically split panes
- '*' := leaf component
I would like to know if there is any sort of algorithm that can be used to easily traverse this tree to get the top, bottom, left, or right component which could be several branches away on the component tree.