UILayout.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #pragma once
  2. #include <ThirdParty/TurboBadger/tb_layout.h>
  3. #include "UIWidget.h"
  4. namespace Atomic
  5. {
  6. enum UI_AXIS {
  7. ///< Horizontal layout
  8. UI_AXIS_X = tb::AXIS_X,
  9. ///< Vertical layout
  10. UI_AXIS_Y = tb::AXIS_Y,
  11. };
  12. /// Specifies which height widgets in a AXIS_X layout should have,
  13. /// or which width widgets in a AXIS_Y layout should have.
  14. /// No matter what, it will still prioritize minimum and maximum for each widget.
  15. enum UI_LAYOUT_SIZE
  16. {
  17. /// Sizes depend on the gravity for each widget. (If the widget pulls
  18. /// towards both directions, it should grow to all available space)
  19. UI_LAYOUT_SIZE_GRAVITY = tb::LAYOUT_SIZE_GRAVITY,
  20. /// Size will be the preferred so each widget may be sized differently.
  21. UI_LAYOUT_SIZE_PREFERRED = tb::LAYOUT_SIZE_PREFERRED,
  22. /// Size should grow to all available space
  23. UI_LAYOUT_SIZE_AVAILABLE = tb::LAYOUT_SIZE_AVAILABLE
  24. };
  25. /// Specifies which width widgets in a AXIS_X layout should have,
  26. /// or which height widgets in a AXIS_Y layout should have. */
  27. ///
  28. enum UI_LAYOUT_DISTRIBUTION
  29. {
  30. ///< Size will be the preferred so each widget may be sized differently.
  31. UI_LAYOUT_DISTRIBUTION_PREFERRED = tb::LAYOUT_DISTRIBUTION_PREFERRED,
  32. ///< Size should grow to all available space
  33. UI_LAYOUT_DISTRIBUTION_AVAILABLE = tb::LAYOUT_DISTRIBUTION_AVAILABLE,
  34. ///< Sizes depend on the gravity for each widget. (If the widget pulls
  35. /// ///< towards both directions, it should grow to all available space)
  36. UI_LAYOUT_DISTRIBUTION_GRAVITY = tb::LAYOUT_DISTRIBUTION_GRAVITY
  37. };
  38. /// Specifies which y position widgets in a AXIS_X layout should have,
  39. /// or which x position widgets in a AXIS_Y layout should have. */
  40. enum UI_LAYOUT_POSITION
  41. {
  42. ///< Position is centered
  43. UI_LAYOUT_POSITION_CENTER = tb::LAYOUT_POSITION_CENTER,
  44. ///< Position is to the left for AXIS_Y layout and top for AXIS_X layout.
  45. UI_LAYOUT_POSITION_LEFT_TOP = tb::LAYOUT_POSITION_LEFT_TOP,
  46. ///< Position is to the right for AXIS_Y layout and bottom for AXIS_X layout.
  47. UI_LAYOUT_POSITION_RIGHT_BOTTOM = tb::LAYOUT_POSITION_RIGHT_BOTTOM,
  48. ///< Position depend on the gravity for each widget. (If the widget pulls
  49. /// ///< towards both directions, it will be centered)
  50. UI_LAYOUT_POSITION_GRAVITY= tb::LAYOUT_POSITION_GRAVITY
  51. };
  52. /** Specifies how widgets should be moved horizontally in a AXIS_X
  53. layout (or vertically in a AXIS_Y layout) if there is extra space
  54. available. */
  55. enum UI_LAYOUT_DISTRIBUTION_POSITION
  56. {
  57. UI_LAYOUT_DISTRIBUTION_POSITION_CENTER = tb::LAYOUT_DISTRIBUTION_POSITION_CENTER,
  58. UI_LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP = tb::LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP,
  59. UI_LAYOUT_DISTRIBUTION_POSITION_RIGHT_BOTTOM = tb::LAYOUT_DISTRIBUTION_POSITION_RIGHT_BOTTOM
  60. };
  61. class UILayoutParams : public Object
  62. {
  63. OBJECT(UILayoutParams)
  64. public:
  65. UILayoutParams(Context* context);
  66. virtual ~UILayoutParams();
  67. void SetWidth(int width) { params_.SetWidth(width); }
  68. void SetHeight(int height) { params_.SetHeight(height); }
  69. void SetMinWidth(int width) { params_.min_w = width; }
  70. void SetMinHeight(int height) { params_.min_h = height; }
  71. void SetMaxWidth(int width) { params_.max_w = width; }
  72. void SetMaxHeight(int height) { params_.max_h = height; }
  73. tb::LayoutParams* GetTBLayoutParams() { return &params_; }
  74. private:
  75. tb::LayoutParams params_;
  76. };
  77. class UILayout : public UIWidget
  78. {
  79. OBJECT(UILayout)
  80. public:
  81. UILayout(Context* context, UI_AXIS axis = UI_AXIS_X, bool createWidget = true);
  82. virtual ~UILayout();
  83. void SetSpacing(int spacing);
  84. void SetAxis(UI_AXIS axis);
  85. void SetLayoutSize(UI_LAYOUT_SIZE size);
  86. void SetLayoutPosition(UI_LAYOUT_POSITION position);
  87. void SetLayoutDistribution(UI_LAYOUT_DISTRIBUTION distribution);
  88. void SetLayoutDistributionPosition(UI_LAYOUT_DISTRIBUTION_POSITION distribution_pos);
  89. protected:
  90. virtual bool OnEvent(const tb::TBWidgetEvent &ev);
  91. private:
  92. };
  93. }