BsGUIFieldBase.h 9.6 KB

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