MyGUI_Widget.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_WIDGET_H_
#define MYGUI_WIDGET_H_
#include "MyGUI_Prerequest.h"
#include "MyGUI_Any.h"
#include "MyGUI_EventPair.h"
#include "MyGUI_ICroppedRectangle.h"
#include "MyGUI_WidgetUserData.h"
#include "MyGUI_WidgetInput.h"
#include "MyGUI_ResourceSkin.h"
#include "MyGUI_ResourceLayout.h"
#include "MyGUI_IObject.h"
#include "MyGUI_SkinItem.h"
#include "MyGUI_BackwardCompatibility.h"
namespace MyGUI
{
using EventHandle_WidgetStringString = EventPairConvertStringView<
delegates::MultiDelegate<Widget*, const std::string&, const std::string&>,
delegates::MultiDelegate<Widget*, std::string_view, std::string_view>>;
class MYGUI_EXPORT Widget :
public IObject,
public ICroppedRectangle,
public UserData,
public WidgetInput,
public delegates::IDelegateUnlink,
public SkinItem,
public MemberObsolete<Widget>
{
// для вызова закрытых деструкторов
friend class WidgetManager;
MYGUI_RTTI_DERIVED(Widget)
public:
Widget* createWidgetT(
std::string_view _type,
std::string_view _skin,
const IntCoord& _coord,
Align _align,
std::string_view _name = {});
Widget* createWidgetT(
std::string_view _type,
std::string_view _skin,
int _left,
int _top,
int _width,
int _height,
Align _align,
std::string_view _name = {});
Widget* createWidgetRealT(
std::string_view _type,
std::string_view _skin,
const FloatCoord& _coord,
Align _align,
std::string_view _name = {});
Widget* createWidgetRealT(
std::string_view _type,
std::string_view _skin,
float _left,
float _top,
float _width,
float _height,
Align _align,
std::string_view _name = {});
// templates for creating widgets by type
template<typename T>
T* createWidget(std::string_view _skin, const IntCoord& _coord, Align _align, std::string_view _name = {})
{
return static_cast<T*>(createWidgetT(T::getClassTypeName(), _skin, _coord, _align, _name));
}
template<typename T>
T* createWidget(
std::string_view _skin,
int _left,
int _top,
int _width,
int _height,
Align _align,
std::string_view _name = {})
{
return static_cast<T*>(
createWidgetT(T::getClassTypeName(), _skin, IntCoord(_left, _top, _width, _height), _align, _name));
}
template<typename T>
T* createWidgetReal(std::string_view _skin, const FloatCoord& _coord, Align _align, std::string_view _name = {})
{
return static_cast<T*>(createWidgetRealT(T::getClassTypeName(), _skin, _coord, _align, _name));
}
template<typename T>
T* createWidgetReal(
std::string_view _skin,
float _left,
float _top,
float _width,
float _height,
Align _align,
std::string_view _name = {})
{
return static_cast<T*>(
createWidgetRealT(T::getClassTypeName(), _skin, _left, _top, _width, _height, _align, _name));
}
Widget* createWidgetT(
WidgetStyle _style,
std::string_view _type,
std::string_view _skin,
const IntCoord& _coord,
Align _align,
std::string_view _layer = {},
std::string_view _name = {});
template<typename T>
T* createWidget(
WidgetStyle _style,
std::string_view _skin,
const IntCoord& _coord,
Align _align,
std::string_view _layer = {},
std::string_view _name = {})
{
return static_cast<T*>(createWidgetT(_style, T::getClassTypeName(), _skin, _coord, _align, _layer, _name));
}
void setPosition(const IntPoint& _point) override;
void setSize(const IntSize& _size) override;
void setCoord(const IntCoord& _coord) override;
void setPosition(int _left, int _top);
void setSize(int _width, int _height);
void setCoord(int _left, int _top, int _width, int _height);
void setRealPosition(const FloatPoint& _point);
void setRealSize(const FloatSize& _size);
void setRealCoord(const FloatCoord& _coord);
void setRealPosition(float _left, float _top);
void setRealSize(float _width, float _height);
void setRealCoord(float _left, float _top, float _width, float _height);
const std::string& getName() const;
virtual void setVisible(bool _value);
bool getVisible() const;
void setDepth(int _value);
int getDepth() const;
bool getInheritedVisible() const;
virtual void setAlign(Align _value);
Align getAlign() const;
void setAlpha(float _alpha);
float getAlpha() const;
void setInheritsAlpha(bool _inherits);
bool getInheritsAlpha() const;
void setColour(const Colour& _value);
// являемся ли мы рутовым виджетом
bool isRootWidget() const;
Widget* getParent() const;
IntSize getParentSize() const;
EnumeratorWidgetPtr getEnumerator() const;
size_t getChildCount() const;
Widget* getChildAt(size_t _index) const;
Widget* findWidget(std::string_view _name);
void findWidgets(std::string_view _name, VectorWidgetPtr& _result);
virtual void setEnabled(bool _value);
void setEnabledSilent(bool _value);
bool getEnabled() const;
bool getInheritedEnabled() const;
IntCoord getClientCoord() const;
Widget* getClientWidget();
const Widget* getClientWidget() const;
void detachFromWidget(std::string_view _layer = {});
void attachToWidget(Widget* _parent, WidgetStyle _style = WidgetStyle::Child, std::string_view _layer = {});
void changeWidgetSkin(std::string_view _skinName);
void setWidgetStyle(WidgetStyle _style, std::string_view _layer = {});
WidgetStyle getWidgetStyle() const;
void setProperty(std::string_view _key, std::string_view _value);
EventHandle_WidgetStringString eventChangeProperty;
EventHandle_WidgetVoid eventChangeCoord;
EventHandle_WidgetVoid eventWidgetDestroyed;
/*internal:*/
// метод для запроса номера айтема и контейнера
virtual size_t _getItemIndex(Widget* _item) const;
// дает приоритет виджету при пиккинге
void _forcePick(Widget* _widget);
void _initialise(
WidgetStyle _style,
const IntCoord& _coord,
std::string_view _skinName,
Widget* _parent,
ICroppedRectangle* _croppedParent,
std::string_view _name);
void _shutdown();
// удяляет неудачника
void _destroyChildWidget(Widget* _widget);
void _setContainer(Widget* _value);
Widget* _getContainer() const;
void _setAlign(const IntSize& _oldsize, const IntSize& _newSize);
bool _checkPoint(int _left, int _top) const;
Widget* _createSkinWidget(
WidgetStyle _style,
std::string_view _type,
std::string_view _skin,
const IntCoord& _coord,
Align _align,
std::string_view _layer = {},
std::string_view _name = {});
// сброс всех данных контейнера, тултипы и все остальное
virtual void _resetContainer(bool _update);
bool _setWidgetState(std::string_view _state);
// перерисовывает детей
void _updateChilds();
protected:
// все создание только через фабрику
~Widget() override = default;
virtual void shutdownOverride();
virtual void initialiseOverride();
void _updateView(); // обновления себя и детей
// создает виджет
Widget* baseCreateWidget(
WidgetStyle _style,
std::string_view _type,
std::string_view _skin,
const IntCoord& _coord,
Align _align,
std::string_view _layer,
std::string_view _name,
bool _template);
// удаляет всех детей
void _destroyAllChildWidget();
// запрашиваем у конейтера айтем по позиции мыши
virtual size_t _getContainerIndex(const IntPoint& _point) const;
virtual void baseUpdateEnable();
// наследуемся он LayerInfo
ILayerItem* getLayerItemByPoint(int _left, int _top) const override;
const IntCoord& getLayerItemCoord() const override;
template<typename T>
void assignWidget(T*& _widget, std::string_view _name)
{
_widget = nullptr;
for (const auto& iter : mWidgetChildSkin)
{
Widget* find = iter->findWidget(_name);
if (nullptr != find)
{
_widget = find->castType<T>(false);
break;
}
}
}
VectorWidgetPtr getSkinWidgetsByName(std::string_view _name) const;
virtual void onWidgetCreated(Widget* _widget);
virtual void onWidgetDestroy(Widget* _widget);
void setWidgetClient(Widget* _widget);
Widget* _getClientWidget();
const Widget* _getClientWidget() const;
virtual void setPropertyOverride(std::string_view _key, std::string_view _value);
private:
const WidgetInfo* initialiseWidgetSkinBase(ResourceSkin* _skinInfo, ResourceLayout* _templateInfo);
void shutdownWidgetSkinBase();
void _updateAlpha();
void _updateAbsolutePoint();
// для внутреннего использования
void _updateVisible();
void _updateEnabled();
float _getRealAlpha() const;
void _createChildSkinWidget(ResourceSkin* _info);
void _destroyChildSkinWidget();
void _parseSkinProperties(ResourceSkin* _info);
void _checkInheristProperties();
void _linkChildWidget(Widget* _widget);
void _unlinkChildWidget(Widget* _widget);
void setSkinProperty(ResourceSkin* _info);
void resizeLayerItemView(const IntSize& _oldView, const IntSize& _newView) override;
void addWidget(Widget* _widget);
private:
// клиентская зона окна
// если виджет имеет пользовательские окна не в себе
// то обязательно проинициализировать Client
Widget* mWidgetClient{nullptr};
// вектор всех детей виджетов
VectorWidgetPtr mWidgetChild;
// вектор детей скина
VectorWidgetPtr mWidgetChildSkin;
// availability for mouse/keyboard
bool mEnabled{true};
bool mInheritedEnabled{true};
// visibility on screen and for mouse
bool mVisible{true};
bool mInheritedVisible{true};
// transparency and transparency inheritance
float mAlpha{ALPHA_MAX};
float mRealAlpha{ALPHA_MAX};
bool mInheritsAlpha{true};
std::string mName;
// parent in widgets hierarchy
Widget* mParent{nullptr};
WidgetStyle mWidgetStyle{WidgetStyle::Child};
Widget* mContainer{nullptr};
Align mAlign{Align::Default};
int mDepth{0};
};
} // namespace MyGUI
#endif // MYGUI_WIDGET_H_
MyGUI_Any.h
MyGUI_BackwardCompatibility.h
MyGUI_EventPair.h
MyGUI_ICroppedRectangle.h
MyGUI_IObject.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_ResourceLayout.h
MyGUI_ResourceSkin.h
MyGUI_SkinItem.h
MyGUI_WidgetInput.h
MyGUI_WidgetUserData.h
MyGUI::EventPairConvertStringView
Definition MyGUI_EventPair.h:213
MyGUI::ICroppedRectangle
Definition MyGUI_ICroppedRectangle.h:17
MyGUI::ILayerItem
Definition MyGUI_ILayerItem.h:20
MyGUI::IObject
Definition MyGUI_IObject.h:17
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition MyGUI_IObject.h:18
MyGUI::MemberObsolete
Definition MyGUI_DeprecatedTypes.h:14
MyGUI::ResourceLayout
Definition MyGUI_ResourceLayout.h:19
MyGUI::ResourceSkin
Definition MyGUI_ResourceSkin.h:22
MyGUI::SkinItem
Definition MyGUI_SkinItem.h:20
MyGUI::UserData
Definition MyGUI_WidgetUserData.h:18
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:40
MyGUI::Widget::_destroyAllChildWidget
void _destroyAllChildWidget()
Definition MyGUI_Widget.cpp:442
MyGUI::Widget::getLayerItemByPoint
ILayerItem * getLayerItemByPoint(int _left, int _top) const override
Definition MyGUI_Widget.cpp:496
MyGUI::Widget::_checkPoint
bool _checkPoint(int _left, int _top) const
Definition MyGUI_Widget.cpp:1098
MyGUI::Widget::_destroyChildWidget
void _destroyChildWidget(Widget *_widget)
Definition MyGUI_Widget.cpp:411
MyGUI::Widget::eventChangeProperty
EventHandle_WidgetStringString eventChangeProperty
Definition MyGUI_Widget.h:324
MyGUI::Widget::createWidgetReal
T * createWidgetReal(std::string_view _skin, const FloatCoord &_coord, Align _align, std::string_view _name={})
Definition MyGUI_Widget.h:116
MyGUI::Widget::initialiseOverride
virtual void initialiseOverride()
Definition MyGUI_Widget.cpp:1122
MyGUI::Widget::createWidget
T * createWidget(std::string_view _skin, int _left, int _top, int _width, int _height, Align _align, std::string_view _name={})
Definition MyGUI_Widget.h:101
MyGUI::Widget::_shutdown
void _shutdown()
Definition MyGUI_Widget.cpp:112
MyGUI::Widget::_setAlign
void _setAlign(const IntSize &_oldsize, const IntSize &_newSize)
Definition MyGUI_Widget.cpp:612
MyGUI::Widget::baseUpdateEnable
virtual void baseUpdateEnable()
Definition MyGUI_Widget.cpp:1014
MyGUI::Widget::_initialise
void _initialise(WidgetStyle _style, const IntCoord &_coord, std::string_view _skinName, Widget *_parent, ICroppedRectangle *_croppedParent, std::string_view _name)
Definition MyGUI_Widget.cpp:31
MyGUI::Widget::WidgetManager
friend class WidgetManager
Definition MyGUI_Widget.h:42
MyGUI::Widget::getLayerItemCoord
const IntCoord & getLayerItemCoord() const override
Definition MyGUI_Widget.cpp:1402
MyGUI::Widget::createWidgetT
Widget * createWidgetT(std::string_view _type, std::string_view _skin, const IntCoord &_coord, Align _align, std::string_view _name={})
Definition MyGUI_Widget.cpp:944
MyGUI::Widget::findWidget
Widget * findWidget(std::string_view _name)
Definition MyGUI_Widget.cpp:575
MyGUI::Widget::eventChangeCoord
EventHandle_WidgetVoid eventChangeCoord
Definition MyGUI_Widget.h:330
MyGUI::Widget::~Widget
~Widget() override=default
MyGUI::Widget::assignWidget
void assignWidget(T *&_widget, std::string_view _name)
Definition MyGUI_Widget.h:413
MyGUI::Widget::createWidget
T * createWidget(WidgetStyle _style, std::string_view _skin, const IntCoord &_coord, Align _align, std::string_view _layer={}, std::string_view _name={})
Definition MyGUI_Widget.h:156
MyGUI::Widget::_getContainer
Widget * _getContainer() const
Definition MyGUI_Widget.cpp:1392
MyGUI::Widget::_createSkinWidget
Widget * _createSkinWidget(WidgetStyle _style, std::string_view _type, std::string_view _skin, const IntCoord &_coord, Align _align, std::string_view _layer={}, std::string_view _name={})
Definition MyGUI_Widget.cpp:1206
MyGUI::Widget::createWidget
T * createWidget(std::string_view _skin, const IntCoord &_coord, Align _align, std::string_view _name={})
Definition MyGUI_Widget.h:94
MyGUI::Widget::_setContainer
void _setContainer(Widget *_value)
Definition MyGUI_Widget.cpp:1387
MyGUI::Widget::_getContainerIndex
virtual size_t _getContainerIndex(const IntPoint &_point) const
Definition MyGUI_Widget.cpp:1397
MyGUI::Widget::_updateView
void _updateView()
Definition MyGUI_Widget.cpp:359
MyGUI::Widget::_forcePick
void _forcePick(Widget *_widget)
Definition MyGUI_Widget.cpp:547
MyGUI::Widget::eventWidgetDestroyed
EventHandle_WidgetVoid eventWidgetDestroyed
Definition MyGUI_Widget.h:336
MyGUI::Widget::_getItemIndex
virtual size_t _getItemIndex(Widget *_item) const
Definition MyGUI_Widget.cpp:1382
MyGUI::Widget::shutdownOverride
virtual void shutdownOverride()
Definition MyGUI_Widget.cpp:1118
MyGUI::Widget::baseCreateWidget
Widget * baseCreateWidget(WidgetStyle _style, std::string_view _type, std::string_view _skin, const IntCoord &_coord, Align _align, std::string_view _layer, std::string_view _name, bool _template)
Definition MyGUI_Widget.cpp:293
MyGUI::Widget::createWidgetReal
T * createWidgetReal(std::string_view _skin, float _left, float _top, float _width, float _height, Align _align, std::string_view _name={})
Definition MyGUI_Widget.h:123
MyGUI::WidgetInput
Definition MyGUI_WidgetInput.h:60
MyGUI::delegates::IDelegateUnlink
Definition MyGUI_Delegate.h:24
MyGUI::delegates::MultiDelegate
Definition MyGUI_Delegate.h:190
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::ALPHA_MAX
constexpr float ALPHA_MAX
Definition MyGUI_Macros.h:20
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
MyGUI::FloatCoord
types::TCoord< float > FloatCoord
Definition MyGUI_Types.h:37
MyGUI::EnumeratorWidgetPtr
Enumerator< VectorWidgetPtr > EnumeratorWidgetPtr
Definition MyGUI_WidgetDefines.h:22
MyGUI::EventHandle_WidgetVoid
delegates::MultiDelegate< Widget * > EventHandle_WidgetVoid
Definition MyGUI_WidgetInput.h:48
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:36
MyGUI::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
MyGUI::VectorWidgetPtr
std::vector< Widget * > VectorWidgetPtr
Definition MyGUI_WidgetDefines.h:20
MyGUI::EventHandle_WidgetStringString
EventPairConvertStringView< delegates::MultiDelegate< Widget *, const std::string &, const std::string & >, delegates::MultiDelegate< Widget *, std::string_view, std::string_view > > EventHandle_WidgetStringString
Definition MyGUI_Widget.h:25
MyGUI::Align
Definition MyGUI_Align.h:20
MyGUI::WidgetInfo
Definition MyGUI_LayoutData.h:23
MyGUI::WidgetStyle
Definition MyGUI_WidgetStyle.h:19