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 | #include "GUI/BsGUIElementContainer.h" |
7 | #include "GUI/BsGUIDropDownMenu.h" |
8 | |
9 | namespace bs |
10 | { |
11 | /** @addtogroup GUI-Internal |
12 | * @{ |
13 | */ |
14 | |
15 | /** GUI element that is used for representing entries in a drop down menu. */ |
16 | class BS_EXPORT GUIDropDownContent : public GUIElementContainer |
17 | { |
18 | /** Contains various GUI elements used for displaying a single menu entry. */ |
19 | struct VisibleElement |
20 | { |
21 | UINT32 idx = 0; |
22 | GUIButtonBase* button = nullptr; |
23 | GUITexture* separator = nullptr; |
24 | GUILabel* shortcutLabel = nullptr; |
25 | }; |
26 | |
27 | public: |
28 | /** Returns type name of the GUI element used for finding GUI element styles. */ |
29 | static const String& getGUITypeName(); |
30 | |
31 | /** |
32 | * Creates a new drop down contents element. |
33 | * |
34 | * @param[in] parent Parent sub-menu that owns the drop down contents. |
35 | * @param[in] dropDownData Data that will be used for initializing the child entries. |
36 | * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the |
37 | * GUIWidget the element is used on. If not specified default button style is used. |
38 | */ |
39 | static GUIDropDownContent* (GUIDropDownMenu::DropDownSubMenu* parent, const GUIDropDownData& dropDownData, |
40 | const String& style = StringUtil::BLANK); |
41 | |
42 | /** |
43 | * Creates a new drop down contents element. |
44 | * |
45 | * @param[in] parent Parent sub-menu that owns the drop down contents. |
46 | * @param[in] dropDownData Data that will be used for initializing the child entries. |
47 | * @param[in] options Options that allow you to control how is the element positioned and sized. |
48 | * This will override any similar options set by style. |
49 | * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the |
50 | * GUIWidget the element is used on. If not specified default button style is used. |
51 | */ |
52 | static GUIDropDownContent* (GUIDropDownMenu::DropDownSubMenu* parent, const GUIDropDownData& dropDownData, |
53 | const GUIOptions& options, const String& style = StringUtil::BLANK); |
54 | |
55 | /** |
56 | * Changes the range of the displayed elements. |
57 | * |
58 | * @note This must be called at least once after creation. |
59 | */ |
60 | void setRange(UINT32 start, UINT32 end); |
61 | |
62 | /** Returns height of a menu element at the specified index, in pixels. */ |
63 | UINT32 getElementHeight(UINT32 idx) const; |
64 | |
65 | /** |
66 | * Enables or disables keyboard focus. When keyboard focus is enabled the contents will respond to keyboard events. |
67 | */ |
68 | void setKeyboardFocus(bool focus); |
69 | |
70 | static constexpr const char* ENTRY_TOGGLE_STYLE_TYPE = "DropDownEntryToggleBtn" ; |
71 | static constexpr const char* ENTRY_STYLE_TYPE = "DropDownEntryBtn" ; |
72 | static constexpr const char* ENTRY_EXP_STYLE_TYPE = "DropDownEntryExpBtn" ; |
73 | static constexpr const char* SEPARATOR_STYLE_TYPE = "DropDownSeparator" ; |
74 | protected: |
75 | (GUIDropDownMenu::DropDownSubMenu* parent, const GUIDropDownData& dropDownData, |
76 | const String& style, const GUIDimensions& dimensions); |
77 | |
78 | /** Get localized name of a menu item element with the specified index. */ |
79 | HString getElementLocalizedName(UINT32 idx) const; |
80 | |
81 | /** @copydoc GUIElementContainer::_getOptimalSize */ |
82 | Vector2I _getOptimalSize() const override; |
83 | |
84 | /** @copydoc GUIElementContainer::_updateLayoutInternal */ |
85 | void _updateLayoutInternal(const GUILayoutData& data) override; |
86 | |
87 | /** @copydoc GUIElementContainer::styleUpdated */ |
88 | void styleUpdated() override; |
89 | |
90 | /** @copydoc GUIElementContainer::_commandEvent */ |
91 | bool _commandEvent(const GUICommandEvent& ev) override; |
92 | |
93 | /** @copydoc GUIElementContainer::_mouseEvent */ |
94 | bool _mouseEvent(const GUIMouseEvent& ev) override; |
95 | |
96 | /** |
97 | * Marks the element with the specified index as selected. |
98 | * |
99 | * @param[in] idx Index of the displayed element (indexing visible elements). |
100 | */ |
101 | void setSelected(UINT32 idx); |
102 | |
103 | /** |
104 | * Selects the next available non-separator entry. |
105 | * |
106 | * @param[in] startIdx Index of the menu element. |
107 | */ |
108 | void selectNext(UINT32 startIdx); |
109 | |
110 | /** |
111 | * Selects the previous available non-separator entry. |
112 | * |
113 | * @param[in] startIdx Index of the menu element. |
114 | */ |
115 | void selectPrevious(UINT32 startIdx); |
116 | |
117 | GUIDropDownData mDropDownData; |
118 | Vector<bool> mStates; |
119 | Vector<VisibleElement> mVisibleElements; |
120 | UINT32 mSelectedIdx; |
121 | UINT32 mRangeStart, mRangeEnd; |
122 | GUIDropDownMenu::DropDownSubMenu* mParent; |
123 | bool mKeyboardFocus; |
124 | bool mIsToggle; |
125 | }; |
126 | |
127 | /** @} */ |
128 | } |