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#ifndef SCROLL_CONTAINER_H
32#define SCROLL_CONTAINER_H
33
34#include "container.h"
35
36#include "scroll_bar.h"
37
38class ScrollContainer : public Container {
39 GDCLASS(ScrollContainer, Container);
40
41public:
42 enum ScrollMode {
43 SCROLL_MODE_DISABLED = 0,
44 SCROLL_MODE_AUTO,
45 SCROLL_MODE_SHOW_ALWAYS,
46 SCROLL_MODE_SHOW_NEVER,
47 };
48
49private:
50 HScrollBar *h_scroll = nullptr;
51 VScrollBar *v_scroll = nullptr;
52
53 mutable Size2 largest_child_min_size; // The largest one among the min sizes of all available child controls.
54
55 void update_scrollbars();
56
57 Vector2 drag_speed;
58 Vector2 drag_accum;
59 Vector2 drag_from;
60 Vector2 last_drag_accum;
61 float time_since_motion = 0.0f;
62 bool drag_touching = false;
63 bool drag_touching_deaccel = false;
64 bool beyond_deadzone = false;
65
66 ScrollMode horizontal_scroll_mode = SCROLL_MODE_AUTO;
67 ScrollMode vertical_scroll_mode = SCROLL_MODE_AUTO;
68
69 int deadzone = 0;
70 bool follow_focus = false;
71
72 struct ThemeCache {
73 Ref<StyleBox> panel_style;
74 } theme_cache;
75
76 void _cancel_drag();
77
78protected:
79 Size2 get_minimum_size() const override;
80
81 void _gui_focus_changed(Control *p_control);
82 void _reposition_children();
83
84 void _notification(int p_what);
85 static void _bind_methods();
86
87 bool _updating_scrollbars = false;
88 void _update_scrollbar_position();
89 void _scroll_moved(float);
90
91public:
92 virtual void gui_input(const Ref<InputEvent> &p_gui_input) override;
93
94 void set_h_scroll(int p_pos);
95 int get_h_scroll() const;
96
97 void set_v_scroll(int p_pos);
98 int get_v_scroll() const;
99
100 void set_horizontal_custom_step(float p_custom_step);
101 float get_horizontal_custom_step() const;
102
103 void set_vertical_custom_step(float p_custom_step);
104 float get_vertical_custom_step() const;
105
106 void set_horizontal_scroll_mode(ScrollMode p_mode);
107 ScrollMode get_horizontal_scroll_mode() const;
108
109 void set_vertical_scroll_mode(ScrollMode p_mode);
110 ScrollMode get_vertical_scroll_mode() const;
111
112 int get_deadzone() const;
113 void set_deadzone(int p_deadzone);
114
115 bool is_following_focus() const;
116 void set_follow_focus(bool p_follow);
117
118 HScrollBar *get_h_scroll_bar();
119 VScrollBar *get_v_scroll_bar();
120 void ensure_control_visible(Control *p_control);
121
122 PackedStringArray get_configuration_warnings() const override;
123
124 ScrollContainer();
125};
126
127VARIANT_ENUM_CAST(ScrollContainer::ScrollMode);
128
129#endif // SCROLL_CONTAINER_H
130