BsGUIFieldBase.h 9.9 KB

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