| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #pragma once
- #include "BsEditorPrerequisites.h"
- #include "GUI/BsGUIElementContainer.h"
- #include "GUI/BsGUIContent.h"
- namespace bs
- {
- /** @addtogroup Implementation
- * @{
- */
- /** Base class for all editor GUI fields. All fields are a combination of an optional label and an input field. */
- class BS_ED_EXPORT GUIFieldBase : public GUIElementContainer
- {
- protected:
- struct PrivatelyConstruct {};
- public:
- /** Returns the style type name for the internal label element. */
- static const String& getLabelStyleType()
- {
- static String LABEL_STYLE_TYPE = "EditorFieldLabel";
- return LABEL_STYLE_TYPE;
- }
- GUIFieldBase(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
- const String& labelStyle, const GUIDimensions& dimensions, bool withLabel);
- /** @name Internal
- * @{
- */
- /** @copydoc GUIElementContainer::_updateLayoutInternal */
- void _updateLayoutInternal(const GUILayoutData& data) override;
- /** @copydoc GUIElementContainer::_getOptimalSize */
- Vector2I _getOptimalSize() const override;
- /** @} */
- protected:
- virtual ~GUIFieldBase() = default;
- /** @copydoc GUIElementContainer::styleUpdated */
- void styleUpdated() override;
- static const UINT32 DEFAULT_LABEL_WIDTH;
- GUILayout* mLayout;
- GUILabel* mLabel;
- };
- /** Templated GUI field class that provides common methods needed for constructing an editor field. */
- template <class T>
- class TGUIField : public GUIFieldBase
- {
- public:
- /**
- * Creates a new GUI editor field with a label.
- *
- * @param[in] labelContent Content to display in the editor field label.
- * @param[in] labelWidth Width of the label in pixels.
- * @param[in] options Options that allow you to control how is the element positioned and sized.
- * This will override any similar options set by style.
- * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the
- * GUIWidget the element is used on. If not specified default style is used.
- */
- static T* create(const GUIContent& labelContent, UINT32 labelWidth, const GUIOptions& options,
- const String& style = StringUtil::BLANK)
- {
- const String* curStyle = &style;
- if (*curStyle == StringUtil::BLANK)
- curStyle = &T::getGUITypeName();
- return bs_new<T>(PrivatelyConstruct(), labelContent, labelWidth, *curStyle,
- GUIDimensions::create(options), true);
- }
- /**
- * Creates a new GUI editor field with a label.
- *
- * @param[in] labelContent Content to display in the editor field label.
- * @param[in] options Options that allow you to control how is the element positioned and sized. This will
- * override any similar options set by style.
- * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the
- * GUIWidget the element is used on. If not specified default style is used.
- */
- static T* create(const GUIContent& labelContent, const GUIOptions& options,
- const String& style = StringUtil::BLANK)
- {
- const String* curStyle = &style;
- if (*curStyle == StringUtil::BLANK)
- curStyle = &T::getGUITypeName();
- return bs_new<T>(PrivatelyConstruct(), labelContent, DEFAULT_LABEL_WIDTH, *curStyle,
- GUIDimensions::create(options), true);
- }
- /**
- * Creates a new GUI editor field with a label.
- *
- * @param[in] labelText String to display in the editor field label.
- * @param[in] labelWidth Width of the label in pixels.
- * @param[in] options Options that allow you to control how is the element positioned and sized.
- * This will override any similar options set by style.
- * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the
- * GUIWidget the element is used on. If not specified default style is used.
- */
- static T* create(const HString& labelText, UINT32 labelWidth, const GUIOptions& options,
- const String& style = StringUtil::BLANK)
- {
- const String* curStyle = &style;
- if (*curStyle == StringUtil::BLANK)
- curStyle = &T::getGUITypeName();
- return bs_new<T>(PrivatelyConstruct(), GUIContent(labelText), labelWidth, *curStyle,
- GUIDimensions::create(options), true);
- }
- /**
- * Creates a new GUI editor field with a label.
- *
- * @param[in] labelText String to display in the editor field label.
- * @param[in] options Options that allow you to control how is the element positioned and sized.
- * This will override any similar options set by style.
- * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the
- * GUIWidget the element is used on. If not specified default style is used.
- */
- static T* create(const HString& labelText, const GUIOptions& options,
- const String& style = StringUtil::BLANK)
- {
- const String* curStyle = &style;
- if (*curStyle == StringUtil::BLANK)
- curStyle = &T::getGUITypeName();
- return bs_new<T>(PrivatelyConstruct(), GUIContent(labelText), DEFAULT_LABEL_WIDTH, *curStyle,
- GUIDimensions::create(options), true);
- }
- /**
- * Creates a new GUI editor field without a label.
- *
- * @param[in] options Options that allow you to control how is the element positioned and sized.
- * This will override any similar options set by style.
- * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the
- * GUIWidget the element is used on. If not specified default style is used.
- */
- static T* create(const GUIOptions& options, const String& style = StringUtil::BLANK)
- {
- const String* curStyle = &style;
- if (*curStyle == StringUtil::BLANK)
- curStyle = &T::getGUITypeName();
- return bs_new<T>(PrivatelyConstruct(), GUIContent(), 0, *curStyle,
- GUIDimensions::create(options), false);
- }
- /**
- * Creates a new GUI editor field with a label.
- *
- * @param[in] labelContent Content to display in the editor field label.
- * @param[in] labelWidth Width of the label in pixels.
- * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the
- * GUIWidget the element is used on. If not specified default style is used.
- */
- BS_SCRIPT_EXPORT(ec:T)
- static T* create(const GUIContent& labelContent, UINT32 labelWidth,
- const String& style = StringUtil::BLANK)
- {
- const String* curStyle = &style;
- if (*curStyle == StringUtil::BLANK)
- curStyle = &T::getGUITypeName();
- return bs_new<T>(PrivatelyConstruct(), labelContent, labelWidth, *curStyle, GUIDimensions::create(), true);
- }
- /**
- * Creates a new GUI editor field with a label.
- *
- * @param[in] labelContent Content to display in the editor field label.
- * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the
- * GUIWidget the element is used on. If not specified default style is used.
- */
- BS_SCRIPT_EXPORT(ec:T)
- static T* create(const GUIContent& labelContent,
- const String& style = StringUtil::BLANK)
- {
- const String* curStyle = &style;
- if (*curStyle == StringUtil::BLANK)
- curStyle = &T::getGUITypeName();
- return bs_new<T>(PrivatelyConstruct(), labelContent, DEFAULT_LABEL_WIDTH, *curStyle,
- GUIDimensions::create(), true);
- }
- /**
- * Creates a new GUI editor field with a label.
- *
- * @param[in] labelText String to display in the editor field label.
- * @param[in] labelWidth Width of the label in pixels.
- * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the
- * GUIWidget the element is used on. If not specified default style is used.
- */
- BS_SCRIPT_EXPORT(ec:T)
- static T* create(const HString& labelText, UINT32 labelWidth,
- const String& style = StringUtil::BLANK)
- {
- const String* curStyle = &style;
- if (*curStyle == StringUtil::BLANK)
- curStyle = &T::getGUITypeName();
- return bs_new<T>(PrivatelyConstruct(), GUIContent(labelText), labelWidth, *curStyle,
- GUIDimensions::create(), true);
- }
- /**
- * Creates a new GUI editor field with a label.
- *
- * @param[in] labelText String to display in the editor field label.
- * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the
- * GUIWidget the element is used on. If not specified default style is used.
- */
- BS_SCRIPT_EXPORT(ec:T)
- static T* create(const HString& labelText, const String& style = StringUtil::BLANK)
- {
- const String* curStyle = &style;
- if (*curStyle == StringUtil::BLANK)
- curStyle = &T::getGUITypeName();
- return bs_new<T>(PrivatelyConstruct(), GUIContent(labelText), DEFAULT_LABEL_WIDTH, *curStyle,
- GUIDimensions::create(), true);
- }
- /**
- * Creates a new GUI editor field without a label.
- *
- * @param[in] style Optional style to use for the element. Style will be retrieved from GUISkin of the
- * GUIWidget the element is used on. If not specified default style is used.
- */
- BS_SCRIPT_EXPORT(ec:T)
- static T* create(const String& style = StringUtil::BLANK)
- {
- const String* curStyle = &style;
- if (*curStyle == StringUtil::BLANK)
- curStyle = &T::getGUITypeName();
- return bs_new<T>(PrivatelyConstruct(), GUIContent(), 0, *curStyle,
- GUIDimensions::create(), false);
- }
- TGUIField(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
- const String& style, const GUIDimensions& dimensions, bool withLabel)
- :GUIFieldBase(dummy, labelContent, labelWidth, style, dimensions, withLabel)
- { }
- };
- /** @} */
- }
|