Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/gui/flow_container.h
9902 views
1
/**************************************************************************/
2
/* flow_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 FlowContainer : public Container {
36
GDCLASS(FlowContainer, Container);
37
38
public:
39
enum AlignmentMode {
40
ALIGNMENT_BEGIN,
41
ALIGNMENT_CENTER,
42
ALIGNMENT_END
43
};
44
enum LastWrapAlignmentMode {
45
LAST_WRAP_ALIGNMENT_INHERIT,
46
LAST_WRAP_ALIGNMENT_BEGIN,
47
LAST_WRAP_ALIGNMENT_CENTER,
48
LAST_WRAP_ALIGNMENT_END
49
};
50
51
private:
52
int cached_size = 0;
53
int cached_line_count = 0;
54
int cached_line_max_child_count = 0;
55
int cached_items_on_last_row = 0;
56
57
bool vertical = false;
58
bool reverse_fill = false;
59
AlignmentMode alignment = ALIGNMENT_BEGIN;
60
LastWrapAlignmentMode last_wrap_alignment = LAST_WRAP_ALIGNMENT_INHERIT;
61
62
struct ThemeCache {
63
int h_separation = 0;
64
int v_separation = 0;
65
} theme_cache;
66
67
void _resort();
68
69
protected:
70
bool is_fixed = false;
71
72
void _notification(int p_what);
73
void _validate_property(PropertyInfo &p_property) const;
74
static void _bind_methods();
75
76
public:
77
int get_line_count() const;
78
int get_line_max_child_count() const;
79
80
void set_alignment(AlignmentMode p_alignment);
81
AlignmentMode get_alignment() const;
82
83
void set_last_wrap_alignment(LastWrapAlignmentMode p_last_wrap_alignment);
84
LastWrapAlignmentMode get_last_wrap_alignment() const;
85
86
void set_vertical(bool p_vertical);
87
bool is_vertical() const;
88
89
void set_reverse_fill(bool p_reverse_fill);
90
bool is_reverse_fill() const;
91
92
virtual Size2 get_minimum_size() const override;
93
94
virtual Vector<int> get_allowed_size_flags_horizontal() const override;
95
virtual Vector<int> get_allowed_size_flags_vertical() const override;
96
97
FlowContainer(bool p_vertical = false);
98
};
99
100
class HFlowContainer : public FlowContainer {
101
GDCLASS(HFlowContainer, FlowContainer);
102
103
public:
104
HFlowContainer() :
105
FlowContainer(false) { is_fixed = true; }
106
};
107
108
class VFlowContainer : public FlowContainer {
109
GDCLASS(VFlowContainer, FlowContainer);
110
111
public:
112
VFlowContainer() :
113
FlowContainer(true) { is_fixed = true; }
114
};
115
116
VARIANT_ENUM_CAST(FlowContainer::AlignmentMode);
117
VARIANT_ENUM_CAST(FlowContainer::LastWrapAlignmentMode);
118
119