BsGUIFieldBase.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsEditorPrerequisites.h"
  5. #include "BsGUIElementContainer.h"
  6. #include "BsGUIContent.h"
  7. namespace BansheeEngine
  8. {
  9. /** @addtogroup Implementation
  10. * @{
  11. */
  12. /** Base class for all editor GUI fields. All fields are a combination of an optional label and an input field. */
  13. class BS_ED_EXPORT GUIFieldBase : public GUIElementContainer
  14. {
  15. protected:
  16. struct PrivatelyConstruct {};
  17. public:
  18. /** Returns the style type name for the internal label element. */
  19. static const String& getLabelStyleType()
  20. {
  21. static String LABEL_STYLE_TYPE = "EditorFieldLabel";
  22. return LABEL_STYLE_TYPE;
  23. }
  24. GUIFieldBase(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  25. const String& labelStyle, const GUIDimensions& dimensions, bool withLabel);
  26. /** @cond INTERNAL */
  27. /** @copydoc GUIElementContainer::_updateLayoutInternal */
  28. void _updateLayoutInternal(const GUILayoutData& data) override;
  29. /** @copydoc GUIElementContainer::_getOptimalSize */
  30. virtual Vector2I _getOptimalSize() const override;
  31. /** @endcond */
  32. protected:
  33. virtual ~GUIFieldBase() { }
  34. /** @copydoc GUIElementContainer::styleUpdated */
  35. virtual void styleUpdated() override;
  36. static const UINT32 DEFAULT_LABEL_WIDTH;
  37. GUILayout* mLayout;
  38. GUILabel* mLabel;
  39. };
  40. /** Templated GUI field class that provides common methods needed for constructing an editor field. */
  41. template <class T>
  42. class TGUIField : public GUIFieldBase
  43. {
  44. public:
  45. /**
  46. * Creates a new GUI editor field with a label.
  47. *
  48. * @param[in] labelContent Content to display in the editor field label.
  49. * @param[in] labelWidth Width of the label in pixels.
  50. * @param[in] options Options that allow you to control how is the element positioned and sized.
  51. * This will override any similar options set by style.
  52. * @param[in] styleName Optional style to use for the element. Style will be retrieved from GUISkin of the
  53. * GUIWidget the element is used on. If not specified default style is used.
  54. */
  55. static T* create(const GUIContent& labelContent, UINT32 labelWidth, const GUIOptions& options,
  56. const String& style = StringUtil::BLANK)
  57. {
  58. const String* curStyle = &style;
  59. if (*curStyle == StringUtil::BLANK)
  60. curStyle = &T::getGUITypeName();
  61. return bs_new<T>(PrivatelyConstruct(), labelContent, labelWidth, *curStyle,
  62. GUIDimensions::create(options), true);
  63. }
  64. /**
  65. * Creates a new GUI editor field with a label.
  66. *
  67. * @param[in] labelContent Content to display in the editor field label.
  68. * @param[in] options Options that allow you to control how is the element positioned and sized. This will
  69. * override any similar options set by style.
  70. * @param[in] styleName Optional style to use for the element. Style will be retrieved from GUISkin of the
  71. * GUIWidget the element is used on. If not specified default style is used.
  72. */
  73. static T* create(const GUIContent& labelContent, const GUIOptions& options,
  74. const String& style = StringUtil::BLANK)
  75. {
  76. const String* curStyle = &style;
  77. if (*curStyle == StringUtil::BLANK)
  78. curStyle = &T::getGUITypeName();
  79. return bs_new<T>(PrivatelyConstruct(), labelContent, DEFAULT_LABEL_WIDTH, *curStyle,
  80. GUIDimensions::create(options), true);
  81. }
  82. /**
  83. * Creates a new GUI editor field with a label.
  84. *
  85. * @param[in] labelText String to display in the editor field label.
  86. * @param[in] labelWidth Width of the label in pixels.
  87. * @param[in] options Options that allow you to control how is the element positioned and sized.
  88. * This will override any similar options set by style.
  89. * @param[in] styleName Optional style to use for the element. Style will be retrieved from GUISkin of the
  90. * GUIWidget the element is used on. If not specified default style is used.
  91. */
  92. static T* create(const HString& labelText, UINT32 labelWidth, const GUIOptions& options,
  93. const String& style = StringUtil::BLANK)
  94. {
  95. const String* curStyle = &style;
  96. if (*curStyle == StringUtil::BLANK)
  97. curStyle = &T::getGUITypeName();
  98. return bs_new<T>(PrivatelyConstruct(), GUIContent(labelText), labelWidth, *curStyle,
  99. GUIDimensions::create(options), true);
  100. }
  101. /**
  102. * Creates a new GUI editor field with a label.
  103. *
  104. * @param[in] labelText String to display in the editor field label.
  105. * @param[in] options Options that allow you to control how is the element positioned and sized.
  106. * This will override any similar options set by style.
  107. * @param[in] styleName Optional style to use for the element. Style will be retrieved from GUISkin of the
  108. * GUIWidget the element is used on. If not specified default style is used.
  109. */
  110. static T* create(const HString& labelText, const GUIOptions& options,
  111. const String& style = StringUtil::BLANK)
  112. {
  113. const String* curStyle = &style;
  114. if (*curStyle == StringUtil::BLANK)
  115. curStyle = &T::getGUITypeName();
  116. return bs_new<T>(PrivatelyConstruct(), GUIContent(labelText), DEFAULT_LABEL_WIDTH, *curStyle,
  117. GUIDimensions::create(options), true);
  118. }
  119. /**
  120. * Creates a new GUI editor field without a label.
  121. *
  122. * @param[in] options Options that allow you to control how is the element positioned and sized.
  123. * This will override any similar options set by style.
  124. * @param[in] styleName Optional style to use for the element. Style will be retrieved from GUISkin of the
  125. * GUIWidget the element is used on. If not specified default style is used.
  126. */
  127. static T* create(const GUIOptions& options, const String& style = StringUtil::BLANK)
  128. {
  129. const String* curStyle = &style;
  130. if (*curStyle == StringUtil::BLANK)
  131. curStyle = &T::getGUITypeName();
  132. return bs_new<T>(PrivatelyConstruct(), GUIContent(), 0, *curStyle,
  133. GUIDimensions::create(options), false);
  134. }
  135. /**
  136. * Creates a new GUI editor field with a label.
  137. *
  138. * @param[in] labelContent Content to display in the editor field label.
  139. * @param[in] labelWidth Width of the label in pixels.
  140. * @param[in] styleName Optional style to use for the element. Style will be retrieved from GUISkin of the
  141. * GUIWidget the element is used on. If not specified default style is used.
  142. */
  143. static T* create(const GUIContent& labelContent, UINT32 labelWidth,
  144. const String& style = StringUtil::BLANK)
  145. {
  146. const String* curStyle = &style;
  147. if (*curStyle == StringUtil::BLANK)
  148. curStyle = &T::getGUITypeName();
  149. return bs_new<T>(PrivatelyConstruct(), labelContent, labelWidth, *curStyle, GUIDimensions::create(), true);
  150. }
  151. /**
  152. * Creates a new GUI editor field with a label.
  153. *
  154. * @param[in] labelContent Content to display in the editor field label.
  155. * @param[in] styleName Optional style to use for the element. Style will be retrieved from GUISkin of the
  156. * GUIWidget the element is used on. If not specified default style is used.
  157. */
  158. static T* create(const GUIContent& labelContent,
  159. const String& style = StringUtil::BLANK)
  160. {
  161. const String* curStyle = &style;
  162. if (*curStyle == StringUtil::BLANK)
  163. curStyle = &T::getGUITypeName();
  164. return bs_new<T>(PrivatelyConstruct(), labelContent, DEFAULT_LABEL_WIDTH, *curStyle,
  165. GUIDimensions::create(), true);
  166. }
  167. /**
  168. * Creates a new GUI editor field with a label.
  169. *
  170. * @param[in] labelText String to display in the editor field label.
  171. * @param[in] labelWidth Width of the label in pixels.
  172. * @param[in] styleName Optional style to use for the element. Style will be retrieved from GUISkin of the
  173. * GUIWidget the element is used on. If not specified default style is used.
  174. */
  175. static T* create(const HString& labelText, UINT32 labelWidth,
  176. const String& style = StringUtil::BLANK)
  177. {
  178. const String* curStyle = &style;
  179. if (*curStyle == StringUtil::BLANK)
  180. curStyle = &T::getGUITypeName();
  181. return bs_new<T>(PrivatelyConstruct(), GUIContent(labelText), labelWidth, *curStyle,
  182. GUIDimensions::create(), true);
  183. }
  184. /**
  185. * Creates a new GUI editor field with a label.
  186. *
  187. * @param[in] labelText String to display in the editor field label.
  188. * @param[in] styleName Optional style to use for the element. Style will be retrieved from GUISkin of the
  189. * GUIWidget the element is used on. If not specified default style is used.
  190. */
  191. static T* create(const HString& labelText, const String& style = StringUtil::BLANK)
  192. {
  193. const String* curStyle = &style;
  194. if (*curStyle == StringUtil::BLANK)
  195. curStyle = &T::getGUITypeName();
  196. return bs_new<T>(PrivatelyConstruct(), GUIContent(labelText), DEFAULT_LABEL_WIDTH, *curStyle,
  197. GUIDimensions::create(), true);
  198. }
  199. /**
  200. * Creates a new GUI editor field without a label.
  201. *
  202. * @param[in] styleName Optional style to use for the element. Style will be retrieved from GUISkin of the
  203. * GUIWidget the element is used on. If not specified default style is used.
  204. */
  205. static T* create(const String& style = StringUtil::BLANK)
  206. {
  207. const String* curStyle = &style;
  208. if (*curStyle == StringUtil::BLANK)
  209. curStyle = &T::getGUITypeName();
  210. return bs_new<T>(PrivatelyConstruct(), GUIContent(), 0, *curStyle,
  211. GUIDimensions::create(), false);
  212. }
  213. TGUIField(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  214. const String& style, const GUIDimensions& dimensions, bool withLabel)
  215. :GUIFieldBase(dummy, labelContent, labelWidth, style, dimensions, withLabel)
  216. { }
  217. };
  218. /** @} */
  219. }