| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- #include "BsGUIFoldout.h"
- #include "BsGUILayout.h"
- #include "BsGUILabel.h"
- #include "BsGUIToggle.h"
- #include "BsGUITexture.h"
- #include "BsBuiltinResources.h"
- #include "BsGUIWidget.h"
- #include "BsGUIMouseEvent.h"
- using namespace std::placeholders;
- namespace BansheeEngine
- {
- GUIFoldout::GUIFoldout(const PrivatelyConstruct& dummy, const HString& label, const String& style,
- const GUIDimensions& dimensions)
- :GUIElementContainer(dimensions, style), mToggle(nullptr), mIsExpanded(false)
- {
- mLabel = GUILabel::create(label, getSubStyleName(getLabelStyleType()));
- mToggle = GUIToggle::create(HString(L""), getSubStyleName(getFoldoutButtonStyleType()));
- _registerChildElement(mLabel);
- _registerChildElement(mToggle);
- mToggle->onToggled.connect(std::bind(&GUIFoldout::toggleTriggered, this, _1));
- }
- GUIFoldout::~GUIFoldout()
- {
- }
- GUIFoldout* GUIFoldout::create(const HString& label, const GUIOptions& options,
- const String& style)
- {
- const String* curStyle = &style;
- if (*curStyle == StringUtil::BLANK)
- curStyle = &getGUITypeName();
- return bs_new<GUIFoldout>(PrivatelyConstruct(), label, *curStyle, GUIDimensions::create(options));
- }
- GUIFoldout* GUIFoldout::create(const HString& label, const String& style)
- {
- const String* curStyle = &style;
- if (*curStyle == StringUtil::BLANK)
- curStyle = &getGUITypeName();
- return bs_new<GUIFoldout>(PrivatelyConstruct(), label, *curStyle, GUIDimensions::create());
- }
- void GUIFoldout::setExpanded(bool expanded)
- {
- if (mIsExpanded != expanded)
- {
- mIsExpanded = expanded;
- if (mIsExpanded)
- mToggle->toggleOn();
- else
- mToggle->toggleOff();
- _markContentAsDirty();
- if (!onStateChanged.empty())
- onStateChanged(mIsExpanded);
- }
- }
- void GUIFoldout::setContent(const GUIContent& content)
- {
- mLabel->setContent(content);
- }
- void GUIFoldout::setTint(const Color& color)
- {
- mLabel->setTint(color);
- mToggle->setTint(color);
- }
- void GUIFoldout::toggleTriggered(bool value)
- {
- mIsExpanded = value;
- _markContentAsDirty();
- onStateChanged(value);
- }
- void GUIFoldout::_updateLayoutInternal(const GUILayoutData& data)
- {
- UINT32 toggleOffset = 0;
- {
- Vector2I optimalSize = mToggle->_getOptimalSize();
- INT32 yOffset = Math::roundToInt(((INT32)data.area.height - optimalSize.y) * 0.5f);
- GUILayoutData childData = data;
- childData.area.y += yOffset;
- childData.area.width = optimalSize.x;
- childData.area.height = optimalSize.y;
- mToggle->_setLayoutData(childData);
- toggleOffset = optimalSize.x;
- }
- {
- Vector2I optimalSize = mLabel->_getOptimalSize();
- INT32 yOffset = Math::roundToInt(((INT32)data.area.height - optimalSize.y) * 0.5f);
- GUILayoutData childData = data;
- childData.area.x += toggleOffset;
- childData.area.y += yOffset;
- childData.area.width = optimalSize.x;
- childData.area.height = optimalSize.y;
- mLabel->_setLayoutData(childData);
- }
- }
- Vector2I GUIFoldout::_getOptimalSize() const
- {
- Vector2I optimalsize = mToggle->_getOptimalSize();
- Vector2I labelOptimalSize = mLabel->_getOptimalSize();
- optimalsize.x += labelOptimalSize.x;
- optimalsize.y = std::max(optimalsize.y, labelOptimalSize.y);
- return optimalsize;
- }
- void GUIFoldout::styleUpdated()
- {
- mLabel->setStyle(getSubStyleName(getLabelStyleType()));
- mToggle->setStyle(getSubStyleName(getFoldoutButtonStyleType()));
- }
- const String& GUIFoldout::getGUITypeName()
- {
- static String typeName = "Foldout";
- return typeName;
- }
- const String& GUIFoldout::getFoldoutButtonStyleType()
- {
- static String FOLDOUT_BUTTON_STYLE = "FoldoutButton";
- return FOLDOUT_BUTTON_STYLE;
- }
- const String& GUIFoldout::getLabelStyleType()
- {
- static String FOLDOUT_LABEL_STYLE = "EditorFieldLabel";
- return FOLDOUT_LABEL_STYLE;
- }
- }
|