BsGUIFieldBase.h 9.5 KB

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