| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #pragma once
- #include "BsEditorPrerequisites.h"
- #include "GUI/BsGUIElementContainer.h"
- namespace bs
- {
- /** @addtogroup GUI-Editor
- * @{
- */
- /**
- * A composite GUI object representing an editor field. Editor fields are a combination of a label and an input field.
- * Label is optional. This specific implementation displays a text input field.
- */
- class BS_ED_EXPORT GUITextField : public GUIElementContainer
- {
- struct PrivatelyConstruct {};
- public:
- /** Returns type name of the GUI element used for finding GUI element styles. */
- static const String& getGUITypeName();
- /** Returns style type name of the internal GUILabel element. */
- static const String& getLabelStyleType();
- /** Returns style type name of the internal GUIInputBox element. */
- static const String& getInputStyleType();
- /**
- * Creates a new GUI text editor field with a label.
- *
- * @param[in] multiline Should the input box accept multiple lines of input.
- * @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 GUITextField* create(bool multiline, const GUIContent& labelContent, UINT32 labelWidth, const GUIOptions& options,
- const String& style = StringUtil::BLANK);
- /**
- * Creates a new GUI text editor field with a label.
- *
- * @param[in] multiline Should the input box accept multiple lines of input.
- * @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 GUITextField* create(bool multiline, const GUIContent& labelContent, const GUIOptions& options,
- const String& style = StringUtil::BLANK);
- /**
- * Creates a new GUI text editor field with a label.
- *
- * @param[in] multiline Should the input box accept multiple lines of input.
- * @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 GUITextField* create(bool multiline, const HString& labelText, UINT32 labelWidth, const GUIOptions& options,
- const String& style = StringUtil::BLANK);
- /**
- * Creates a new GUI text editor field with a label.
- *
- * @param[in] multiline Should the input box accept multiple lines of input.
- * @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 GUITextField* create(bool multiline, const HString& labelText, const GUIOptions& options,
- const String& style = StringUtil::BLANK);
- /**
- * Creates a new GUI text editor field without a label.
- *
- * @param[in] multiline Should the input box accept multiple lines of input.
- * @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 GUITextField* create(bool multiline, const GUIOptions& options, const String& style = StringUtil::BLANK);
- /**
- * Creates a new GUI text editor field with a label.
- *
- * @param[in] multiline Should the input box accept multiple lines of input.
- * @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.
- */
- static GUITextField* create(bool multiline, const GUIContent& labelContent, UINT32 labelWidth,
- const String& style = StringUtil::BLANK);
- /**
- * Creates a new GUI text editor field with a label.
- *
- * @param[in] multiline Should the input box accept multiple lines of input.
- * @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.
- */
- static GUITextField* create(bool multiline, const GUIContent& labelContent,
- const String& style = StringUtil::BLANK);
- /**
- * Creates a new GUI text editor field with a label.
- *
- * @param[in] multiline Should the input box accept multiple lines of input.
- * @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.
- */
- static GUITextField* create(bool multiline, const HString& labelText, UINT32 labelWidth,
- const String& style = StringUtil::BLANK);
- /**
- * Creates a new GUI text editor field with a label.
- *
- * @param[in] multiline Should the input box accept multiple lines of input.
- * @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.
- */
- static GUITextField* create(bool multiline, const HString& labelText,
- const String& style = StringUtil::BLANK);
- /**
- * Creates a new GUI text editor field without a label.
- *
- * @param[in] multiline Should the input box accept multiple lines of input.
- * @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 GUITextField* create(bool multiline, const String& style = StringUtil::BLANK);
- GUITextField(const PrivatelyConstruct& dummy, bool multiline, const GUIContent& labelContent, UINT32 labelWidth,
- const String& style, const GUIDimensions& dimensions, bool withLabel);
- /** Returns the value currently input in the text field. */
- String getValue() const { return mValue; }
- /** Sets a new value in the text field. */
- void setValue(const String& value);
- /** Checks whether the element currently has keyboard focus. */
- bool hasInputFocus() const { return mHasInputFocus; }
- /** @copydoc GUIElement::setTint */
- void setTint(const Color& color) override;
-
- Event<void(const String&)> onValueChanged; /** Triggered when the value in the field changes. */
- Event<void()> onConfirm; /**< Triggered when the user hits the Enter key with the input box in focus. */
- /** @name Internal
- * @{
- */
- /**
- * Sets a new value in the input field, and also allows you to choose should the field trigger an onValueChanged
- * event.
- */
- void _setValue(const String& value, bool triggerEvent);
- /** @} */
- protected:
- static const UINT32 DEFAULT_LABEL_WIDTH;
- /** @copydoc GUIElement::styleUpdated */
- void styleUpdated() override;
- /** @copydoc GUIElement::_updateLayoutInternal */
- void _updateLayoutInternal(const GUILayoutData& data) override;
- /** @copydoc GUIElement::_getOptimalSize */
- Vector2I _getOptimalSize() const override;
- /** Triggered when the value in the internal input box changes. */
- void valueChanged(const String& newValue);
- /** Triggers when the input box receives or loses keyboard focus. */
- void focusChanged(bool focus);
- /** Triggered when the users confirms input in the input box. */
- void inputConfirmed();
- GUIInputBox* mInputBox;
- GUILayout* mLayout;
- GUILabel* mLabel;
- bool mHasInputFocus;
- String mValue;
- };
- /** @} */
- }
|