MyGUI_MenuControl.h
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#ifndef MYGUI_MENU_CONTROL_H_
#define MYGUI_MENU_CONTROL_H_
#include "MyGUI_Prerequest.h"
#include "MyGUI_Types.h"
#include "MyGUI_MenuItemType.h"
#include "MyGUI_Widget.h"
#include "MyGUI_Any.h"
#include "MyGUI_EventPair.h"
#include "MyGUI_ControllerFadeAlpha.h"
#include "MyGUI_IItem.h"
#include "MyGUI_IItemContainer.h"
namespace MyGUI
{
using EventHandle_MenuCtrlPtrMenuItemPtr = delegates::MultiDelegate<MenuControl*, MenuItem*>;
using EventHandle_MenuCtrlPtr = delegates::MultiDelegate<MenuControl*>;
class MYGUI_EXPORT MenuControl : public Widget, public IItemContainer, public MemberObsolete<MenuControl>
{
MYGUI_RTTI_DERIVED(MenuControl)
public:
struct ItemInfo
{
ItemInfo(
MenuItem* _item,
const UString& _name,
MenuItemType _type,
MenuControl* _submenu,
std::string_view _id,
Any _data) :
item(_item),
name(_name),
type(_type),
submenu(_submenu),
id(_id),
data(_data)
{
}
MenuItem* item;
UString name;
MenuItemType type;
MenuControl* submenu;
std::string id;
Any data;
int width{0};
};
using VectorMenuItemInfo = std::vector<ItemInfo>;
public:
void setVisible(bool _visible) override;
void setVisibleSmooth(bool _visible);
//------------------------------------------------------------------------------//
// манипуляции айтемами
size_t getItemCount() const;
MenuItem* insertItemAt(
size_t _index,
const UString& _name,
MenuItemType _type = MenuItemType::Normal,
std::string_view _id = {},
Any _data = Any::Null);
MenuItem* insertItem(
MenuItem* _to,
const UString& _name,
MenuItemType _type = MenuItemType::Normal,
std::string_view _id = {},
Any _data = Any::Null);
MenuItem* addItem(
const UString& _name,
MenuItemType _type = MenuItemType::Normal,
std::string_view _id = {},
Any _data = Any::Null);
void removeItemAt(size_t _index);
void removeItem(MenuItem* _item);
void removeAllItems();
MenuItem* getItemAt(size_t _index) const;
size_t getItemIndex(const MenuItem* _item) const;
size_t findItemIndex(MenuItem* _item);
MenuItem* findItemWith(const UString& _name);
//------------------------------------------------------------------------------//
// манипуляции данными
void setItemDataAt(size_t _index, Any _data);
void setItemData(MenuItem* _item, Any _data);
void clearItemDataAt(size_t _index);
void clearItemData(MenuItem* _item);
template<typename ValueType>
ValueType* getItemDataAt(size_t _index, bool _throw = true)
{
MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuControl::getItemDataAt");
return mItemsInfo[_index].data.castType<ValueType>(_throw);
}
template<typename ValueType>
ValueType* getItemData(MenuItem* _item, bool _throw = true)
{
return getItemDataAt<ValueType>(getItemIndex(_item), _throw);
}
void setItemIdAt(size_t _index, std::string_view _id);
void setItemId(MenuItem* _item, std::string_view _id);
const std::string& getItemIdAt(size_t _index) const;
const std::string& getItemId(const MenuItem* _item) const;
MenuItem* getItemById(std::string_view _id) const;
MenuItem* findItemById(std::string_view _id, bool _recursive = false);
size_t getItemIndexById(std::string_view _id) const;
//------------------------------------------------------------------------------//
// манипуляции отображением
void setItemNameAt(size_t _index, const UString& _name);
void setItemName(MenuItem* _item, const UString& _name);
const UString& getItemNameAt(size_t _index) const;
const UString& getItemName(const MenuItem* _item) const;
size_t findItemIndexWith(const UString& _name);
void setItemChildVisibleAt(size_t _index, bool _visible);
void setItemChildVisible(MenuItem* _item, bool _visible);
//------------------------------------------------------------------------------//
// остальные манипуляции
template<typename Type>
Type* createItemChildTAt(size_t _index)
{
return static_cast<Type*>(createItemChildByType(_index, Type::getClassTypeName()));
}
template<typename Type>
Type* createItemChildT(MenuItem* _item)
{
return createItemChildTAt<Type>(getItemIndex(_item));
}
MenuControl* getItemChildAt(size_t _index) const;
MenuControl* getItemChild(const MenuItem* _item) const;
MenuControl* createItemChildAt(size_t _index);
MenuControl* createItemChild(MenuItem* _item);
void removeItemChildAt(size_t _index);
void removeItemChild(MenuItem* _item);
MenuItemType getItemTypeAt(size_t _index) const;
MenuItemType getItemType(const MenuItem* _item) const;
void setItemTypeAt(size_t _index, MenuItemType _type);
void setItemType(MenuItem* _item, MenuItemType _type);
void setPopupAccept(bool _value);
bool getPopupAccept() const;
MenuItem* getMenuItemParent() const;
void setVerticalAlignment(bool _value);
bool getVerticalAlignment() const;
/*events:*/
EventHandle_MenuCtrlPtrMenuItemPtr eventMenuCtrlAccept;
EventHandle_MenuCtrlPtr eventMenuCtrlClose;
/*internal:*/
void _notifyDeleteItem(MenuItem* _item);
void _notifyDeletePopup(MenuItem* _item);
void _notifyUpdateName(MenuItem* _item);
void _wrapItemChild(MenuItem* _item, MenuControl* _widget);
// IItemContainer impl
size_t _getItemCount() const override;
void _addItem(const MyGUI::UString& _name) override;
void _removeItemAt(size_t _index) override;
Widget* _getItemAt(size_t _index) const override;
void _setItemNameAt(size_t _index, const UString& _name) override;
const UString& _getItemNameAt(size_t _index) const override;
void _setItemSelected(IItem* _item) override;
void _updateItems(size_t _index);
void _updateSizeForEmpty();
protected:
void initialiseOverride() override;
void shutdownOverride() override;
void onKeyChangeRootFocus(bool _focus) override;
void onWidgetCreated(Widget* _widget) override;
void setPropertyOverride(std::string_view _key, std::string_view _value) override;
private:
void notifyRootKeyChangeFocus(Widget* _sender, bool _focus) const;
void notifyMouseButtonClick(Widget* _sender);
void notifyMouseSetFocus(Widget* _sender, Widget* _new);
const std::string& getSkinByType(MenuItemType _type) const;
std::string_view getIconIndexByType(MenuItemType _type) const;
void update();
MenuItemType getItemType(bool _submenu, bool _separator) const;
void notifyMenuCtrlAccept(MenuItem* _item);
Widget* createItemChildByType(size_t _index, std::string_view _type);
void _wrapItem(
MenuItem* _item,
size_t _index,
const UString& _name,
MenuItemType _type,
std::string_view _id,
Any _data);
ControllerFadeAlpha* createControllerFadeAlpha(float _alpha, float _coef, bool _enable);
void _setItemChildVisibleAt(size_t _index, bool _visible, bool _smooth);
protected:
bool mHideByAccept{true};
// нужно ли выбрасывать по нажатию
bool mMenuDropMode{false};
bool mIsMenuDrop{true};
bool mHideByLostKey{false};
bool mResizeToContent{true};
private:
VectorMenuItemInfo mItemsInfo;
std::string mItemNormalSkin;
std::string mItemPopupSkin;
std::string mItemSeparatorSkin;
std::string mSubMenuSkin;
std::string mSubMenuLayer;
// флаг, чтобы отсеч уведомления от айтемов, при общем шутдауне виджета
bool mShutdown{false};
bool mVerticalAlignment{true};
int mDistanceButton{0};
bool mPopupAccept{false};
MenuItem* mOwner{nullptr};
bool mAnimateSmooth{false};
bool mChangeChildSkin{false};
bool mInternalCreateChild{false};
};
} // namespace MyGUI
#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