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#ifndef FLOW_CONTAINER_H
32#define FLOW_CONTAINER_H
33
34#include "scene/gui/container.h"
35
36class FlowContainer : public Container {
37 GDCLASS(FlowContainer, Container);
38
39public:
40 enum AlignmentMode {
41 ALIGNMENT_BEGIN,
42 ALIGNMENT_CENTER,
43 ALIGNMENT_END
44 };
45
46private:
47 int cached_size = 0;
48 int cached_line_count = 0;
49
50 bool vertical = false;
51 AlignmentMode alignment = ALIGNMENT_BEGIN;
52
53 struct ThemeCache {
54 int h_separation = 0;
55 int v_separation = 0;
56 } theme_cache;
57
58 void _resort();
59
60protected:
61 bool is_fixed = false;
62
63 void _notification(int p_what);
64 void _validate_property(PropertyInfo &p_property) const;
65 static void _bind_methods();
66
67public:
68 int get_line_count() const;
69
70 void set_alignment(AlignmentMode p_alignment);
71 AlignmentMode get_alignment() const;
72
73 void set_vertical(bool p_vertical);
74 bool is_vertical() const;
75
76 virtual Size2 get_minimum_size() const override;
77
78 virtual Vector<int> get_allowed_size_flags_horizontal() const override;
79 virtual Vector<int> get_allowed_size_flags_vertical() const override;
80
81 FlowContainer(bool p_vertical = false);
82};
83
84class HFlowContainer : public FlowContainer {
85 GDCLASS(HFlowContainer, FlowContainer);
86
87public:
88 HFlowContainer() :
89 FlowContainer(false) { is_fixed = true; }
90};
91
92class VFlowContainer : public FlowContainer {
93 GDCLASS(VFlowContainer, FlowContainer);
94
95public:
96 VFlowContainer() :
97 FlowContainer(true) { is_fixed = true; }
98};
99
100VARIANT_ENUM_CAST(FlowContainer::AlignmentMode);
101
102#endif // FLOW_CONTAINER_H
103