UILayout.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include <ThirdParty/TurboBadger/tb_layout.h>
  24. #include "UIWidget.h"
  25. namespace Atomic
  26. {
  27. enum UI_AXIS {
  28. ///< Horizontal layout
  29. UI_AXIS_X = tb::AXIS_X,
  30. ///< Vertical layout
  31. UI_AXIS_Y = tb::AXIS_Y,
  32. };
  33. /// Specifies which height widgets in a AXIS_X layout should have,
  34. /// or which width widgets in a AXIS_Y layout should have.
  35. /// No matter what, it will still prioritize minimum and maximum for each widget.
  36. enum UI_LAYOUT_SIZE
  37. {
  38. /// Sizes depend on the gravity for each widget. (If the widget pulls
  39. /// towards both directions, it should grow to all available space)
  40. UI_LAYOUT_SIZE_GRAVITY = tb::LAYOUT_SIZE_GRAVITY,
  41. /// Size will be the preferred so each widget may be sized differently.
  42. UI_LAYOUT_SIZE_PREFERRED = tb::LAYOUT_SIZE_PREFERRED,
  43. /// Size should grow to all available space
  44. UI_LAYOUT_SIZE_AVAILABLE = tb::LAYOUT_SIZE_AVAILABLE
  45. };
  46. /// Specifies which width widgets in a AXIS_X layout should have,
  47. /// or which height widgets in a AXIS_Y layout should have. */
  48. ///
  49. enum UI_LAYOUT_DISTRIBUTION
  50. {
  51. ///< Size will be the preferred so each widget may be sized differently.
  52. UI_LAYOUT_DISTRIBUTION_PREFERRED = tb::LAYOUT_DISTRIBUTION_PREFERRED,
  53. ///< Size should grow to all available space
  54. UI_LAYOUT_DISTRIBUTION_AVAILABLE = tb::LAYOUT_DISTRIBUTION_AVAILABLE,
  55. ///< Sizes depend on the gravity for each widget. (If the widget pulls
  56. /// ///< towards both directions, it should grow to all available space)
  57. UI_LAYOUT_DISTRIBUTION_GRAVITY = tb::LAYOUT_DISTRIBUTION_GRAVITY
  58. };
  59. /// Specifies which y position widgets in a AXIS_X layout should have,
  60. /// or which x position widgets in a AXIS_Y layout should have. */
  61. enum UI_LAYOUT_POSITION
  62. {
  63. ///< Position is centered
  64. UI_LAYOUT_POSITION_CENTER = tb::LAYOUT_POSITION_CENTER,
  65. ///< Position is to the left for AXIS_Y layout and top for AXIS_X layout.
  66. UI_LAYOUT_POSITION_LEFT_TOP = tb::LAYOUT_POSITION_LEFT_TOP,
  67. ///< Position is to the right for AXIS_Y layout and bottom for AXIS_X layout.
  68. UI_LAYOUT_POSITION_RIGHT_BOTTOM = tb::LAYOUT_POSITION_RIGHT_BOTTOM,
  69. ///< Position depend on the gravity for each widget. (If the widget pulls
  70. /// ///< towards both directions, it will be centered)
  71. UI_LAYOUT_POSITION_GRAVITY= tb::LAYOUT_POSITION_GRAVITY
  72. };
  73. /** Specifies how widgets should be moved horizontally in a AXIS_X
  74. layout (or vertically in a AXIS_Y layout) if there is extra space
  75. available. */
  76. enum UI_LAYOUT_DISTRIBUTION_POSITION
  77. {
  78. UI_LAYOUT_DISTRIBUTION_POSITION_CENTER = tb::LAYOUT_DISTRIBUTION_POSITION_CENTER,
  79. UI_LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP = tb::LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP,
  80. UI_LAYOUT_DISTRIBUTION_POSITION_RIGHT_BOTTOM = tb::LAYOUT_DISTRIBUTION_POSITION_RIGHT_BOTTOM
  81. };
  82. class UILayoutParams : public Object
  83. {
  84. OBJECT(UILayoutParams)
  85. public:
  86. UILayoutParams(Context* context);
  87. virtual ~UILayoutParams();
  88. void SetWidth(int width) { params_.SetWidth(width); }
  89. void SetHeight(int height) { params_.SetHeight(height); }
  90. void SetMinWidth(int width) { params_.min_w = width; }
  91. void SetMinHeight(int height) { params_.min_h = height; }
  92. void SetMaxWidth(int width) { params_.max_w = width; }
  93. void SetMaxHeight(int height) { params_.max_h = height; }
  94. tb::LayoutParams* GetTBLayoutParams() { return &params_; }
  95. private:
  96. tb::LayoutParams params_;
  97. };
  98. class UILayout : public UIWidget
  99. {
  100. OBJECT(UILayout)
  101. public:
  102. UILayout(Context* context, UI_AXIS axis = UI_AXIS_X, bool createWidget = true);
  103. virtual ~UILayout();
  104. void SetSpacing(int spacing);
  105. void SetAxis(UI_AXIS axis);
  106. void SetLayoutSize(UI_LAYOUT_SIZE size);
  107. void SetLayoutPosition(UI_LAYOUT_POSITION position);
  108. void SetLayoutDistribution(UI_LAYOUT_DISTRIBUTION distribution);
  109. void SetLayoutDistributionPosition(UI_LAYOUT_DISTRIBUTION_POSITION distribution_pos);
  110. protected:
  111. virtual bool OnEvent(const tb::TBWidgetEvent &ev);
  112. private:
  113. };
  114. }