| 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 "container.h" |
| 34 |
|
| 35 |
#include "scroll_bar.h" |
| 36 |
|
| 37 |
class PanelContainer; |
| 38 |
class TextureRect; |
| 39 |
|
| 40 |
class ScrollContainer : public Container { |
| 41 |
GDCLASS(ScrollContainer, Container); |
| 42 |
|
| 43 |
public: |
| 44 |
enum ScrollMode { |
| 45 |
SCROLL_MODE_DISABLED = 0, |
| 46 |
SCROLL_MODE_AUTO, |
| 47 |
SCROLL_MODE_SHOW_ALWAYS, |
| 48 |
SCROLL_MODE_SHOW_NEVER, |
| 49 |
SCROLL_MODE_RESERVE, |
| 50 |
}; |
| 51 |
|
| 52 |
enum ScrollHintMode { |
| 53 |
SCROLL_HINT_MODE_DISABLED, |
| 54 |
SCROLL_HINT_MODE_ALL, |
| 55 |
SCROLL_HINT_MODE_TOP_AND_LEFT, |
| 56 |
SCROLL_HINT_MODE_BOTTOM_AND_RIGHT, |
| 57 |
}; |
| 58 |
|
| 59 |
private: |
| 60 |
HScrollBar *h_scroll = nullptr; |
| 61 |
VScrollBar *v_scroll = nullptr; |
| 62 |
PanelContainer *focus_panel = nullptr; |
| 63 |
|
| 64 |
mutable Size2 largest_child_min_size; |
| 65 |
|
| 66 |
void _update_scrollbars(); |
| 67 |
|
| 68 |
Vector2 drag_speed; |
| 69 |
Vector2 drag_accum; |
| 70 |
Vector2 drag_from; |
| 71 |
Vector2 last_drag_accum; |
| 72 |
float time_since_motion = 0.0f; |
| 73 |
bool drag_touching = false; |
| 74 |
bool drag_touching_deaccel = false; |
| 75 |
bool beyond_deadzone = false; |
| 76 |
bool scroll_on_drag_hover = false; |
| 77 |
|
| 78 |
TextureRect *scroll_hint_top_left = nullptr; |
| 79 |
TextureRect *scroll_hint_bottom_right = nullptr; |
| 80 |
|
| 81 |
ScrollMode horizontal_scroll_mode = SCROLL_MODE_AUTO; |
| 82 |
ScrollMode vertical_scroll_mode = SCROLL_MODE_AUTO; |
| 83 |
|
| 84 |
void _update_scroll_hints(); |
| 85 |
|
| 86 |
int deadzone = 0; |
| 87 |
bool follow_focus = false; |
| 88 |
int scroll_border = 20; |
| 89 |
int scroll_speed = 12; |
| 90 |
|
| 91 |
ScrollHintMode scroll_hint_mode = SCROLL_HINT_MODE_DISABLED; |
| 92 |
bool tile_scroll_hint = false; |
| 93 |
|
| 94 |
struct ThemeCache { |
| 95 |
Ref<StyleBox> panel_style; |
| 96 |
Ref<StyleBox> focus_style; |
| 97 |
|
| 98 |
Ref<Texture2D> scroll_hint_vertical; |
| 99 |
Ref<Texture2D> scroll_hint_horizontal; |
| 100 |
|
| 101 |
Color scroll_hint_vertical_color; |
| 102 |
Color scroll_hint_horizontal_color; |
| 103 |
|
| 104 |
int scrollbar_h_separation = 0; |
| 105 |
int scrollbar_v_separation = 0; |
| 106 |
} theme_cache; |
| 107 |
|
| 108 |
void _cancel_drag(); |
| 109 |
|
| 110 |
bool _is_h_scroll_visible() const; |
| 111 |
bool _is_v_scroll_visible() const; |
| 112 |
|
| 113 |
Rect2 _get_margins() const; |
| 114 |
|
| 115 |
bool draw_focus_border = false; |
| 116 |
bool focus_border_is_drawn = false; |
| 117 |
bool child_has_focus(); |
| 118 |
|
| 119 |
protected: |
| 120 |
Size2 get_minimum_size() const override; |
| 121 |
|
| 122 |
void _gui_focus_changed(Control *p_control); |
| 123 |
void _reposition_children(); |
| 124 |
|
| 125 |
void _notification(int p_what); |
| 126 |
static void _bind_methods(); |
| 127 |
|
| 128 |
bool _updating_scrollbars = false; |
| 129 |
void _update_scrollbar_position(); |
| 130 |
void _scroll_moved(float); |
| 131 |
|
| 132 |
void _accessibility_action_scroll_set(const Variant &p_data); |
| 133 |
void _accessibility_action_scroll_up(const Variant &p_data); |
| 134 |
void _accessibility_action_scroll_down(const Variant &p_data); |
| 135 |
void _accessibility_action_scroll_left(const Variant &p_data); |
| 136 |
void _accessibility_action_scroll_right(const Variant &p_data); |
| 137 |
|
| 138 |
public: |
| 139 |
virtual void gui_input(const Ref<InputEvent> &p_gui_input) override; |
| 140 |
|
| 141 |
void set_h_scroll(int p_pos); |
| 142 |
int get_h_scroll() const; |
| 143 |
|
| 144 |
void set_v_scroll(int p_pos); |
| 145 |
int get_v_scroll() const; |
| 146 |
|
| 147 |
void set_horizontal_custom_step(float p_custom_step); |
| 148 |
float get_horizontal_custom_step() const; |
| 149 |
|
| 150 |
void set_vertical_custom_step(float p_custom_step); |
| 151 |
float get_vertical_custom_step() const; |
| 152 |
|
| 153 |
void set_horizontal_scroll_mode(ScrollMode p_mode); |
| 154 |
ScrollMode get_horizontal_scroll_mode() const; |
| 155 |
|
| 156 |
void set_vertical_scroll_mode(ScrollMode p_mode); |
| 157 |
ScrollMode get_vertical_scroll_mode() const; |
| 158 |
|
| 159 |
void set_deadzone(int p_deadzone); |
| 160 |
int get_deadzone() const; |
| 161 |
|
| 162 |
void set_scroll_hint_mode(ScrollHintMode p_mode); |
| 163 |
ScrollHintMode get_scroll_hint_mode() const; |
| 164 |
|
| 165 |
void set_tile_scroll_hint(bool p_enable); |
| 166 |
bool is_scroll_hint_tiled(); |
| 167 |
|
| 168 |
bool is_following_focus() const; |
| 169 |
void set_follow_focus(bool p_follow); |
| 170 |
|
| 171 |
void set_scroll_on_drag_hover(bool p_scroll); |
| 172 |
|
| 173 |
HScrollBar *get_h_scroll_bar(); |
| 174 |
VScrollBar *get_v_scroll_bar(); |
| 175 |
void ensure_control_visible(Control *p_control); |
| 176 |
|
| 177 |
PackedStringArray get_configuration_warnings() const override; |
| 178 |
|
| 179 |
void set_draw_focus_border(bool p_draw); |
| 180 |
bool get_draw_focus_border(); |
| 181 |
|
| 182 |
ScrollContainer(); |
| 183 |
}; |
| 184 |
|
| 185 |
VARIANT_ENUM_CAST(ScrollContainer::ScrollMode); |
| 186 |
VARIANT_ENUM_CAST(ScrollContainer::ScrollHintMode); |