1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #pragma once |
4 | |
5 | #include "BsPrerequisites.h" |
6 | |
7 | namespace bs |
8 | { |
9 | /** @addtogroup GUI |
10 | * @{ |
11 | */ |
12 | |
13 | /** |
14 | * Contains a set of elements that can be navigated between using keyboard or gamepad buttons (i.e. the 'Tab' button) |
15 | */ |
16 | class BS_EXPORT GUINavGroup |
17 | { |
18 | public: |
19 | /** Creates a new navigation group. */ |
20 | static SPtr<GUINavGroup> create(); |
21 | |
22 | /** Sets the focus to the first element in the group. */ |
23 | void focusFirst(); |
24 | |
25 | /** |
26 | * Sets the focus to the next element in the navigation order. |
27 | * |
28 | * @param[in] anchor Element relative to which to determine the navigation. This is usually the currently |
29 | * focused element. |
30 | */ |
31 | void focusNext(GUIElement* anchor); |
32 | |
33 | private: |
34 | friend class GUIElement; |
35 | friend class GUIManager; |
36 | |
37 | /** |
38 | * Registers a new element with the tab group. Caller must ensure the element has been removed from the previous |
39 | * tab group, if any. |
40 | * |
41 | * @param[in] element Element to register. |
42 | * @param[in] tabIdx Index of the element in the tab group. Set setIndex() for more information on how |
43 | * is the index interpreted. |
44 | */ |
45 | void registerElement(GUIElement* element, INT32 tabIdx = 0); |
46 | |
47 | /** |
48 | * Sets the index of a previously registered element in the tab group. The index determines in what order will the |
49 | * element be visited compared to other elements. |
50 | * |
51 | * Index 0 is reserved and means that tab index will be calculated automatically based on element position. The |
52 | * rest of indices are visited in order from lowest to highest. Negative indices are visited before auto-positioned |
53 | * 0-index element, and positive indices are visited after. |
54 | */ |
55 | void setIndex(GUIElement* element, INT32 tabIdx); |
56 | |
57 | /** Unregisters an element from the tab group. */ |
58 | void unregisterElement(GUIElement* element); |
59 | |
60 | /** Sets the focus to the top-left element. Only iterates over elements with no explicit tab index. */ |
61 | void focusTopLeft(); |
62 | |
63 | UnorderedMap<GUIElement*, INT32> mElements; |
64 | MultiMap<INT32, GUIElement*> mOrderedElements; |
65 | }; |
66 | |
67 | /** @} */ |
68 | } |