UILayout.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. /// Specifies which height widgets in a AXIS_X layout should have,
  28. /// or which width widgets in a AXIS_Y layout should have.
  29. /// No matter what, it will still prioritize minimum and maximum for each widget.
  30. enum UI_LAYOUT_SIZE
  31. {
  32. /// Sizes depend on the gravity for each widget. (If the widget pulls
  33. /// towards both directions, it should grow to all available space)
  34. UI_LAYOUT_SIZE_GRAVITY = 0, // tb::LAYOUT_SIZE_GRAVITY,
  35. /// Size will be the preferred so each widget may be sized differently.
  36. UI_LAYOUT_SIZE_PREFERRED = 1, // tb::LAYOUT_SIZE_PREFERRED,
  37. /// Size should grow to all available space
  38. UI_LAYOUT_SIZE_AVAILABLE = 2 // tb::LAYOUT_SIZE_AVAILABLE
  39. };
  40. /// Specifies which width widgets in a AXIS_X layout should have,
  41. /// or which height widgets in a AXIS_Y layout should have. */
  42. ///
  43. enum UI_LAYOUT_DISTRIBUTION
  44. {
  45. ///< Size will be the preferred so each widget may be sized differently.
  46. UI_LAYOUT_DISTRIBUTION_PREFERRED = 0, // tb::LAYOUT_DISTRIBUTION_PREFERRED,
  47. ///< Size should grow to all available space
  48. UI_LAYOUT_DISTRIBUTION_AVAILABLE = 1, // tb::LAYOUT_DISTRIBUTION_AVAILABLE,
  49. ///< Sizes depend on the gravity for each widget. (If the widget pulls
  50. /// ///< towards both directions, it should grow to all available space)
  51. UI_LAYOUT_DISTRIBUTION_GRAVITY = 2 // tb::LAYOUT_DISTRIBUTION_GRAVITY
  52. };
  53. /// Specifies which y position widgets in a AXIS_X layout should have,
  54. /// or which x position widgets in a AXIS_Y layout should have. */
  55. enum UI_LAYOUT_POSITION
  56. {
  57. ///< Position is centered
  58. UI_LAYOUT_POSITION_CENTER = 0, // tb::LAYOUT_POSITION_CENTER,
  59. ///< Position is to the left for AXIS_Y layout and top for AXIS_X layout.
  60. UI_LAYOUT_POSITION_LEFT_TOP = 1, // tb::LAYOUT_POSITION_LEFT_TOP,
  61. ///< Position is to the right for AXIS_Y layout and bottom for AXIS_X layout.
  62. UI_LAYOUT_POSITION_RIGHT_BOTTOM = 2, // tb::LAYOUT_POSITION_RIGHT_BOTTOM,
  63. ///< Position depend on the gravity for each widget. (If the widget pulls
  64. /// ///< towards both directions, it will be centered)
  65. UI_LAYOUT_POSITION_GRAVITY = 3 // tb::LAYOUT_POSITION_GRAVITY
  66. };
  67. /** Specifies how widgets should be moved horizontally in a AXIS_X
  68. layout (or vertically in a AXIS_Y layout) if there is extra space
  69. available. */
  70. enum UI_LAYOUT_DISTRIBUTION_POSITION
  71. {
  72. UI_LAYOUT_DISTRIBUTION_POSITION_CENTER = 0, // tb::LAYOUT_DISTRIBUTION_POSITION_CENTER,
  73. UI_LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP = 1, // tb::LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP,
  74. UI_LAYOUT_DISTRIBUTION_POSITION_RIGHT_BOTTOM = 2 //tb::LAYOUT_DISTRIBUTION_POSITION_RIGHT_BOTTOM
  75. };
  76. class ATOMIC_API UILayoutParams : public Object
  77. {
  78. ATOMIC_OBJECT(UILayoutParams, Object)
  79. public:
  80. UILayoutParams(Context* context);
  81. virtual ~UILayoutParams();
  82. void SetWidth(int width) { params_.SetWidth(width); }
  83. void SetHeight(int height) { params_.SetHeight(height); }
  84. void SetMinWidth(int width) { params_.min_w = width; }
  85. void SetMinHeight(int height) { params_.min_h = height; }
  86. void SetMaxWidth(int width) { params_.max_w = width; }
  87. void SetMaxHeight(int height) { params_.max_h = height; }
  88. tb::LayoutParams* GetTBLayoutParams() { return &params_; }
  89. private:
  90. tb::LayoutParams params_;
  91. };
  92. class ATOMIC_API UILayout : public UIWidget
  93. {
  94. ATOMIC_OBJECT(UILayout, UIWidget)
  95. public:
  96. UILayout(Context* context, UI_AXIS axis = UI_AXIS_X, bool createWidget = true);
  97. virtual ~UILayout();
  98. void SetSpacing(int spacing);
  99. void SetAxis(UI_AXIS axis);
  100. void SetLayoutSize(UI_LAYOUT_SIZE size);
  101. void SetLayoutPosition(UI_LAYOUT_POSITION position);
  102. void SetLayoutDistribution(UI_LAYOUT_DISTRIBUTION distribution);
  103. void SetLayoutDistributionPosition(UI_LAYOUT_DISTRIBUTION_POSITION distribution_pos);
  104. /// A different way of setting up a layout, using a series of characters to program the main 5 layout fields
  105. /// character [0] = 'X' or 'Y' for UI_AXIS = X(D), Y
  106. /// character [1] = 'A'|'G'|'P' for UI_LAYOUT_SIZE = Available, Gravity(D), Perferred
  107. /// character [2] = 'C'|'G'|'L'|'R' for UI_LAYOUT_POSITION = Center(D), Gravity, LeftTop, RightBottom
  108. /// character [3] = 'A'|'G'|'P' for UI_LAYOUT_DISTRIBUTION = Available, Gravity, Perferred(D)
  109. /// character [4] = 'C'|'L'|'R' for UI_LAYOUT_DISTRIBUTION_POSITION, Center(D), LeftTop, RightBottom
  110. /// A '-' character in any field will not program that entry.
  111. /// Any character used that is not an allowed characters or a '-' will result in the default setting to be used.
  112. /// Any text in the string above character 5 is ignored.
  113. /// If the input string is less than 5 characters it will not program any of the fields.
  114. void SetLayoutConfig ( const String &settings );
  115. protected:
  116. virtual bool OnEvent(const tb::TBWidgetEvent &ev);
  117. private:
  118. };
  119. }