Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/gui/button.h
9903 views
1
/**************************************************************************/
2
/* button.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/base_button.h"
34
#include "scene/resources/text_paragraph.h"
35
36
class Button : public BaseButton {
37
GDCLASS(Button, BaseButton);
38
39
private:
40
bool flat = false;
41
String text;
42
String xl_text;
43
Ref<TextParagraph> text_buf;
44
45
String language;
46
TextDirection text_direction = TEXT_DIRECTION_AUTO;
47
TextServer::AutowrapMode autowrap_mode = TextServer::AUTOWRAP_OFF;
48
BitField<TextServer::LineBreakFlag> autowrap_flags_trim = TextServer::BREAK_TRIM_END_EDGE_SPACES;
49
TextServer::OverrunBehavior overrun_behavior = TextServer::OVERRUN_NO_TRIMMING;
50
51
Ref<Texture2D> icon;
52
bool expand_icon = false;
53
bool clip_text = false;
54
HorizontalAlignment alignment = HORIZONTAL_ALIGNMENT_CENTER;
55
HorizontalAlignment horizontal_icon_alignment = HORIZONTAL_ALIGNMENT_LEFT;
56
VerticalAlignment vertical_icon_alignment = VERTICAL_ALIGNMENT_CENTER;
57
float _internal_margin[4] = {};
58
59
struct ThemeCache {
60
Ref<StyleBox> normal;
61
Ref<StyleBox> normal_mirrored;
62
Ref<StyleBox> pressed;
63
Ref<StyleBox> pressed_mirrored;
64
Ref<StyleBox> hover;
65
Ref<StyleBox> hover_mirrored;
66
Ref<StyleBox> hover_pressed;
67
Ref<StyleBox> hover_pressed_mirrored;
68
Ref<StyleBox> disabled;
69
Ref<StyleBox> disabled_mirrored;
70
Ref<StyleBox> focus;
71
72
Size2 max_style_size;
73
float style_margin_left = 0;
74
float style_margin_right = 0;
75
float style_margin_top = 0;
76
float style_margin_bottom = 0;
77
78
bool align_to_largest_stylebox = false;
79
80
Color font_color;
81
Color font_focus_color;
82
Color font_pressed_color;
83
Color font_hover_color;
84
Color font_hover_pressed_color;
85
Color font_disabled_color;
86
87
Ref<Font> font;
88
int font_size = 0;
89
int outline_size = 0;
90
Color font_outline_color;
91
92
Color icon_normal_color;
93
Color icon_focus_color;
94
Color icon_pressed_color;
95
Color icon_hover_color;
96
Color icon_hover_pressed_color;
97
Color icon_disabled_color;
98
99
Ref<Texture2D> icon;
100
101
int h_separation = 0;
102
int icon_max_width = 0;
103
int line_spacing = 0;
104
} theme_cache;
105
106
void _shape(Ref<TextParagraph> p_paragraph = Ref<TextParagraph>(), String p_text = "") const;
107
void _texture_changed();
108
109
protected:
110
virtual void _update_theme_item_cache() override;
111
112
void _set_internal_margin(Side p_side, float p_value);
113
virtual void _queue_update_size_cache();
114
virtual String _get_translated_text(const String &p_text) const;
115
116
Size2 _fit_icon_size(const Size2 &p_size) const;
117
Ref<StyleBox> _get_current_stylebox() const;
118
Size2 _get_largest_stylebox_size() const;
119
void _notification(int p_what);
120
static void _bind_methods();
121
122
public:
123
virtual Size2 get_minimum_size() const override;
124
125
Size2 get_minimum_size_for_text_and_icon(const String &p_text, Ref<Texture2D> p_icon) const;
126
127
void set_text(const String &p_text);
128
String get_text() const;
129
130
void set_text_overrun_behavior(TextServer::OverrunBehavior p_behavior);
131
TextServer::OverrunBehavior get_text_overrun_behavior() const;
132
133
void set_autowrap_mode(TextServer::AutowrapMode p_mode);
134
TextServer::AutowrapMode get_autowrap_mode() const;
135
136
void set_autowrap_trim_flags(BitField<TextServer::LineBreakFlag> p_flags);
137
BitField<TextServer::LineBreakFlag> get_autowrap_trim_flags() const;
138
139
void set_text_direction(TextDirection p_text_direction);
140
TextDirection get_text_direction() const;
141
142
void set_language(const String &p_language);
143
String get_language() const;
144
145
void set_button_icon(const Ref<Texture2D> &p_icon);
146
Ref<Texture2D> get_button_icon() const;
147
148
void set_expand_icon(bool p_enabled);
149
bool is_expand_icon() const;
150
151
void set_flat(bool p_enabled);
152
bool is_flat() const;
153
154
void set_clip_text(bool p_enabled);
155
bool get_clip_text() const;
156
157
void set_text_alignment(HorizontalAlignment p_alignment);
158
HorizontalAlignment get_text_alignment() const;
159
160
void set_icon_alignment(HorizontalAlignment p_alignment);
161
void set_vertical_icon_alignment(VerticalAlignment p_alignment);
162
HorizontalAlignment get_icon_alignment() const;
163
VerticalAlignment get_vertical_icon_alignment() const;
164
165
Button(const String &p_text = String());
166
~Button();
167
};
168
169