BsGUIFieldBase.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. RectI clipRect, UINT8 widgetDepth, UINT16 areaDepth);
  15. Vector2I _getOptimalSize() const;
  16. protected:
  17. virtual ~GUIFieldBase() { }
  18. protected:
  19. static const UINT32 DEFAULT_LABEL_WIDTH;
  20. GUILayout* mLayout;
  21. GUILabel* mLabel;
  22. };
  23. template <class T>
  24. class TGUIField : public GUIFieldBase
  25. {
  26. public:
  27. static T* create(const GUIContent& labelContent, UINT32 labelWidth, const GUIOptions& layoutOptions,
  28. const String& labelStyle = StringUtil::BLANK, const String& entryElementStyle = StringUtil::BLANK)
  29. {
  30. return bs_new<T>(PrivatelyConstruct(), labelContent, labelWidth, labelStyle, entryElementStyle,
  31. GUILayoutOptions::create(layoutOptions), true);
  32. }
  33. static T* create(const GUIContent& labelContent, const GUIOptions& layoutOptions,
  34. const String& labelStyle = StringUtil::BLANK, const String& entryElementStyle = StringUtil::BLANK)
  35. {
  36. return bs_new<T>(PrivatelyConstruct(), labelContent, DEFAULT_LABEL_WIDTH, labelStyle, entryElementStyle,
  37. GUILayoutOptions::create(layoutOptions), true);
  38. }
  39. static T* create(const HString& labelText, UINT32 labelWidth, const GUIOptions& layoutOptions,
  40. const String& labelStyle = StringUtil::BLANK, const String& entryElementStyle = StringUtil::BLANK)
  41. {
  42. return bs_new<T>(PrivatelyConstruct(), GUIContent(labelText), labelWidth, labelStyle, entryElementStyle,
  43. GUILayoutOptions::create(layoutOptions), true);
  44. }
  45. static T* create(const HString& labelText, const GUIOptions& layoutOptions,
  46. const String& labelStyle = StringUtil::BLANK, const String& entryElementStyle = StringUtil::BLANK)
  47. {
  48. return bs_new<T>(PrivatelyConstruct(), GUIContent(labelText), DEFAULT_LABEL_WIDTH, labelStyle, entryElementStyle,
  49. GUILayoutOptions::create(layoutOptions), true);
  50. }
  51. static T* create(const GUIOptions& layoutOptions, const String& entryElementStyle = StringUtil::BLANK)
  52. {
  53. return bs_new<T>(PrivatelyConstruct(), GUIContent(), 0, nullptr, entryElementStyle,
  54. GUILayoutOptions::create(layoutOptions), false);
  55. }
  56. static T* create(const GUIContent& labelContent, UINT32 labelWidth,
  57. const String& labelStyle = StringUtil::BLANK, const String& entryElementStyle = StringUtil::BLANK)
  58. {
  59. return bs_new<T>(PrivatelyConstruct(), labelContent, labelWidth, labelStyle, entryElementStyle,
  60. GUILayoutOptions::create(), true);
  61. }
  62. static T* create(const GUIContent& labelContent,
  63. const String& labelStyle = StringUtil::BLANK, const String& entryElementStyle = StringUtil::BLANK)
  64. {
  65. return bs_new<T>(PrivatelyConstruct(), labelContent, DEFAULT_LABEL_WIDTH, labelStyle, entryElementStyle,
  66. GUILayoutOptions::create(), true);
  67. }
  68. static T* create(const HString& labelText, UINT32 labelWidth,
  69. const String& labelStyle = StringUtil::BLANK, const String& entryElementStyle = StringUtil::BLANK)
  70. {
  71. return bs_new<T>(PrivatelyConstruct(), GUIContent(labelText), labelWidth, labelStyle, entryElementStyle,
  72. GUILayoutOptions::create(), true);
  73. }
  74. static T* create(const HString& labelText,
  75. const String& labelStyle = StringUtil::BLANK, const String& entryElementStyle = StringUtil::BLANK)
  76. {
  77. return bs_new<T>(PrivatelyConstruct(), GUIContent(labelText), DEFAULT_LABEL_WIDTH, labelStyle, entryElementStyle,
  78. GUILayoutOptions::create(), true);
  79. }
  80. static T* create(const String& entryElementStyle = StringUtil::BLANK)
  81. {
  82. return bs_new<T>(PrivatelyConstruct(), GUIContent(), 0, nullptr, entryElementStyle,
  83. GUILayoutOptions::create(), false);
  84. }
  85. TGUIField(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  86. const String& labelStyle, const GUILayoutOptions& layoutOptions, bool withLabel)
  87. :GUIFieldBase(dummy, labelContent, labelWidth, labelStyle, layoutOptions, withLabel)
  88. { }
  89. };
  90. }