MyGUI: MyGUI_MenuControl.h Source File

MyGUI 3.4.3

MyGUI_MenuControl.h
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#ifndef MYGUI_MENU_CONTROL_H_
8#define MYGUI_MENU_CONTROL_H_
9
10#include "MyGUI_Prerequest.h"
11#include "MyGUI_Types.h"
12#include "MyGUI_MenuItemType.h"
13#include "MyGUI_Widget.h"
14#include "MyGUI_Any.h"
15#include "MyGUI_EventPair.h"
16#include "MyGUI_ControllerFadeAlpha.h"
17#include "MyGUI_IItem.h"
18#include "MyGUI_IItemContainer.h"
19
20namespace MyGUI
21{
22
23 using EventHandle_MenuCtrlPtrMenuItemPtr = delegates::MultiDelegate<MenuControl*, MenuItem*>;
24 using EventHandle_MenuCtrlPtr = delegates::MultiDelegate<MenuControl*>;
25
29 class MYGUI_EXPORT MenuControl : public Widget, public IItemContainer, public MemberObsolete<MenuControl>
30 {
31 MYGUI_RTTI_DERIVED(MenuControl)
32
33 public:
34 struct ItemInfo
35 {
36 ItemInfo(
37 MenuItem* _item,
38 const UString& _name,
39 MenuItemType _type,
40 MenuControl* _submenu,
41 std::string_view _id,
42 Any _data) :
43 item(_item),
44 name(_name),
45 type(_type),
46 submenu(_submenu),
47 id(_id),
48 data(_data)
49 {
50 }
51
53 MenuItem* item;
55 UString name;
57 MenuItemType type;
59 MenuControl* submenu;
61 std::string id;
63 Any data;
65 int width{0};
66 };
67
68 using VectorMenuItemInfo = std::vector<ItemInfo>;
69
70 public:
72 void setVisible(bool _visible) override;
73
75 void setVisibleSmooth(bool _visible);
76
77 //------------------------------------------------------------------------------//
78 // манипуляции айтемами
79
81 size_t getItemCount() const;
82
84 MenuItem* insertItemAt(
85 size_t _index,
86 const UString& _name,
87 MenuItemType _type = MenuItemType::Normal,
88 std::string_view _id = {},
89 Any _data = Any::Null);
91 MenuItem* insertItem(
92 MenuItem* _to,
93 const UString& _name,
94 MenuItemType _type = MenuItemType::Normal,
95 std::string_view _id = {},
96 Any _data = Any::Null);
97
99 MenuItem* addItem(
100 const UString& _name,
101 MenuItemType _type = MenuItemType::Normal,
102 std::string_view _id = {},
103 Any _data = Any::Null);
104
106 void removeItemAt(size_t _index);
108 void removeItem(MenuItem* _item);
109
111 void removeAllItems();
112
113
115 MenuItem* getItemAt(size_t _index) const;
116
118 size_t getItemIndex(const MenuItem* _item) const;
119
121 size_t findItemIndex(MenuItem* _item);
122
124 MenuItem* findItemWith(const UString& _name);
125
126 //------------------------------------------------------------------------------//
127 // манипуляции данными
128
130 void setItemDataAt(size_t _index, Any _data);
132 void setItemData(MenuItem* _item, Any _data);
133
135 void clearItemDataAt(size_t _index);
137 void clearItemData(MenuItem* _item);
138
140 template<typename ValueType>
141 ValueType* getItemDataAt(size_t _index, bool _throw = true)
142 {
143 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuControl::getItemDataAt");
144 return mItemsInfo[_index].data.castType<ValueType>(_throw);
145 }
146
147 template<typename ValueType>
148 ValueType* getItemData(MenuItem* _item, bool _throw = true)
149 {
150 return getItemDataAt<ValueType>(getItemIndex(_item), _throw);
151 }
152
154 void setItemIdAt(size_t _index, std::string_view _id);
156 void setItemId(MenuItem* _item, std::string_view _id);
157
159 const std::string& getItemIdAt(size_t _index) const;
161 const std::string& getItemId(const MenuItem* _item) const;
162
164 MenuItem* getItemById(std::string_view _id) const;
165
167 MenuItem* findItemById(std::string_view _id, bool _recursive = false);
168
170 size_t getItemIndexById(std::string_view _id) const;
171 //------------------------------------------------------------------------------//
172 // манипуляции отображением
173
175 void setItemNameAt(size_t _index, const UString& _name);
177 void setItemName(MenuItem* _item, const UString& _name);
178
180 const UString& getItemNameAt(size_t _index) const;
182 const UString& getItemName(const MenuItem* _item) const;
183
185 size_t findItemIndexWith(const UString& _name);
186
188 void setItemChildVisibleAt(size_t _index, bool _visible);
190 void setItemChildVisible(MenuItem* _item, bool _visible);
191
192 //------------------------------------------------------------------------------//
193 // остальные манипуляции
194
196 template<typename Type>
197 Type* createItemChildTAt(size_t _index)
198 {
199 return static_cast<Type*>(createItemChildByType(_index, Type::getClassTypeName()));
200 }
201
203 template<typename Type>
204 Type* createItemChildT(MenuItem* _item)
205 {
206 return createItemChildTAt<Type>(getItemIndex(_item));
207 }
208
210 MenuControl* getItemChildAt(size_t _index) const;
211
213 MenuControl* getItemChild(const MenuItem* _item) const;
214
216 MenuControl* createItemChildAt(size_t _index);
217
219 MenuControl* createItemChild(MenuItem* _item);
220
222 void removeItemChildAt(size_t _index);
223
225 void removeItemChild(MenuItem* _item);
226
227
229 MenuItemType getItemTypeAt(size_t _index) const;
230
232 MenuItemType getItemType(const MenuItem* _item) const;
233
235 void setItemTypeAt(size_t _index, MenuItemType _type);
237 void setItemType(MenuItem* _item, MenuItemType _type);
238
240 void setPopupAccept(bool _value);
242 bool getPopupAccept() const;
243
245 MenuItem* getMenuItemParent() const;
246
248 void setVerticalAlignment(bool _value);
250 bool getVerticalAlignment() const;
251
252
253 /*events:*/
259 EventHandle_MenuCtrlPtrMenuItemPtr eventMenuCtrlAccept;
260
265 EventHandle_MenuCtrlPtr eventMenuCtrlClose;
266
267
268 /*internal:*/
269 void _notifyDeleteItem(MenuItem* _item);
270 void _notifyDeletePopup(MenuItem* _item);
271 void _notifyUpdateName(MenuItem* _item);
272 void _wrapItemChild(MenuItem* _item, MenuControl* _widget);
273
274 // IItemContainer impl
275 size_t _getItemCount() const override;
276 void _addItem(const MyGUI::UString& _name) override;
277 void _removeItemAt(size_t _index) override;
278 Widget* _getItemAt(size_t _index) const override;
279 void _setItemNameAt(size_t _index, const UString& _name) override;
280 const UString& _getItemNameAt(size_t _index) const override;
281 void _setItemSelected(IItem* _item) override;
282
283 void _updateItems(size_t _index);
284 void _updateSizeForEmpty();
285
286 protected:
287 void initialiseOverride() override;
288 void shutdownOverride() override;
289
290 void onKeyChangeRootFocus(bool _focus) override;
291
292 void onWidgetCreated(Widget* _widget) override;
293
294 void setPropertyOverride(std::string_view _key, std::string_view _value) override;
295
296 private:
297 void notifyRootKeyChangeFocus(Widget* _sender, bool _focus) const;
298 void notifyMouseButtonClick(Widget* _sender);
299 void notifyMouseSetFocus(Widget* _sender, Widget* _new);
300
301 const std::string& getSkinByType(MenuItemType _type) const;
302 std::string_view getIconIndexByType(MenuItemType _type) const;
303
304 void update();
305
306 MenuItemType getItemType(bool _submenu, bool _separator) const;
307
308 void notifyMenuCtrlAccept(MenuItem* _item);
309
310 Widget* createItemChildByType(size_t _index, std::string_view _type);
311
312 void _wrapItem(
313 MenuItem* _item,
314 size_t _index,
315 const UString& _name,
316 MenuItemType _type,
317 std::string_view _id,
318 Any _data);
319
320 ControllerFadeAlpha* createControllerFadeAlpha(float _alpha, float _coef, bool _enable);
321
322 void _setItemChildVisibleAt(size_t _index, bool _visible, bool _smooth);
323
324 protected:
325 bool mHideByAccept{true};
326 // нужно ли выбрасывать по нажатию
327 bool mMenuDropMode{false};
328 bool mIsMenuDrop{true};
329 bool mHideByLostKey{false};
330 bool mResizeToContent{true};
331
332 private:
333 VectorMenuItemInfo mItemsInfo;
334
335 std::string mItemNormalSkin;
336 std::string mItemPopupSkin;
337 std::string mItemSeparatorSkin;
338
339 std::string mSubMenuSkin;
340 std::string mSubMenuLayer;
341
342 // флаг, чтобы отсеч уведомления от айтемов, при общем шутдауне виджета
343 bool mShutdown{false};
344
345 bool mVerticalAlignment{true};
346 int mDistanceButton{0};
347 bool mPopupAccept{false};
348 MenuItem* mOwner{nullptr};
349 bool mAnimateSmooth{false};
350
351 bool mChangeChildSkin{false};
352 bool mInternalCreateChild{false};
353 };
354
355} // namespace MyGUI
356
357#endif // MYGUI_MENU_CONTROL_H_
MyGUI_Any.h
MyGUI_ControllerFadeAlpha.h
MYGUI_ASSERT_RANGE
#define MYGUI_ASSERT_RANGE(index, size, owner)
Definition MyGUI_Diagnostic.h:44
MyGUI_EventPair.h
MyGUI_IItem.h
MyGUI_IItemContainer.h
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition MyGUI_Platform.h:77
MyGUI_Prerequest.h
MYGUI_RTTI_DERIVED
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition MyGUI_RTTI.h:69
MyGUI_Types.h
MyGUI_Widget.h
MyGUI::Any
Definition MyGUI_Any.h:56
MyGUI::Any::Null
static const Any Null
Definition MyGUI_Any.h:58
MyGUI::ControllerFadeAlpha
Definition MyGUI_ControllerFadeAlpha.h:19
MyGUI::IItemContainer
Definition MyGUI_IItemContainer.h:19
MyGUI::IItem
Definition MyGUI_IItem.h:18
MyGUI::MemberObsolete
Definition MyGUI_DeprecatedTypes.h:14
MyGUI::UString
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
Definition MyGUI_UString.h:144
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:40
MyGUI::delegates::MultiDelegate
Definition MyGUI_Delegate.h:190
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::EventHandle_MenuCtrlPtr
delegates::MultiDelegate< MenuControl * > EventHandle_MenuCtrlPtr
Definition MyGUI_MenuControl.h:24
MyGUI::EventHandle_MenuCtrlPtrMenuItemPtr
delegates::MultiDelegate< MenuControl *, MenuItem * > EventHandle_MenuCtrlPtrMenuItemPtr
Definition MyGUI_MenuControl.h:23