Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/gui/foldable_container.h
9902 views
1
/**************************************************************************/
2
/* foldable_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 "scene/gui/container.h"
34
35
class FoldableGroup;
36
class TextLine;
37
38
class FoldableContainer : public Container {
39
GDCLASS(FoldableContainer, Container);
40
41
public:
42
enum TitlePosition {
43
POSITION_TOP,
44
POSITION_BOTTOM,
45
POSITION_MAX
46
};
47
48
private:
49
bool folded = false;
50
String title;
51
Ref<FoldableGroup> foldable_group;
52
String language;
53
TextDirection title_text_direction = TEXT_DIRECTION_AUTO;
54
HorizontalAlignment title_alignment = HORIZONTAL_ALIGNMENT_LEFT;
55
TextServer::OverrunBehavior overrun_behavior = TextServer::OVERRUN_NO_TRIMMING;
56
TitlePosition title_position = POSITION_TOP;
57
58
Ref<TextLine> text_buf;
59
bool changing_group = false;
60
bool is_hovering = false;
61
mutable Vector2 title_minimum_size;
62
63
LocalVector<Control *> title_controls;
64
65
struct ThemeCache {
66
Ref<StyleBox> title_style;
67
Ref<StyleBox> title_hover_style;
68
Ref<StyleBox> title_collapsed_style;
69
Ref<StyleBox> title_collapsed_hover_style;
70
Ref<StyleBox> panel_style;
71
Ref<StyleBox> focus_style;
72
73
Color title_font_color;
74
Color title_hovered_font_color;
75
Color title_collapsed_font_color;
76
Color title_font_outline_color;
77
78
Ref<Font> title_font;
79
int title_font_size = 0;
80
int title_font_outline_size = 0;
81
82
Ref<Texture2D> expanded_arrow;
83
Ref<Texture2D> expanded_arrow_mirrored;
84
Ref<Texture2D> folded_arrow;
85
Ref<Texture2D> folded_arrow_mirrored;
86
87
int h_separation = 0;
88
} theme_cache;
89
90
Ref<StyleBox> _get_title_style() const;
91
Ref<Texture2D> _get_title_icon() const;
92
int _get_h_separation() const { return MAX(theme_cache.h_separation, 0); }
93
real_t _get_title_controls_width() const;
94
95
void _update_title_min_size() const;
96
void _shape();
97
HorizontalAlignment _get_actual_alignment() const;
98
void _update_group();
99
void _draw_flippable_stylebox(const Ref<StyleBox> p_stylebox, const Rect2 &p_rect);
100
101
protected:
102
virtual void gui_input(const Ref<InputEvent> &p_event) override;
103
virtual String get_tooltip(const Point2 &p_pos) const override;
104
void _notification(int p_what);
105
static void _bind_methods();
106
107
public:
108
void fold();
109
void expand();
110
111
void set_folded(bool p_folded);
112
bool is_folded() const;
113
114
void set_foldable_group(const Ref<FoldableGroup> &p_group);
115
Ref<FoldableGroup> get_foldable_group() const;
116
117
void set_title(const String &p_text);
118
String get_title() const;
119
120
void set_title_alignment(HorizontalAlignment p_alignment);
121
HorizontalAlignment get_title_alignment() const;
122
123
void set_title_text_direction(TextDirection p_text_direction);
124
TextDirection get_title_text_direction() const;
125
126
void set_title_text_overrun_behavior(TextServer::OverrunBehavior p_overrun_behavior);
127
TextServer::OverrunBehavior get_title_text_overrun_behavior() const;
128
129
void set_language(const String &p_language);
130
String get_language() const;
131
132
void set_title_position(TitlePosition p_title_position);
133
TitlePosition get_title_position() const;
134
135
void add_title_bar_control(Control *p_control);
136
void remove_title_bar_control(Control *p_control);
137
138
virtual Size2 get_minimum_size() const override;
139
140
virtual Vector<int> get_allowed_size_flags_horizontal() const override { return { SIZE_FILL, SIZE_SHRINK_BEGIN, SIZE_SHRINK_CENTER, SIZE_SHRINK_END }; }
141
virtual Vector<int> get_allowed_size_flags_vertical() const override { return { SIZE_FILL, SIZE_SHRINK_BEGIN, SIZE_SHRINK_CENTER, SIZE_SHRINK_END }; }
142
143
FoldableContainer(const String &p_text = String());
144
~FoldableContainer();
145
};
146
147
VARIANT_ENUM_CAST(FoldableContainer::TitlePosition);
148
149
class FoldableGroup : public Resource {
150
GDCLASS(FoldableGroup, Resource);
151
152
friend class FoldableContainer;
153
154
HashSet<FoldableContainer *> containers;
155
bool allow_folding_all = false;
156
bool updating_group = false;
157
158
protected:
159
static void _bind_methods();
160
161
public:
162
FoldableContainer *get_expanded_container() const;
163
164
void get_containers(List<FoldableContainer *> *r_containers) const;
165
TypedArray<FoldableContainer> _get_containers() const;
166
167
void set_allow_folding_all(bool p_enabled);
168
bool is_allow_folding_all() const;
169
170
FoldableGroup();
171
};
172
173