2
0

BsGUIFieldBase.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 GUILayoutOptions& layoutOptions, bool withLabel);
  13. void _updateLayoutInternal(INT32 x, INT32 y, UINT32 width, UINT32 height,
  14. Rect2I clipRect, UINT8 widgetDepth, UINT16 areaDepth);
  15. virtual Vector2I _getOptimalSize() const;
  16. static const String& getLabelStyleType()
  17. {
  18. static String LABEL_STYLE_TYPE = "EditorFieldLabel";
  19. return LABEL_STYLE_TYPE;
  20. }
  21. protected:
  22. virtual ~GUIFieldBase() { }
  23. virtual void styleUpdated();
  24. static const UINT32 DEFAULT_LABEL_WIDTH;
  25. GUILayout* mLayout;
  26. GUILabel* mLabel;
  27. };
  28. template <class T>
  29. class TGUIField : public GUIFieldBase
  30. {
  31. public:
  32. static T* create(const GUIContent& labelContent, UINT32 labelWidth, const GUIOptions& layoutOptions,
  33. const String& style = StringUtil::BLANK)
  34. {
  35. const String* curStyle = &style;
  36. if (*curStyle == StringUtil::BLANK)
  37. curStyle = &T::getGUITypeName();
  38. return bs_new<T>(PrivatelyConstruct(), labelContent, labelWidth, *curStyle,
  39. GUILayoutOptions::create(layoutOptions), true);
  40. }
  41. static T* create(const GUIContent& labelContent, const GUIOptions& layoutOptions,
  42. const String& style = StringUtil::BLANK)
  43. {
  44. const String* curStyle = &style;
  45. if (*curStyle == StringUtil::BLANK)
  46. curStyle = &T::getGUITypeName();
  47. return bs_new<T>(PrivatelyConstruct(), labelContent, DEFAULT_LABEL_WIDTH, *curStyle,
  48. GUILayoutOptions::create(layoutOptions), true);
  49. }
  50. static T* create(const HString& labelText, UINT32 labelWidth, const GUIOptions& layoutOptions,
  51. const String& style = StringUtil::BLANK)
  52. {
  53. const String* curStyle = &style;
  54. if (*curStyle == StringUtil::BLANK)
  55. curStyle = &T::getGUITypeName();
  56. return bs_new<T>(PrivatelyConstruct(), GUIContent(labelText), labelWidth, *curStyle,
  57. GUILayoutOptions::create(layoutOptions), true);
  58. }
  59. static T* create(const HString& labelText, const GUIOptions& layoutOptions,
  60. const String& style = StringUtil::BLANK)
  61. {
  62. const String* curStyle = &style;
  63. if (*curStyle == StringUtil::BLANK)
  64. curStyle = &T::getGUITypeName();
  65. return bs_new<T>(PrivatelyConstruct(), GUIContent(labelText), DEFAULT_LABEL_WIDTH, *curStyle,
  66. GUILayoutOptions::create(layoutOptions), true);
  67. }
  68. static T* create(const GUIOptions& layoutOptions, const String& style = StringUtil::BLANK)
  69. {
  70. const String* curStyle = &style;
  71. if (*curStyle == StringUtil::BLANK)
  72. curStyle = &T::getGUITypeName();
  73. return bs_new<T>(PrivatelyConstruct(), GUIContent(), 0, *curStyle,
  74. GUILayoutOptions::create(layoutOptions), false);
  75. }
  76. static T* create(const GUIContent& labelContent, UINT32 labelWidth,
  77. const String& style = StringUtil::BLANK)
  78. {
  79. const String* curStyle = &style;
  80. if (*curStyle == StringUtil::BLANK)
  81. curStyle = &T::getGUITypeName();
  82. return bs_new<T>(PrivatelyConstruct(), labelContent, labelWidth, *curStyle, GUILayoutOptions::create(), true);
  83. }
  84. static T* create(const GUIContent& labelContent,
  85. const String& style = StringUtil::BLANK)
  86. {
  87. const String* curStyle = &style;
  88. if (*curStyle == StringUtil::BLANK)
  89. curStyle = &T::getGUITypeName();
  90. return bs_new<T>(PrivatelyConstruct(), labelContent, DEFAULT_LABEL_WIDTH, *curStyle,
  91. GUILayoutOptions::create(), true);
  92. }
  93. static T* create(const HString& labelText, UINT32 labelWidth,
  94. const String& style = StringUtil::BLANK)
  95. {
  96. const String* curStyle = &style;
  97. if (*curStyle == StringUtil::BLANK)
  98. curStyle = &T::getGUITypeName();
  99. return bs_new<T>(PrivatelyConstruct(), GUIContent(labelText), labelWidth, *curStyle,
  100. GUILayoutOptions::create(), true);
  101. }
  102. static T* create(const HString& labelText,
  103. const String& style = StringUtil::BLANK)
  104. {
  105. const String* curStyle = &style;
  106. if (*curStyle == StringUtil::BLANK)
  107. curStyle = &T::getGUITypeName();
  108. return bs_new<T>(PrivatelyConstruct(), GUIContent(labelText), DEFAULT_LABEL_WIDTH, *curStyle,
  109. GUILayoutOptions::create(), true);
  110. }
  111. static T* create(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(), 0, *curStyle,
  117. GUILayoutOptions::create(), false);
  118. }
  119. TGUIField(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  120. const String& style, const GUILayoutOptions& layoutOptions, bool withLabel)
  121. :GUIFieldBase(dummy, labelContent, labelWidth, style, layoutOptions, withLabel)
  122. { }
  123. };
  124. }