| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/gui/container.h" |
| 34 |
|
| 35 |
class TextureRect; |
| 36 |
|
| 37 |
class SplitContainerDragger : public Control { |
| 38 |
GDCLASS(SplitContainerDragger, Control); |
| 39 |
friend class SplitContainer; |
| 40 |
|
| 41 |
Rect2 split_bar_rect; |
| 42 |
TextureRect *touch_dragger = nullptr; |
| 43 |
|
| 44 |
void _touch_dragger_mouse_exited(); |
| 45 |
void _touch_dragger_gui_input(const Ref<InputEvent> &p_event); |
| 46 |
|
| 47 |
protected: |
| 48 |
void _notification(int p_what); |
| 49 |
virtual void gui_input(const Ref<InputEvent> &p_event) override; |
| 50 |
|
| 51 |
void _accessibility_action_inc(const Variant &p_data); |
| 52 |
void _accessibility_action_dec(const Variant &p_data); |
| 53 |
void _accessibility_action_set_value(const Variant &p_data); |
| 54 |
|
| 55 |
private: |
| 56 |
bool dragging = false; |
| 57 |
int drag_from = 0; |
| 58 |
int start_drag_split_offset = 0; |
| 59 |
bool mouse_inside = false; |
| 60 |
|
| 61 |
public: |
| 62 |
int dragger_index = -1; |
| 63 |
|
| 64 |
virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const override; |
| 65 |
|
| 66 |
void set_touch_dragger_enabled(bool p_enabled); |
| 67 |
void update_touch_dragger(); |
| 68 |
bool is_touch_dragger_enabled() const; |
| 69 |
|
| 70 |
SplitContainerDragger(); |
| 71 |
}; |
| 72 |
|
| 73 |
class SplitContainer : public Container { |
| 74 |
GDCLASS(SplitContainer, Container); |
| 75 |
friend class SplitContainerDragger; |
| 76 |
|
| 77 |
public: |
| 78 |
enum DraggerVisibility { |
| 79 |
DRAGGER_VISIBLE, |
| 80 |
DRAGGER_HIDDEN, |
| 81 |
DRAGGER_HIDDEN_COLLAPSED |
| 82 |
}; |
| 83 |
|
| 84 |
private: |
| 85 |
bool show_drag_area = false; |
| 86 |
int drag_area_margin_begin = 0; |
| 87 |
int drag_area_margin_end = 0; |
| 88 |
int drag_area_offset = 0; |
| 89 |
|
| 90 |
PackedInt32Array split_offsets; |
| 91 |
LocalVector<int> default_dragger_positions; |
| 92 |
LocalVector<int> dragger_positions; |
| 93 |
LocalVector<Control *> valid_children; |
| 94 |
LocalVector<SplitContainerDragger *> dragging_area_controls; |
| 95 |
|
| 96 |
bool vertical = false; |
| 97 |
bool collapsed = false; |
| 98 |
DraggerVisibility dragger_visibility = DRAGGER_VISIBLE; |
| 99 |
bool dragging_enabled = true; |
| 100 |
bool split_offset_pending = false; |
| 101 |
bool can_use_desired_sizes = false; |
| 102 |
bool initialized = false; |
| 103 |
|
| 104 |
bool touch_dragger_enabled = false; |
| 105 |
|
| 106 |
struct ThemeCache { |
| 107 |
Color touch_dragger_color; |
| 108 |
Color touch_dragger_pressed_color; |
| 109 |
Color touch_dragger_hover_color; |
| 110 |
int separation = 0; |
| 111 |
int minimum_grab_thickness = 0; |
| 112 |
bool autohide = false; |
| 113 |
Ref<Texture2D> touch_dragger_icon; |
| 114 |
Ref<Texture2D> touch_dragger_icon_h; |
| 115 |
Ref<Texture2D> touch_dragger_icon_v; |
| 116 |
Ref<Texture2D> grabber_icon; |
| 117 |
Ref<Texture2D> grabber_icon_h; |
| 118 |
Ref<Texture2D> grabber_icon_v; |
| 119 |
float base_scale = 1.0; |
| 120 |
Ref<StyleBox> split_bar_background; |
| 121 |
} theme_cache; |
| 122 |
|
| 123 |
Ref<Texture2D> _get_grabber_icon() const; |
| 124 |
Ref<Texture2D> _get_touch_dragger_icon() const; |
| 125 |
Point2i _get_valid_range(int p_dragger_index) const; |
| 126 |
|
| 127 |
PackedInt32Array _get_desired_sizes() const; |
| 128 |
void _set_desired_sizes(const PackedInt32Array &p_desired_sizes, int p_priority_index = -1); |
| 129 |
|
| 130 |
void _update_default_dragger_positions(); |
| 131 |
void _update_dragger_positions(int p_clamp_index = -1); |
| 132 |
int _get_separation() const; |
| 133 |
void _resort(); |
| 134 |
void _update_draggers(); |
| 135 |
void _on_child_visibility_changed(Control *p_control); |
| 136 |
void _add_valid_child(Control *p_control); |
| 137 |
void _remove_valid_child(Control *p_control); |
| 138 |
|
| 139 |
protected: |
| 140 |
bool is_fixed = false; |
| 141 |
|
| 142 |
void _notification(int p_what); |
| 143 |
void _validate_property(PropertyInfo &p_property) const; |
| 144 |
|
| 145 |
virtual void add_child_notify(Node *p_child) override; |
| 146 |
virtual void remove_child_notify(Node *p_child) override; |
| 147 |
virtual void move_child_notify(Node *p_child) override; |
| 148 |
static void _bind_methods(); |
| 149 |
|
| 150 |
#ifndef DISABLE_DEPRECATED |
| 151 |
void _clamp_split_offset_compat_90411(); |
| 152 |
static void _bind_compatibility_methods(); |
| 153 |
#endif |
| 154 |
|
| 155 |
public: |
| 156 |
void set_split_offset(int p_offset, int p_index = 0); |
| 157 |
int get_split_offset(int p_index = 0) const; |
| 158 |
|
| 159 |
void set_split_offsets(const PackedInt32Array &p_offsets); |
| 160 |
PackedInt32Array get_split_offsets() const; |
| 161 |
|
| 162 |
void clamp_split_offset(int p_priority_index = 0); |
| 163 |
|
| 164 |
void set_collapsed(bool p_collapsed); |
| 165 |
bool is_collapsed() const; |
| 166 |
|
| 167 |
void set_dragger_visibility(DraggerVisibility p_visibility); |
| 168 |
DraggerVisibility get_dragger_visibility() const; |
| 169 |
|
| 170 |
void set_vertical(bool p_vertical); |
| 171 |
bool is_vertical() const; |
| 172 |
|
| 173 |
void set_dragging_enabled(bool p_enabled); |
| 174 |
bool is_dragging_enabled() const; |
| 175 |
|
| 176 |
virtual Size2 get_minimum_size() const override; |
| 177 |
|
| 178 |
virtual Vector<int> get_allowed_size_flags_horizontal() const override; |
| 179 |
virtual Vector<int> get_allowed_size_flags_vertical() const override; |
| 180 |
|
| 181 |
void set_drag_area_margin_begin(int p_margin); |
| 182 |
int get_drag_area_margin_begin() const; |
| 183 |
|
| 184 |
void set_drag_area_margin_end(int p_margin); |
| 185 |
int get_drag_area_margin_end() const; |
| 186 |
|
| 187 |
void set_drag_area_offset(int p_offset); |
| 188 |
int get_drag_area_offset() const; |
| 189 |
|
| 190 |
void set_show_drag_area_enabled(bool p_enabled); |
| 191 |
bool is_show_drag_area_enabled() const; |
| 192 |
|
| 193 |
TypedArray<Control> get_drag_area_controls(); |
| 194 |
|
| 195 |
void set_touch_dragger_enabled(bool p_enabled); |
| 196 |
bool is_touch_dragger_enabled() const; |
| 197 |
|
| 198 |
#ifndef DISABLE_DEPRECATED |
| 199 |
Control *get_drag_area_control() { return dragging_area_controls[0]; } |
| 200 |
void _set_split_offset_first(int p_offset) { set_split_offset(p_offset); } |
| 201 |
int _get_split_offset_first() const { return get_split_offset(); } |
| 202 |
#endif |
| 203 |
|
| 204 |
SplitContainer(bool p_vertical = false); |
| 205 |
}; |
| 206 |
|
| 207 |
VARIANT_ENUM_CAST(SplitContainer::DraggerVisibility); |
| 208 |
|
| 209 |
class HSplitContainer : public SplitContainer { |
| 210 |
GDCLASS(HSplitContainer, SplitContainer); |
| 211 |
|
| 212 |
public: |
| 213 |
HSplitContainer() : |
| 214 |
SplitContainer(false) { is_fixed = true; } |
| 215 |
}; |
| 216 |
|
| 217 |
class VSplitContainer : public SplitContainer { |
| 218 |
GDCLASS(VSplitContainer, SplitContainer); |
| 219 |
|
| 220 |
public: |
| 221 |
VSplitContainer() : |
| 222 |
SplitContainer(true) { is_fixed = true; } |
| 223 |
}; |