| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 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 |
void _update_style_margins(const Ref<StyleBox> &p_stylebox); |
| 109 |
|
| 110 |
protected: |
| 111 |
virtual void _update_theme_item_cache() override; |
| 112 |
|
| 113 |
void _set_internal_margin(Side p_side, float p_value); |
| 114 |
virtual void _queue_update_size_cache(); |
| 115 |
virtual String _get_translated_text(const String &p_text) const; |
| 116 |
|
| 117 |
Size2 _fit_icon_size(const Size2 &p_size) const; |
| 118 |
Ref<StyleBox> _get_current_stylebox() const; |
| 119 |
Size2 _get_largest_stylebox_size() const; |
| 120 |
void _notification(int p_what); |
| 121 |
static void _bind_methods(); |
| 122 |
|
| 123 |
public: |
| 124 |
virtual Size2 get_minimum_size() const override; |
| 125 |
|
| 126 |
Size2 get_minimum_size_for_text_and_icon(const String &p_text, Ref<Texture2D> p_icon) const; |
| 127 |
|
| 128 |
void set_text(const String &p_text); |
| 129 |
String get_text() const; |
| 130 |
|
| 131 |
void set_text_overrun_behavior(TextServer::OverrunBehavior p_behavior); |
| 132 |
TextServer::OverrunBehavior get_text_overrun_behavior() const; |
| 133 |
|
| 134 |
void set_autowrap_mode(TextServer::AutowrapMode p_mode); |
| 135 |
TextServer::AutowrapMode get_autowrap_mode() const; |
| 136 |
|
| 137 |
void set_autowrap_trim_flags(BitField<TextServer::LineBreakFlag> p_flags); |
| 138 |
BitField<TextServer::LineBreakFlag> get_autowrap_trim_flags() const; |
| 139 |
|
| 140 |
void set_text_direction(TextDirection p_text_direction); |
| 141 |
TextDirection get_text_direction() const; |
| 142 |
|
| 143 |
void set_language(const String &p_language); |
| 144 |
String get_language() const; |
| 145 |
|
| 146 |
void set_button_icon(const Ref<Texture2D> &p_icon); |
| 147 |
Ref<Texture2D> get_button_icon() const; |
| 148 |
|
| 149 |
void set_expand_icon(bool p_enabled); |
| 150 |
bool is_expand_icon() const; |
| 151 |
|
| 152 |
void set_flat(bool p_enabled); |
| 153 |
bool is_flat() const; |
| 154 |
|
| 155 |
void set_clip_text(bool p_enabled); |
| 156 |
bool get_clip_text() const; |
| 157 |
|
| 158 |
void set_text_alignment(HorizontalAlignment p_alignment); |
| 159 |
HorizontalAlignment get_text_alignment() const; |
| 160 |
|
| 161 |
void set_icon_alignment(HorizontalAlignment p_alignment); |
| 162 |
void set_vertical_icon_alignment(VerticalAlignment p_alignment); |
| 163 |
HorizontalAlignment get_icon_alignment() const; |
| 164 |
VerticalAlignment get_vertical_icon_alignment() const; |
| 165 |
|
| 166 |
Button(const String &p_text = String()); |
| 167 |
~Button(); |
| 168 |
}; |