split_container.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. #pragma once
  31. #include "scene/gui/container.h"
  32. class TextureRect;
  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. void _accessibility_action_inc(const Variant &p_data);
  41. void _accessibility_action_dec(const Variant &p_data);
  42. void _accessibility_action_set_value(const Variant &p_data);
  43. private:
  44. bool dragging = false;
  45. int drag_from = 0;
  46. int drag_ofs = 0;
  47. bool mouse_inside = false;
  48. public:
  49. virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const override;
  50. SplitContainerDragger();
  51. };
  52. class SplitContainer : public Container {
  53. GDCLASS(SplitContainer, Container);
  54. friend class SplitContainerDragger;
  55. public:
  56. enum DraggerVisibility {
  57. DRAGGER_VISIBLE,
  58. DRAGGER_HIDDEN,
  59. DRAGGER_HIDDEN_COLLAPSED
  60. };
  61. private:
  62. int show_drag_area = false;
  63. int drag_area_margin_begin = 0;
  64. int drag_area_margin_end = 0;
  65. int drag_area_offset = 0;
  66. int split_offset = 0;
  67. int computed_split_offset = 0;
  68. bool vertical = false;
  69. bool collapsed = false;
  70. DraggerVisibility dragger_visibility = DRAGGER_VISIBLE;
  71. bool dragging_enabled = true;
  72. SplitContainerDragger *dragging_area_control = nullptr;
  73. bool touch_dragger_enabled = false;
  74. TextureRect *touch_dragger = nullptr;
  75. struct ThemeCache {
  76. Color touch_dragger_color;
  77. Color touch_dragger_pressed_color;
  78. Color touch_dragger_hover_color;
  79. int separation = 0;
  80. int minimum_grab_thickness = 0;
  81. bool autohide = false;
  82. Ref<Texture2D> touch_dragger_icon;
  83. Ref<Texture2D> touch_dragger_icon_h;
  84. Ref<Texture2D> touch_dragger_icon_v;
  85. Ref<Texture2D> grabber_icon;
  86. Ref<Texture2D> grabber_icon_h;
  87. Ref<Texture2D> grabber_icon_v;
  88. float base_scale = 1.0;
  89. Ref<StyleBox> split_bar_background;
  90. } theme_cache;
  91. Ref<Texture2D> _get_grabber_icon() const;
  92. Ref<Texture2D> _get_touch_dragger_icon() const;
  93. void _touch_dragger_mouse_exited();
  94. void _touch_dragger_gui_input(const Ref<InputEvent> &p_event);
  95. void _compute_split_offset(bool p_clamp);
  96. int _get_separation() const;
  97. void _resort();
  98. Control *_get_sortable_child(int p_idx, SortableVisibilityMode p_visibility_mode = SortableVisibilityMode::VISIBLE_IN_TREE) const;
  99. protected:
  100. bool is_fixed = false;
  101. void _notification(int p_what);
  102. void _validate_property(PropertyInfo &p_property) const;
  103. static void _bind_methods();
  104. public:
  105. void set_split_offset(int p_offset);
  106. int get_split_offset() const;
  107. void clamp_split_offset();
  108. void set_collapsed(bool p_collapsed);
  109. bool is_collapsed() const;
  110. void set_dragger_visibility(DraggerVisibility p_visibility);
  111. DraggerVisibility get_dragger_visibility() const;
  112. void set_vertical(bool p_vertical);
  113. bool is_vertical() const;
  114. void set_dragging_enabled(bool p_enabled);
  115. bool is_dragging_enabled() const;
  116. virtual Size2 get_minimum_size() const override;
  117. virtual Vector<int> get_allowed_size_flags_horizontal() const override;
  118. virtual Vector<int> get_allowed_size_flags_vertical() const override;
  119. void set_drag_area_margin_begin(int p_margin);
  120. int get_drag_area_margin_begin() const;
  121. void set_drag_area_margin_end(int p_margin);
  122. int get_drag_area_margin_end() const;
  123. void set_drag_area_offset(int p_offset);
  124. int get_drag_area_offset() const;
  125. void set_show_drag_area_enabled(bool p_enabled);
  126. bool is_show_drag_area_enabled() const;
  127. Control *get_drag_area_control() { return dragging_area_control; }
  128. void set_touch_dragger_enabled(bool p_enabled);
  129. bool is_touch_dragger_enabled() const;
  130. SplitContainer(bool p_vertical = false);
  131. };
  132. VARIANT_ENUM_CAST(SplitContainer::DraggerVisibility);
  133. class HSplitContainer : public SplitContainer {
  134. GDCLASS(HSplitContainer, SplitContainer);
  135. public:
  136. HSplitContainer() :
  137. SplitContainer(false) { is_fixed = true; }
  138. };
  139. class VSplitContainer : public SplitContainer {
  140. GDCLASS(VSplitContainer, SplitContainer);
  141. public:
  142. VSplitContainer() :
  143. SplitContainer(true) { is_fixed = true; }
  144. };