split_container.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /**************************************************************************/
  2. /* split_container.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef SPLIT_CONTAINER_H
  31. #define SPLIT_CONTAINER_H
  32. #include "scene/gui/container.h"
  33. class SplitContainerDragger : public Control {
  34. GDCLASS(SplitContainerDragger, Control);
  35. friend class SplitContainer;
  36. Rect2 split_bar_rect;
  37. protected:
  38. void _notification(int p_what);
  39. virtual void gui_input(const Ref<InputEvent> &p_event) override;
  40. private:
  41. bool dragging = false;
  42. int drag_from = 0;
  43. int drag_ofs = 0;
  44. bool mouse_inside = false;
  45. public:
  46. virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const override;
  47. };
  48. class SplitContainer : public Container {
  49. GDCLASS(SplitContainer, Container);
  50. friend class SplitContainerDragger;
  51. public:
  52. enum DraggerVisibility {
  53. DRAGGER_VISIBLE,
  54. DRAGGER_HIDDEN,
  55. DRAGGER_HIDDEN_COLLAPSED
  56. };
  57. private:
  58. int show_drag_area = false;
  59. int drag_area_margin_begin = 0;
  60. int drag_area_margin_end = 0;
  61. int drag_area_offset = 0;
  62. int split_offset = 0;
  63. int computed_split_offset = 0;
  64. bool vertical = false;
  65. bool collapsed = false;
  66. DraggerVisibility dragger_visibility = DRAGGER_VISIBLE;
  67. bool dragging_enabled = true;
  68. SplitContainerDragger *dragging_area_control = nullptr;
  69. struct ThemeCache {
  70. int separation = 0;
  71. int minimum_grab_thickness = 0;
  72. bool autohide = false;
  73. Ref<Texture2D> grabber_icon;
  74. Ref<Texture2D> grabber_icon_h;
  75. Ref<Texture2D> grabber_icon_v;
  76. float base_scale = 1.0;
  77. Ref<StyleBox> split_bar_background;
  78. } theme_cache;
  79. Ref<Texture2D> _get_grabber_icon() const;
  80. void _compute_split_offset(bool p_clamp);
  81. int _get_separation() const;
  82. void _resort();
  83. Control *_get_sortable_child(int p_idx, SortableVisbilityMode p_visibility_mode = SortableVisbilityMode::VISIBLE_IN_TREE) const;
  84. protected:
  85. bool is_fixed = false;
  86. void _notification(int p_what);
  87. void _validate_property(PropertyInfo &p_property) const;
  88. static void _bind_methods();
  89. public:
  90. void set_split_offset(int p_offset);
  91. int get_split_offset() const;
  92. void clamp_split_offset();
  93. void set_collapsed(bool p_collapsed);
  94. bool is_collapsed() const;
  95. void set_dragger_visibility(DraggerVisibility p_visibility);
  96. DraggerVisibility get_dragger_visibility() const;
  97. void set_vertical(bool p_vertical);
  98. bool is_vertical() const;
  99. void set_dragging_enabled(bool p_enabled);
  100. bool is_dragging_enabled() const;
  101. virtual Size2 get_minimum_size() const override;
  102. virtual Vector<int> get_allowed_size_flags_horizontal() const override;
  103. virtual Vector<int> get_allowed_size_flags_vertical() const override;
  104. void set_drag_area_margin_begin(int p_margin);
  105. int get_drag_area_margin_begin() const;
  106. void set_drag_area_margin_end(int p_margin);
  107. int get_drag_area_margin_end() const;
  108. void set_drag_area_offset(int p_offset);
  109. int get_drag_area_offset() const;
  110. void set_show_drag_area_enabled(bool p_enabled);
  111. bool is_show_drag_area_enabled() const;
  112. Control *get_drag_area_control() { return dragging_area_control; }
  113. SplitContainer(bool p_vertical = false);
  114. };
  115. VARIANT_ENUM_CAST(SplitContainer::DraggerVisibility);
  116. class HSplitContainer : public SplitContainer {
  117. GDCLASS(HSplitContainer, SplitContainer);
  118. public:
  119. HSplitContainer() :
  120. SplitContainer(false) { is_fixed = true; }
  121. };
  122. class VSplitContainer : public SplitContainer {
  123. GDCLASS(VSplitContainer, SplitContainer);
  124. public:
  125. VSplitContainer() :
  126. SplitContainer(true) { is_fixed = true; }
  127. };
  128. #endif // SPLIT_CONTAINER_H