You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a source-only C++ library that implements a spatial navigation algorithm for graphical user interfaces. The way it works is pretty simple:
@@ -19,6 +20,7 @@ This is a source-only C++ library that implements a spatial navigation algorithm
19
20
20
21
Spatial navigation is surprisingly tricky. Guessing which GUI item the user wanted to focus is difficult, and depends on the program, the GUI, and more. There are also a few things that take work to implement, like the ability to loop around once the edge of the GUI is reached, or how to handle GUI items with more items inside. This library aims to ease those burdens.
* Support for looping around the edges of the GUI.
45
-
* Support for parent items that have children items inside.
46
-
* Customizable heuristics.
47
-
* Basic debugging logic.
46
+
* Support for looping around the edges of the GUI (see `Manager::settings`).
47
+
* Support for parent items that have children items that can overflow inside (see `Manager::setParentItem`).
48
+
* Customizable heuristics (see `Manager::heuristics`).
49
+
* Basic debugging logic (see `SPAT_NAV_DEBUG`).
48
50
* Fairly light, and fairly simple.
49
51
* Very agnostic, and with no external dependencies.
50
-
* Unit tests.
52
+
* Simple unit test coverage for the library itself.
53
+
54
+
55
+
## Important information
56
+
57
+
* For simplicity's sake, each item is identified with a `void *`. In your application you probably identify your widgets with an index number or a pointer, so just cast that to a `void *` freely. `nullptr` (zero) is reserved for "none", however.
58
+
* To work with parent and children items:
59
+
* Note that parent items are never eligible for being focused.
60
+
* For children items, specify their position in normal GUI coordinates, even if they overflow past the parent's borders.
61
+
* If you don't provide a valid starting point for navigation, it will use 0,0 for the focus position and size. Your users will probably prefer if you pick the first available widget, or the one closest to the mouse cursor.
62
+
63
+
64
+
## Troubleshooting
65
+
66
+
* When looping through an edge of the GUI, it's skipping over an item.
67
+
* Make sure there's at least a small gap between the items and the edges of the GUI. If it doesn't, you can manually grow the limits by 0.01 without any real drawback.
68
+
* The algorithm is picking the wrong item and I can't understand why.
69
+
* Try defining `SPAT_NAV_DEBUG` (or uncomment its line near the top of the header file). Then on every frame draw onto the window the contents provided by `Manager::lastNavInfo` in whatever way you want. This should help you understand what the algorithm is doing and what you can customize to make it do what you want.
70
+
* There's an item a bit out of the way, but I can't seem to reach it.
71
+
* Try `Manager::heuristics::singleLoopPass`.
72
+
73
+
74
+
## Inner workings notes
75
+
76
+
* For parent and children items:
77
+
* Children items that are overflowing get flattened. In essence the algorithm pretends they exist at the border of the parent, just very very thin.
78
+
* This approach allows the relative position between items to be kept, whilst also ensuring that navigating into the parent item correctly navigates to the most obvious child item.
79
+
* Other approaches were possible, but much more complex to implement.
80
+
* Because of this approach, you have to be wary that while hierarchies can be deeper than one level, the deeper you go the sooner you run into floating-point imprecisions. It should be fine for any normal application though.
81
+
* The algorithm rotates all widgets such that right (positive X) points to the direction of the navigation.
82
+
* Navigation only works in the four cardinal directions. Free angles were considered, but deemed to be way too unreasonable to implement.
0 commit comments