Debian Codegraph @

scene/gui/foldable_container.h

raw symbols SCIP
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 Rect2 _get_title_rect() const;
93 int _get_h_separation() const { return MAX(theme_cache.h_separation, 0); }
94 real_t _get_title_controls_width() const;
95
96 void _update_title_min_size() const;
97 void _shape();
98 HorizontalAlignment _get_actual_alignment() const;
99 void _update_group();
100 void _draw_flippable_stylebox(const Ref<StyleBox> p_stylebox, const Rect2 &p_rect);
101
102 protected:
103 virtual void gui_input(const Ref<InputEvent> &p_event) override;
104 virtual String get_tooltip(const Point2 &p_pos) const override;
105 virtual bool has_point(const Point2 &p_point) const override;
106 void _notification(int p_what);
107 static void _bind_methods();
108
109 public:
110 void fold();
111 void expand();
112
113 void set_folded(bool p_folded);
114 bool is_folded() const;
115
116 void set_foldable_group(const Ref<FoldableGroup> &p_group);
117 Ref<FoldableGroup> get_foldable_group() const;
118
119 void set_title(const String &p_text);
120 String get_title() const;
121
122 void set_title_alignment(HorizontalAlignment p_alignment);
123 HorizontalAlignment get_title_alignment() const;
124
125 void set_title_text_direction(TextDirection p_text_direction);
126 TextDirection get_title_text_direction() const;
127
128 void set_title_text_overrun_behavior(TextServer::OverrunBehavior p_overrun_behavior);
129 TextServer::OverrunBehavior get_title_text_overrun_behavior() const;
130
131 void set_language(const String &p_language);
132 String get_language() const;
133
134 void set_title_position(TitlePosition p_title_position);
135 TitlePosition get_title_position() const;
136
137 void add_title_bar_control(Control *p_control);
138 void remove_title_bar_control(Control *p_control);
139
140 virtual Size2 get_minimum_size() const override;
141
142 virtual Vector<int> get_allowed_size_flags_horizontal() const override { return { SIZE_FILL, SIZE_SHRINK_BEGIN, SIZE_SHRINK_CENTER, SIZE_SHRINK_END }; }
143 virtual Vector<int> get_allowed_size_flags_vertical() const override { return { SIZE_FILL, SIZE_SHRINK_BEGIN, SIZE_SHRINK_CENTER, SIZE_SHRINK_END }; }
144
145 FoldableContainer(const String &p_text = String());
146 ~FoldableContainer();
147 };
148
149 VARIANT_ENUM_CAST(FoldableContainer::TitlePosition);
150
151 class FoldableGroup : public Resource {
152 GDCLASS(FoldableGroup, Resource);
153
154 friend class FoldableContainer;
155
156 HashSet<FoldableContainer *> containers;
157 bool allow_folding_all = false;
158 bool updating_group = false;
159
160 protected:
161 static void _bind_methods();
162
163 public:
164 FoldableContainer *get_expanded_container() const;
165
166 void get_containers(List<FoldableContainer *> *r_containers) const;
167 TypedArray<FoldableContainer> _get_containers() const;
168
169 void set_allow_folding_all(bool p_enabled);
170 bool is_allow_folding_all() const;
171
172 FoldableGroup();
173 };