BsGUIFieldBase.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsGUIElementContainer.h"
  4. namespace BansheeEngine
  5. {
  6. class BS_ED_EXPORT GUIFieldBase : public GUIElementContainer
  7. {
  8. protected:
  9. struct PrivatelyConstruct {};
  10. public:
  11. GUIFieldBase(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  12. const String& labelStyle, const GUIDimensions& dimensions, bool withLabel);
  13. void _updateLayoutInternal(const GUILayoutData& data);
  14. virtual Vector2I _getOptimalSize() const;
  15. static const String& getLabelStyleType()
  16. {
  17. static String LABEL_STYLE_TYPE = "EditorFieldLabel";
  18. return LABEL_STYLE_TYPE;
  19. }
  20. protected:
  21. virtual ~GUIFieldBase() { }
  22. virtual void styleUpdated();
  23. static const UINT32 DEFAULT_LABEL_WIDTH;
  24. GUILayout* mLayout;
  25. GUILabel* mLabel;
  26. };
  27. template <class T>
  28. class TGUIField : public GUIFieldBase
  29. {
  30. public:
  31. static T* create(const GUIContent& labelContent, UINT32 labelWidth, const GUIOptions& options,
  32. const String& style = StringUtil::BLANK)
  33. {
  34. const String* curStyle = &style;
  35. if (*curStyle == StringUtil::BLANK)
  36. curStyle = &T::getGUITypeName();
  37. return bs_new<T>(PrivatelyConstruct(), labelContent, labelWidth, *curStyle,
  38. GUIDimensions::create(options), true);
  39. }
  40. static T* create(const GUIContent& labelContent, const GUIOptions& options,
  41. const String& style = StringUtil::BLANK)
  42. {
  43. const String* curStyle = &style;
  44. if (*curStyle == StringUtil::BLANK)
  45. curStyle = &T::getGUITypeName();
  46. return bs_new<T>(PrivatelyConstruct(), labelContent, DEFAULT_LABEL_WIDTH, *curStyle,
  47. GUIDimensions::create(options), true);
  48. }
  49. static T* create(const HString& labelText, UINT32 labelWidth, const GUIOptions& options,
  50. const String& style = StringUtil::BLANK)
  51. {
  52. const String* curStyle = &style;
  53. if (*curStyle == StringUtil::BLANK)
  54. curStyle = &T::getGUITypeName();
  55. return bs_new<T>(PrivatelyConstruct(), GUIContent(labelText), labelWidth, *curStyle,
  56. GUIDimensions::create(options), true);
  57. }
  58. static T* create(const HString& labelText, const GUIOptions& options,
  59. const String& style = StringUtil::BLANK)
  60. {
  61. const String* curStyle = &style;
  62. if (*curStyle == StringUtil::BLANK)
  63. curStyle = &T::getGUITypeName();
  64. return bs_new<T>(PrivatelyConstruct(), GUIContent(labelText), DEFAULT_LABEL_WIDTH, *curStyle,
  65. GUIDimensions::create(options), true);
  66. }
  67. static T* create(const GUIOptions& options, const String& style = StringUtil::BLANK)
  68. {
  69. const String* curStyle = &style;
  70. if (*curStyle == StringUtil::BLANK)
  71. curStyle = &T::getGUITypeName();
  72. return bs_new<T>(PrivatelyConstruct(), GUIContent(), 0, *curStyle,
  73. GUIDimensions::create(options), false);
  74. }
  75. static T* create(const GUIContent& labelContent, UINT32 labelWidth,
  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, labelWidth, *curStyle, GUIDimensions::create(), true);
  82. }
  83. static T* create(const GUIContent& labelContent,
  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(), true);
  91. }
  92. static T* create(const HString& labelText, UINT32 labelWidth,
  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(), true);
  100. }
  101. static T* create(const HString& labelText,
  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), DEFAULT_LABEL_WIDTH, *curStyle,
  108. GUIDimensions::create(), true);
  109. }
  110. static T* create(const String& style = StringUtil::BLANK)
  111. {
  112. const String* curStyle = &style;
  113. if (*curStyle == StringUtil::BLANK)
  114. curStyle = &T::getGUITypeName();
  115. return bs_new<T>(PrivatelyConstruct(), GUIContent(), 0, *curStyle,
  116. GUIDimensions::create(), false);
  117. }
  118. TGUIField(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  119. const String& style, const GUIDimensions& dimensions, bool withLabel)
  120. :GUIFieldBase(dummy, labelContent, labelWidth, style, dimensions, withLabel)
  121. { }
  122. };
  123. }