Debian Codegraph @

scene/gui/scroll_container.h

raw symbols SCIP
1 /**************************************************************************/
2 /* scroll_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
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; // The largest one among the min sizes of all available child controls.
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);