2023-01-05 12:25:55 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* button.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "button.h"
|
2019-04-05 12:06:16 +00:00
|
|
|
|
2023-05-17 12:49:59 +00:00
|
|
|
#include "core/core_string_names.h"
|
2020-11-07 22:33:38 +00:00
|
|
|
#include "core/string/translation.h"
|
2020-03-27 18:21:27 +00:00
|
|
|
#include "servers/rendering_server.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Size2 Button::get_minimum_size() const {
|
2022-08-12 11:39:22 +00:00
|
|
|
Ref<Texture2D> _icon = icon;
|
|
|
|
if (_icon.is_null() && has_theme_icon(SNAME("icon"))) {
|
2022-08-31 12:02:40 +00:00
|
|
|
_icon = theme_cache.icon;
|
2022-05-07 22:25:35 +00:00
|
|
|
}
|
2021-02-22 13:54:12 +00:00
|
|
|
|
2022-03-19 01:15:55 +00:00
|
|
|
return get_minimum_size_for_text_and_icon("", _icon);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-22 16:24:29 +00:00
|
|
|
void Button::_set_internal_margin(Side p_side, float p_value) {
|
|
|
|
_internal_margin[p_side] = p_value;
|
2017-12-11 05:03:32 +00:00
|
|
|
}
|
|
|
|
|
2023-04-12 01:34:00 +00:00
|
|
|
void Button::_queue_update_size_cache() {
|
|
|
|
}
|
|
|
|
|
2022-08-31 12:02:40 +00:00
|
|
|
void Button::_update_theme_item_cache() {
|
|
|
|
BaseButton::_update_theme_item_cache();
|
|
|
|
|
|
|
|
theme_cache.normal = get_theme_stylebox(SNAME("normal"));
|
|
|
|
theme_cache.normal_mirrored = get_theme_stylebox(SNAME("normal_mirrored"));
|
|
|
|
theme_cache.pressed = get_theme_stylebox(SNAME("pressed"));
|
|
|
|
theme_cache.pressed_mirrored = get_theme_stylebox(SNAME("pressed_mirrored"));
|
|
|
|
theme_cache.hover = get_theme_stylebox(SNAME("hover"));
|
|
|
|
theme_cache.hover_mirrored = get_theme_stylebox(SNAME("hover_mirrored"));
|
|
|
|
theme_cache.hover_pressed = get_theme_stylebox(SNAME("hover_pressed"));
|
|
|
|
theme_cache.hover_pressed_mirrored = get_theme_stylebox(SNAME("hover_pressed_mirrored"));
|
|
|
|
theme_cache.disabled = get_theme_stylebox(SNAME("disabled"));
|
|
|
|
theme_cache.disabled_mirrored = get_theme_stylebox(SNAME("disabled_mirrored"));
|
|
|
|
theme_cache.focus = get_theme_stylebox(SNAME("focus"));
|
|
|
|
|
|
|
|
theme_cache.font_color = get_theme_color(SNAME("font_color"));
|
|
|
|
theme_cache.font_focus_color = get_theme_color(SNAME("font_focus_color"));
|
|
|
|
theme_cache.font_pressed_color = get_theme_color(SNAME("font_pressed_color"));
|
|
|
|
theme_cache.font_hover_color = get_theme_color(SNAME("font_hover_color"));
|
|
|
|
theme_cache.font_hover_pressed_color = get_theme_color(SNAME("font_hover_pressed_color"));
|
|
|
|
theme_cache.font_disabled_color = get_theme_color(SNAME("font_disabled_color"));
|
|
|
|
|
|
|
|
theme_cache.font = get_theme_font(SNAME("font"));
|
|
|
|
theme_cache.font_size = get_theme_font_size(SNAME("font_size"));
|
|
|
|
theme_cache.outline_size = get_theme_constant(SNAME("outline_size"));
|
|
|
|
theme_cache.font_outline_color = get_theme_color(SNAME("font_outline_color"));
|
|
|
|
|
|
|
|
theme_cache.icon_normal_color = get_theme_color(SNAME("icon_normal_color"));
|
|
|
|
theme_cache.icon_focus_color = get_theme_color(SNAME("icon_focus_color"));
|
|
|
|
theme_cache.icon_pressed_color = get_theme_color(SNAME("icon_pressed_color"));
|
|
|
|
theme_cache.icon_hover_color = get_theme_color(SNAME("icon_hover_color"));
|
|
|
|
theme_cache.icon_hover_pressed_color = get_theme_color(SNAME("icon_hover_pressed_color"));
|
|
|
|
theme_cache.icon_disabled_color = get_theme_color(SNAME("icon_disabled_color"));
|
|
|
|
|
|
|
|
theme_cache.icon = get_theme_icon(SNAME("icon"));
|
|
|
|
|
|
|
|
theme_cache.h_separation = get_theme_constant(SNAME("h_separation"));
|
2023-03-31 19:17:59 +00:00
|
|
|
theme_cache.icon_max_width = get_theme_constant(SNAME("icon_max_width"));
|
2022-08-31 12:02:40 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void Button::_notification(int p_what) {
|
2019-08-20 16:41:14 +00:00
|
|
|
switch (p_what) {
|
2020-09-03 11:22:16 +00:00
|
|
|
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2020-09-03 11:22:16 +00:00
|
|
|
} break;
|
2022-02-15 17:06:48 +00:00
|
|
|
|
2019-08-20 16:41:14 +00:00
|
|
|
case NOTIFICATION_TRANSLATION_CHANGED: {
|
2021-05-27 17:31:33 +00:00
|
|
|
xl_text = atr(text);
|
2020-09-03 11:22:16 +00:00
|
|
|
_shape();
|
|
|
|
|
2021-12-06 13:02:34 +00:00
|
|
|
update_minimum_size();
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2020-09-03 11:22:16 +00:00
|
|
|
} break;
|
2022-02-15 17:06:48 +00:00
|
|
|
|
2020-09-03 11:22:16 +00:00
|
|
|
case NOTIFICATION_THEME_CHANGED: {
|
|
|
|
_shape();
|
|
|
|
|
2021-12-06 13:02:34 +00:00
|
|
|
update_minimum_size();
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2019-08-20 16:41:14 +00:00
|
|
|
} break;
|
2022-02-15 17:06:48 +00:00
|
|
|
|
2019-08-20 16:41:14 +00:00
|
|
|
case NOTIFICATION_DRAW: {
|
|
|
|
RID ci = get_canvas_item();
|
|
|
|
Size2 size = get_size();
|
|
|
|
Color color;
|
|
|
|
Color color_icon(1, 1, 1, 1);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2022-08-31 12:02:40 +00:00
|
|
|
Ref<StyleBox> style = theme_cache.normal;
|
2020-09-03 11:22:16 +00:00
|
|
|
bool rtl = is_layout_rtl();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-08-20 16:41:14 +00:00
|
|
|
switch (get_draw_mode()) {
|
|
|
|
case DRAW_NORMAL: {
|
2021-07-17 21:22:52 +00:00
|
|
|
if (rtl && has_theme_stylebox(SNAME("normal_mirrored"))) {
|
2022-08-31 12:02:40 +00:00
|
|
|
style = theme_cache.normal_mirrored;
|
2020-09-03 11:22:16 +00:00
|
|
|
} else {
|
2022-08-31 12:02:40 +00:00
|
|
|
style = theme_cache.normal;
|
2020-09-03 11:22:16 +00:00
|
|
|
}
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!flat) {
|
2019-08-20 16:41:14 +00:00
|
|
|
style->draw(ci, Rect2(Point2(0, 0), size));
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2021-10-26 14:28:12 +00:00
|
|
|
|
|
|
|
// Focus colors only take precedence over normal state.
|
|
|
|
if (has_focus()) {
|
2022-08-31 12:02:40 +00:00
|
|
|
color = theme_cache.font_focus_color;
|
2021-10-26 14:28:12 +00:00
|
|
|
if (has_theme_color(SNAME("icon_focus_color"))) {
|
2022-08-31 12:02:40 +00:00
|
|
|
color_icon = theme_cache.icon_focus_color;
|
2021-10-26 14:28:12 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-08-31 12:02:40 +00:00
|
|
|
color = theme_cache.font_color;
|
2021-10-26 14:28:12 +00:00
|
|
|
if (has_theme_color(SNAME("icon_normal_color"))) {
|
2022-08-31 12:02:40 +00:00
|
|
|
color_icon = theme_cache.icon_normal_color;
|
2021-10-26 14:28:12 +00:00
|
|
|
}
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2019-08-20 16:41:14 +00:00
|
|
|
} break;
|
|
|
|
case DRAW_HOVER_PRESSED: {
|
2021-10-31 00:10:45 +00:00
|
|
|
// Edge case for CheckButton and CheckBox.
|
2022-02-08 09:14:58 +00:00
|
|
|
if (has_theme_stylebox("hover_pressed")) {
|
2021-07-17 21:22:52 +00:00
|
|
|
if (rtl && has_theme_stylebox(SNAME("hover_pressed_mirrored"))) {
|
2022-08-31 12:02:40 +00:00
|
|
|
style = theme_cache.hover_pressed_mirrored;
|
2020-09-03 11:22:16 +00:00
|
|
|
} else {
|
2022-08-31 12:02:40 +00:00
|
|
|
style = theme_cache.hover_pressed;
|
2020-09-03 11:22:16 +00:00
|
|
|
}
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!flat) {
|
2019-08-20 16:41:14 +00:00
|
|
|
style->draw(ci, Rect2(Point2(0, 0), size));
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2021-07-17 21:22:52 +00:00
|
|
|
if (has_theme_color(SNAME("font_hover_pressed_color"))) {
|
2022-08-31 12:02:40 +00:00
|
|
|
color = theme_cache.font_hover_pressed_color;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2021-07-17 21:22:52 +00:00
|
|
|
if (has_theme_color(SNAME("icon_hover_pressed_color"))) {
|
2022-08-31 12:02:40 +00:00
|
|
|
color_icon = theme_cache.icon_hover_pressed_color;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2019-08-20 16:41:14 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2020-02-22 19:47:50 +00:00
|
|
|
[[fallthrough]];
|
2019-08-20 16:41:14 +00:00
|
|
|
}
|
|
|
|
case DRAW_PRESSED: {
|
2021-07-17 21:22:52 +00:00
|
|
|
if (rtl && has_theme_stylebox(SNAME("pressed_mirrored"))) {
|
2022-08-31 12:02:40 +00:00
|
|
|
style = theme_cache.pressed_mirrored;
|
2020-09-03 11:22:16 +00:00
|
|
|
} else {
|
2022-08-31 12:02:40 +00:00
|
|
|
style = theme_cache.pressed;
|
2020-09-03 11:22:16 +00:00
|
|
|
}
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!flat) {
|
2018-09-23 23:56:30 +00:00
|
|
|
style->draw(ci, Rect2(Point2(0, 0), size));
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2021-07-17 21:22:52 +00:00
|
|
|
if (has_theme_color(SNAME("font_pressed_color"))) {
|
2022-08-31 12:02:40 +00:00
|
|
|
color = theme_cache.font_pressed_color;
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2022-08-31 12:02:40 +00:00
|
|
|
color = theme_cache.font_color;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2021-07-17 21:22:52 +00:00
|
|
|
if (has_theme_color(SNAME("icon_pressed_color"))) {
|
2022-08-31 12:02:40 +00:00
|
|
|
color_icon = theme_cache.icon_pressed_color;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-09-23 23:56:30 +00:00
|
|
|
|
2019-08-20 16:41:14 +00:00
|
|
|
} break;
|
|
|
|
case DRAW_HOVER: {
|
2021-07-17 21:22:52 +00:00
|
|
|
if (rtl && has_theme_stylebox(SNAME("hover_mirrored"))) {
|
2022-08-31 12:02:40 +00:00
|
|
|
style = theme_cache.hover_mirrored;
|
2020-09-03 11:22:16 +00:00
|
|
|
} else {
|
2022-08-31 12:02:40 +00:00
|
|
|
style = theme_cache.hover;
|
2020-09-03 11:22:16 +00:00
|
|
|
}
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!flat) {
|
2019-08-20 16:41:14 +00:00
|
|
|
style->draw(ci, Rect2(Point2(0, 0), size));
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2022-08-31 12:02:40 +00:00
|
|
|
color = theme_cache.font_hover_color;
|
2021-07-17 21:22:52 +00:00
|
|
|
if (has_theme_color(SNAME("icon_hover_color"))) {
|
2022-08-31 12:02:40 +00:00
|
|
|
color_icon = theme_cache.icon_hover_color;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2019-08-20 16:41:14 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case DRAW_DISABLED: {
|
2021-07-17 21:22:52 +00:00
|
|
|
if (rtl && has_theme_stylebox(SNAME("disabled_mirrored"))) {
|
2022-08-31 12:02:40 +00:00
|
|
|
style = theme_cache.disabled_mirrored;
|
2020-09-03 11:22:16 +00:00
|
|
|
} else {
|
2022-08-31 12:02:40 +00:00
|
|
|
style = theme_cache.disabled;
|
2020-09-03 11:22:16 +00:00
|
|
|
}
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!flat) {
|
2019-08-20 16:41:14 +00:00
|
|
|
style->draw(ci, Rect2(Point2(0, 0), size));
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2022-08-31 12:02:40 +00:00
|
|
|
color = theme_cache.font_disabled_color;
|
2021-07-17 21:22:52 +00:00
|
|
|
if (has_theme_color(SNAME("icon_disabled_color"))) {
|
2022-08-31 12:02:40 +00:00
|
|
|
color_icon = theme_cache.icon_disabled_color;
|
2022-01-30 19:25:42 +00:00
|
|
|
} else {
|
|
|
|
color_icon.a = 0.4;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2019-08-20 16:41:14 +00:00
|
|
|
|
|
|
|
} break;
|
2018-09-23 23:56:30 +00:00
|
|
|
}
|
2015-06-08 13:36:11 +00:00
|
|
|
|
2019-08-20 16:41:14 +00:00
|
|
|
if (has_focus()) {
|
2022-08-31 12:02:40 +00:00
|
|
|
Ref<StyleBox> style2 = theme_cache.focus;
|
2019-08-20 16:41:14 +00:00
|
|
|
style2->draw(ci, Rect2(Point2(), size));
|
|
|
|
}
|
2015-06-08 13:36:11 +00:00
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
Ref<Texture2D> _icon;
|
2021-07-17 21:22:52 +00:00
|
|
|
if (icon.is_null() && has_theme_icon(SNAME("icon"))) {
|
2022-08-31 12:02:40 +00:00
|
|
|
_icon = theme_cache.icon;
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2019-08-20 16:41:14 +00:00
|
|
|
_icon = icon;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2022-11-14 17:21:06 +00:00
|
|
|
Rect2 icon_region;
|
2023-03-03 20:21:41 +00:00
|
|
|
HorizontalAlignment icon_align_rtl_checked = horizontal_icon_alignment;
|
2021-11-25 02:58:47 +00:00
|
|
|
HorizontalAlignment align_rtl_checked = alignment;
|
2019-10-25 03:29:10 +00:00
|
|
|
// Swap icon and text alignment sides if right-to-left layout is set.
|
|
|
|
if (rtl) {
|
2023-03-03 20:21:41 +00:00
|
|
|
if (horizontal_icon_alignment == HORIZONTAL_ALIGNMENT_RIGHT) {
|
2021-11-25 02:58:47 +00:00
|
|
|
icon_align_rtl_checked = HORIZONTAL_ALIGNMENT_LEFT;
|
2023-03-03 20:21:41 +00:00
|
|
|
} else if (horizontal_icon_alignment == HORIZONTAL_ALIGNMENT_LEFT) {
|
2021-11-25 02:58:47 +00:00
|
|
|
icon_align_rtl_checked = HORIZONTAL_ALIGNMENT_RIGHT;
|
2019-10-25 03:29:10 +00:00
|
|
|
}
|
2021-11-25 02:58:47 +00:00
|
|
|
if (alignment == HORIZONTAL_ALIGNMENT_RIGHT) {
|
|
|
|
align_rtl_checked = HORIZONTAL_ALIGNMENT_LEFT;
|
|
|
|
} else if (alignment == HORIZONTAL_ALIGNMENT_LEFT) {
|
|
|
|
align_rtl_checked = HORIZONTAL_ALIGNMENT_RIGHT;
|
2019-10-25 03:29:10 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-20 16:41:14 +00:00
|
|
|
if (!_icon.is_null()) {
|
|
|
|
int valign = size.height - style->get_minimum_size().y;
|
|
|
|
|
2023-03-03 20:21:41 +00:00
|
|
|
int voffset = 0;
|
|
|
|
Size2 icon_size = _icon->get_size();
|
|
|
|
|
|
|
|
// Fix vertical size.
|
|
|
|
if (vertical_icon_alignment != VERTICAL_ALIGNMENT_CENTER) {
|
|
|
|
valign -= text_buf->get_size().height;
|
|
|
|
}
|
|
|
|
|
2021-02-09 17:24:36 +00:00
|
|
|
float icon_ofs_region = 0.0;
|
2019-10-25 03:29:10 +00:00
|
|
|
Point2 style_offset;
|
2021-11-25 02:58:47 +00:00
|
|
|
if (icon_align_rtl_checked == HORIZONTAL_ALIGNMENT_LEFT) {
|
2019-10-25 03:29:10 +00:00
|
|
|
style_offset.x = style->get_margin(SIDE_LEFT);
|
2020-12-22 16:24:29 +00:00
|
|
|
if (_internal_margin[SIDE_LEFT] > 0) {
|
2022-08-31 12:02:40 +00:00
|
|
|
icon_ofs_region = _internal_margin[SIDE_LEFT] + theme_cache.h_separation;
|
2020-09-03 11:22:16 +00:00
|
|
|
}
|
2021-11-25 02:58:47 +00:00
|
|
|
} else if (icon_align_rtl_checked == HORIZONTAL_ALIGNMENT_CENTER) {
|
2019-10-25 03:29:10 +00:00
|
|
|
style_offset.x = 0.0;
|
2021-11-25 02:58:47 +00:00
|
|
|
} else if (icon_align_rtl_checked == HORIZONTAL_ALIGNMENT_RIGHT) {
|
2019-10-25 03:29:10 +00:00
|
|
|
style_offset.x = -style->get_margin(SIDE_RIGHT);
|
|
|
|
if (_internal_margin[SIDE_RIGHT] > 0) {
|
2022-08-31 12:02:40 +00:00
|
|
|
icon_ofs_region = -_internal_margin[SIDE_RIGHT] - theme_cache.h_separation;
|
2019-10-25 03:29:10 +00:00
|
|
|
}
|
2019-08-29 02:12:22 +00:00
|
|
|
}
|
2019-10-25 03:29:10 +00:00
|
|
|
style_offset.y = style->get_margin(SIDE_TOP);
|
2019-08-20 16:41:14 +00:00
|
|
|
|
|
|
|
if (expand_icon) {
|
|
|
|
Size2 _size = get_size() - style->get_offset() * 2;
|
2022-08-31 12:02:40 +00:00
|
|
|
int icon_text_separation = text.is_empty() ? 0 : theme_cache.h_separation;
|
2022-05-10 20:27:48 +00:00
|
|
|
_size.width -= icon_text_separation + icon_ofs_region;
|
2021-11-25 02:58:47 +00:00
|
|
|
if (!clip_text && icon_align_rtl_checked != HORIZONTAL_ALIGNMENT_CENTER) {
|
2020-09-03 11:22:16 +00:00
|
|
|
_size.width -= text_buf->get_size().width;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2023-03-03 20:21:41 +00:00
|
|
|
if (vertical_icon_alignment != VERTICAL_ALIGNMENT_CENTER) {
|
|
|
|
_size.height -= text_buf->get_size().height;
|
|
|
|
}
|
2019-11-09 19:14:52 +00:00
|
|
|
float icon_width = _icon->get_width() * _size.height / _icon->get_height();
|
2019-08-20 16:41:14 +00:00
|
|
|
float icon_height = _size.height;
|
|
|
|
|
|
|
|
if (icon_width > _size.width) {
|
|
|
|
icon_width = _size.width;
|
2019-11-09 22:06:46 +00:00
|
|
|
icon_height = _icon->get_height() * icon_width / _icon->get_width();
|
2019-08-20 16:41:14 +00:00
|
|
|
}
|
|
|
|
|
2019-10-25 03:29:10 +00:00
|
|
|
icon_size = Size2(icon_width, icon_height);
|
|
|
|
}
|
2023-03-31 19:17:59 +00:00
|
|
|
icon_size = _fit_icon_size(icon_size);
|
2019-10-25 03:29:10 +00:00
|
|
|
|
2023-03-03 20:21:41 +00:00
|
|
|
if (vertical_icon_alignment == VERTICAL_ALIGNMENT_TOP) {
|
|
|
|
voffset = -(valign - icon_size.y) / 2;
|
|
|
|
}
|
|
|
|
if (vertical_icon_alignment == VERTICAL_ALIGNMENT_BOTTOM) {
|
|
|
|
voffset = (valign - icon_size.y) / 2 + text_buf->get_size().y;
|
|
|
|
}
|
|
|
|
|
2021-11-25 02:58:47 +00:00
|
|
|
if (icon_align_rtl_checked == HORIZONTAL_ALIGNMENT_LEFT) {
|
2023-03-03 20:21:41 +00:00
|
|
|
icon_region = Rect2(style_offset + Point2(icon_ofs_region, voffset + Math::floor((valign - icon_size.y) * 0.5)), icon_size);
|
2021-11-25 02:58:47 +00:00
|
|
|
} else if (icon_align_rtl_checked == HORIZONTAL_ALIGNMENT_CENTER) {
|
2023-03-03 20:21:41 +00:00
|
|
|
icon_region = Rect2(style_offset + Point2(icon_ofs_region + Math::floor((size.x - icon_size.x) * 0.5), voffset + Math::floor((valign - icon_size.y) * 0.5)), icon_size);
|
2017-12-11 06:37:29 +00:00
|
|
|
} else {
|
2023-03-03 20:21:41 +00:00
|
|
|
icon_region = Rect2(style_offset + Point2(icon_ofs_region + size.x - icon_size.x, voffset + Math::floor((valign - icon_size.y) * 0.5)), icon_size);
|
2019-10-25 03:29:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (icon_region.size.width > 0) {
|
2022-08-04 21:12:48 +00:00
|
|
|
Rect2 icon_region_rounded = Rect2(icon_region.position.round(), icon_region.size.round());
|
|
|
|
draw_texture_rect(_icon, icon_region_rounded, false, color_icon);
|
2017-12-11 06:37:29 +00:00
|
|
|
}
|
2019-08-20 16:41:14 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2022-08-31 12:02:40 +00:00
|
|
|
Point2 icon_ofs = !_icon.is_null() ? Point2(icon_region.size.width + theme_cache.h_separation, 0) : Point2();
|
2021-11-25 02:58:47 +00:00
|
|
|
if (align_rtl_checked == HORIZONTAL_ALIGNMENT_CENTER && icon_align_rtl_checked == HORIZONTAL_ALIGNMENT_CENTER) {
|
2019-10-25 03:29:10 +00:00
|
|
|
icon_ofs.x = 0.0;
|
|
|
|
}
|
2019-08-20 16:41:14 +00:00
|
|
|
int text_clip = size.width - style->get_minimum_size().width - icon_ofs.width;
|
2022-06-15 08:01:45 +00:00
|
|
|
text_buf->set_width((clip_text || overrun_behavior != TextServer::OVERRUN_NO_TRIMMING) ? text_clip : -1);
|
2020-09-03 11:22:16 +00:00
|
|
|
|
2022-06-15 08:01:45 +00:00
|
|
|
int text_width = MAX(1, (clip_text || overrun_behavior != TextServer::OVERRUN_NO_TRIMMING) ? MIN(text_clip, text_buf->get_size().x) : text_buf->get_size().x);
|
2020-09-03 11:22:16 +00:00
|
|
|
|
2020-12-22 16:24:29 +00:00
|
|
|
if (_internal_margin[SIDE_LEFT] > 0) {
|
2022-08-31 12:02:40 +00:00
|
|
|
text_clip -= _internal_margin[SIDE_LEFT] + theme_cache.h_separation;
|
2019-12-12 21:46:04 +00:00
|
|
|
}
|
2020-12-22 16:24:29 +00:00
|
|
|
if (_internal_margin[SIDE_RIGHT] > 0) {
|
2022-08-31 12:02:40 +00:00
|
|
|
text_clip -= _internal_margin[SIDE_RIGHT] + theme_cache.h_separation;
|
2019-12-12 21:46:04 +00:00
|
|
|
}
|
|
|
|
|
2020-12-22 16:24:29 +00:00
|
|
|
Point2 text_ofs = (size - style->get_minimum_size() - icon_ofs - text_buf->get_size() - Point2(_internal_margin[SIDE_RIGHT] - _internal_margin[SIDE_LEFT], 0)) / 2.0;
|
2019-08-20 16:41:14 +00:00
|
|
|
|
2023-03-03 20:21:41 +00:00
|
|
|
if (vertical_icon_alignment == VERTICAL_ALIGNMENT_TOP) {
|
|
|
|
text_ofs.y += icon_region.size.height / 2;
|
|
|
|
}
|
|
|
|
if (vertical_icon_alignment == VERTICAL_ALIGNMENT_BOTTOM) {
|
|
|
|
text_ofs.y -= icon_region.size.height / 2;
|
|
|
|
}
|
|
|
|
|
2022-01-09 19:25:28 +00:00
|
|
|
text_buf->set_alignment(align_rtl_checked);
|
|
|
|
text_buf->set_width(text_width);
|
2019-10-25 03:29:10 +00:00
|
|
|
switch (align_rtl_checked) {
|
2021-11-25 02:58:47 +00:00
|
|
|
case HORIZONTAL_ALIGNMENT_FILL:
|
|
|
|
case HORIZONTAL_ALIGNMENT_LEFT: {
|
|
|
|
if (icon_align_rtl_checked != HORIZONTAL_ALIGNMENT_LEFT) {
|
2019-10-25 03:29:10 +00:00
|
|
|
icon_ofs.x = 0.0;
|
|
|
|
}
|
|
|
|
if (_internal_margin[SIDE_LEFT] > 0) {
|
2022-08-31 12:02:40 +00:00
|
|
|
text_ofs.x = style->get_margin(SIDE_LEFT) + icon_ofs.x + _internal_margin[SIDE_LEFT] + theme_cache.h_separation;
|
2019-08-20 16:41:14 +00:00
|
|
|
} else {
|
2019-10-25 03:29:10 +00:00
|
|
|
text_ofs.x = style->get_margin(SIDE_LEFT) + icon_ofs.x;
|
2019-08-20 16:41:14 +00:00
|
|
|
}
|
|
|
|
text_ofs.y += style->get_offset().y;
|
|
|
|
} break;
|
2021-11-25 02:58:47 +00:00
|
|
|
case HORIZONTAL_ALIGNMENT_CENTER: {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (text_ofs.x < 0) {
|
2019-08-20 16:41:14 +00:00
|
|
|
text_ofs.x = 0;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2021-11-25 02:58:47 +00:00
|
|
|
if (icon_align_rtl_checked == HORIZONTAL_ALIGNMENT_LEFT) {
|
2019-10-25 03:29:10 +00:00
|
|
|
text_ofs += icon_ofs;
|
|
|
|
}
|
2019-08-20 16:41:14 +00:00
|
|
|
text_ofs += style->get_offset();
|
|
|
|
} break;
|
2021-11-25 02:58:47 +00:00
|
|
|
case HORIZONTAL_ALIGNMENT_RIGHT: {
|
2019-10-25 03:29:10 +00:00
|
|
|
if (_internal_margin[SIDE_RIGHT] > 0) {
|
2022-08-31 12:02:40 +00:00
|
|
|
text_ofs.x = size.x - style->get_margin(SIDE_RIGHT) - text_width - _internal_margin[SIDE_RIGHT] - theme_cache.h_separation;
|
2019-08-20 16:41:14 +00:00
|
|
|
} else {
|
2019-10-25 03:29:10 +00:00
|
|
|
text_ofs.x = size.x - style->get_margin(SIDE_RIGHT) - text_width;
|
2019-08-20 16:41:14 +00:00
|
|
|
}
|
|
|
|
text_ofs.y += style->get_offset().y;
|
2021-11-25 02:58:47 +00:00
|
|
|
if (icon_align_rtl_checked == HORIZONTAL_ALIGNMENT_RIGHT) {
|
2019-10-25 03:29:10 +00:00
|
|
|
text_ofs.x -= icon_ofs.x;
|
|
|
|
}
|
2019-08-20 16:41:14 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
2022-08-31 12:02:40 +00:00
|
|
|
Color font_outline_color = theme_cache.font_outline_color;
|
|
|
|
int outline_size = theme_cache.outline_size;
|
2022-07-08 05:27:18 +00:00
|
|
|
if (outline_size > 0 && font_outline_color.a > 0) {
|
|
|
|
text_buf->draw_outline(ci, text_ofs, outline_size, font_outline_color);
|
|
|
|
}
|
2021-01-19 08:50:43 +00:00
|
|
|
text_buf->draw(ci, text_ofs, color);
|
2019-08-20 16:41:14 +00:00
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-31 19:17:59 +00:00
|
|
|
Size2 Button::_fit_icon_size(const Size2 &p_size) const {
|
|
|
|
int max_width = theme_cache.icon_max_width;
|
|
|
|
Size2 icon_size = p_size;
|
|
|
|
|
|
|
|
if (max_width > 0 && icon_size.width > max_width) {
|
|
|
|
icon_size.height = icon_size.height * max_width / icon_size.width;
|
|
|
|
icon_size.width = max_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
return icon_size;
|
|
|
|
}
|
|
|
|
|
2022-03-19 01:15:55 +00:00
|
|
|
Size2 Button::get_minimum_size_for_text_and_icon(const String &p_text, Ref<Texture2D> p_icon) const {
|
|
|
|
Ref<TextParagraph> paragraph;
|
|
|
|
if (p_text.is_empty()) {
|
|
|
|
paragraph = text_buf;
|
|
|
|
} else {
|
|
|
|
paragraph.instantiate();
|
|
|
|
const_cast<Button *>(this)->_shape(paragraph, p_text);
|
|
|
|
}
|
|
|
|
|
|
|
|
Size2 minsize = paragraph->get_size();
|
|
|
|
if (clip_text || overrun_behavior != TextServer::OVERRUN_NO_TRIMMING) {
|
|
|
|
minsize.width = 0;
|
|
|
|
}
|
|
|
|
|
2022-08-12 11:39:22 +00:00
|
|
|
if (!expand_icon && p_icon.is_valid()) {
|
2023-03-31 19:17:59 +00:00
|
|
|
Size2 icon_size = _fit_icon_size(p_icon->get_size());
|
2023-03-03 20:21:41 +00:00
|
|
|
if (vertical_icon_alignment == VERTICAL_ALIGNMENT_CENTER) {
|
|
|
|
minsize.height = MAX(minsize.height, icon_size.height);
|
|
|
|
} else {
|
|
|
|
minsize.height += icon_size.height;
|
|
|
|
}
|
2022-03-19 01:15:55 +00:00
|
|
|
|
2023-03-03 20:21:41 +00:00
|
|
|
if (horizontal_icon_alignment != HORIZONTAL_ALIGNMENT_CENTER) {
|
2023-03-31 19:17:59 +00:00
|
|
|
minsize.width += icon_size.width;
|
2022-03-19 01:15:55 +00:00
|
|
|
if (!xl_text.is_empty() || !p_text.is_empty()) {
|
2022-08-31 12:02:40 +00:00
|
|
|
minsize.width += MAX(0, theme_cache.h_separation);
|
2022-03-19 01:15:55 +00:00
|
|
|
}
|
|
|
|
} else {
|
2023-03-31 19:17:59 +00:00
|
|
|
minsize.width = MAX(minsize.width, icon_size.width);
|
2022-03-19 01:15:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!xl_text.is_empty() || !p_text.is_empty()) {
|
2022-08-31 12:02:40 +00:00
|
|
|
Ref<Font> font = theme_cache.font;
|
|
|
|
float font_height = font->get_height(theme_cache.font_size);
|
2023-03-03 20:21:41 +00:00
|
|
|
if (vertical_icon_alignment == VERTICAL_ALIGNMENT_CENTER) {
|
|
|
|
minsize.height = MAX(font_height, minsize.height);
|
|
|
|
} else {
|
|
|
|
minsize.height += font_height;
|
|
|
|
}
|
2022-03-19 01:15:55 +00:00
|
|
|
}
|
|
|
|
|
2022-08-31 12:02:40 +00:00
|
|
|
return theme_cache.normal->get_minimum_size() + minsize;
|
2022-03-19 01:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Button::_shape(Ref<TextParagraph> p_paragraph, String p_text) {
|
|
|
|
if (p_paragraph.is_null()) {
|
|
|
|
p_paragraph = text_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_text.is_empty()) {
|
|
|
|
p_text = xl_text;
|
|
|
|
}
|
|
|
|
|
|
|
|
p_paragraph->clear();
|
2022-08-31 12:02:40 +00:00
|
|
|
|
|
|
|
Ref<Font> font = theme_cache.font;
|
|
|
|
int font_size = theme_cache.font_size;
|
|
|
|
if (font.is_null() || font_size == 0) {
|
|
|
|
// Can't shape without a valid font and a non-zero size.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-03 11:22:16 +00:00
|
|
|
if (text_direction == Control::TEXT_DIRECTION_INHERITED) {
|
2022-03-19 01:15:55 +00:00
|
|
|
p_paragraph->set_direction(is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR);
|
2020-09-03 11:22:16 +00:00
|
|
|
} else {
|
2022-03-19 01:15:55 +00:00
|
|
|
p_paragraph->set_direction((TextServer::Direction)text_direction);
|
2020-09-03 11:22:16 +00:00
|
|
|
}
|
2022-03-19 01:15:55 +00:00
|
|
|
p_paragraph->add_string(p_text, font, font_size, language);
|
|
|
|
p_paragraph->set_text_overrun_behavior(overrun_behavior);
|
2022-06-08 16:02:27 +00:00
|
|
|
}
|
|
|
|
|
2022-06-15 08:01:45 +00:00
|
|
|
void Button::set_text_overrun_behavior(TextServer::OverrunBehavior p_behavior) {
|
2022-06-08 16:02:27 +00:00
|
|
|
if (overrun_behavior != p_behavior) {
|
|
|
|
overrun_behavior = p_behavior;
|
|
|
|
_shape();
|
|
|
|
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2022-06-08 16:02:27 +00:00
|
|
|
update_minimum_size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-15 08:01:45 +00:00
|
|
|
TextServer::OverrunBehavior Button::get_text_overrun_behavior() const {
|
2022-06-08 16:02:27 +00:00
|
|
|
return overrun_behavior;
|
2020-09-03 11:22:16 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void Button::set_text(const String &p_text) {
|
2020-09-03 11:22:16 +00:00
|
|
|
if (text != p_text) {
|
|
|
|
text = p_text;
|
2021-05-27 17:31:33 +00:00
|
|
|
xl_text = atr(text);
|
2020-09-03 11:22:16 +00:00
|
|
|
_shape();
|
|
|
|
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2021-12-06 13:02:34 +00:00
|
|
|
update_minimum_size();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String Button::get_text() const {
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2020-09-03 11:22:16 +00:00
|
|
|
void Button::set_text_direction(Control::TextDirection p_text_direction) {
|
|
|
|
ERR_FAIL_COND((int)p_text_direction < -1 || (int)p_text_direction > 3);
|
|
|
|
if (text_direction != p_text_direction) {
|
|
|
|
text_direction = p_text_direction;
|
|
|
|
_shape();
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2020-09-03 11:22:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Control::TextDirection Button::get_text_direction() const {
|
|
|
|
return text_direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Button::set_language(const String &p_language) {
|
|
|
|
if (language != p_language) {
|
|
|
|
language = p_language;
|
|
|
|
_shape();
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2020-09-03 11:22:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String Button::get_language() const {
|
|
|
|
return language;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Button::set_icon(const Ref<Texture2D> &p_icon) {
|
2023-05-17 12:49:59 +00:00
|
|
|
if (icon == p_icon) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (icon.is_valid()) {
|
|
|
|
icon->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Button::_texture_changed));
|
|
|
|
}
|
|
|
|
|
|
|
|
icon = p_icon;
|
|
|
|
|
|
|
|
if (icon.is_valid()) {
|
|
|
|
icon->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Button::_texture_changed));
|
|
|
|
}
|
|
|
|
|
|
|
|
queue_redraw();
|
|
|
|
update_minimum_size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Button::_texture_changed() {
|
|
|
|
if (icon.is_valid()) {
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2021-12-06 13:02:34 +00:00
|
|
|
update_minimum_size();
|
2020-09-03 11:22:16 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
Ref<Texture2D> Button::get_icon() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
2021-10-08 21:26:13 +00:00
|
|
|
void Button::set_expand_icon(bool p_enabled) {
|
|
|
|
if (expand_icon != p_enabled) {
|
|
|
|
expand_icon = p_enabled;
|
2023-04-12 01:34:00 +00:00
|
|
|
_queue_update_size_cache();
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2021-12-06 13:02:34 +00:00
|
|
|
update_minimum_size();
|
2020-09-03 11:22:16 +00:00
|
|
|
}
|
2019-08-20 16:41:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Button::is_expand_icon() const {
|
|
|
|
return expand_icon;
|
|
|
|
}
|
|
|
|
|
2021-10-08 21:26:13 +00:00
|
|
|
void Button::set_flat(bool p_enabled) {
|
|
|
|
if (flat != p_enabled) {
|
|
|
|
flat = p_enabled;
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2020-09-03 11:22:16 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Button::is_flat() const {
|
|
|
|
return flat;
|
|
|
|
}
|
|
|
|
|
2021-10-08 21:26:13 +00:00
|
|
|
void Button::set_clip_text(bool p_enabled) {
|
|
|
|
if (clip_text != p_enabled) {
|
|
|
|
clip_text = p_enabled;
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2021-12-06 13:02:34 +00:00
|
|
|
update_minimum_size();
|
2020-09-03 11:22:16 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Button::get_clip_text() const {
|
|
|
|
return clip_text;
|
|
|
|
}
|
|
|
|
|
2021-11-25 02:58:47 +00:00
|
|
|
void Button::set_text_alignment(HorizontalAlignment p_alignment) {
|
|
|
|
if (alignment != p_alignment) {
|
|
|
|
alignment = p_alignment;
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2020-09-03 11:22:16 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2021-11-25 02:58:47 +00:00
|
|
|
HorizontalAlignment Button::get_text_alignment() const {
|
|
|
|
return alignment;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2021-11-25 02:58:47 +00:00
|
|
|
void Button::set_icon_alignment(HorizontalAlignment p_alignment) {
|
2023-03-03 20:21:41 +00:00
|
|
|
horizontal_icon_alignment = p_alignment;
|
|
|
|
update_minimum_size();
|
|
|
|
queue_redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Button::set_vertical_icon_alignment(VerticalAlignment p_alignment) {
|
|
|
|
vertical_icon_alignment = p_alignment;
|
2021-12-06 13:02:34 +00:00
|
|
|
update_minimum_size();
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2019-10-25 03:29:10 +00:00
|
|
|
}
|
|
|
|
|
2021-11-25 02:58:47 +00:00
|
|
|
HorizontalAlignment Button::get_icon_alignment() const {
|
2023-03-03 20:21:41 +00:00
|
|
|
return horizontal_icon_alignment;
|
|
|
|
}
|
|
|
|
|
|
|
|
VerticalAlignment Button::get_vertical_icon_alignment() const {
|
|
|
|
return vertical_icon_alignment;
|
2019-10-25 03:29:10 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void Button::_bind_methods() {
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_text", "text"), &Button::set_text);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_text"), &Button::get_text);
|
2022-06-08 16:02:27 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_text_overrun_behavior", "overrun_behavior"), &Button::set_text_overrun_behavior);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_text_overrun_behavior"), &Button::get_text_overrun_behavior);
|
2020-09-03 11:22:16 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_text_direction", "direction"), &Button::set_text_direction);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_text_direction"), &Button::get_text_direction);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_language", "language"), &Button::set_language);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_language"), &Button::get_language);
|
2017-08-09 11:19:41 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_button_icon", "texture"), &Button::set_icon);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_button_icon"), &Button::get_icon);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_flat", "enabled"), &Button::set_flat);
|
2019-10-25 03:29:10 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("is_flat"), &Button::is_flat);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_clip_text", "enabled"), &Button::set_clip_text);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_clip_text"), &Button::get_clip_text);
|
2021-11-25 02:58:47 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_text_alignment", "alignment"), &Button::set_text_alignment);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_text_alignment"), &Button::get_text_alignment);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_icon_alignment", "icon_alignment"), &Button::set_icon_alignment);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_icon_alignment"), &Button::get_icon_alignment);
|
2023-03-03 20:21:41 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_vertical_icon_alignment", "vertical_icon_alignment"), &Button::set_vertical_icon_alignment);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_vertical_icon_alignment"), &Button::get_vertical_icon_alignment);
|
2021-10-08 21:26:13 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_expand_icon", "enabled"), &Button::set_expand_icon);
|
2019-10-25 03:29:10 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("is_expand_icon"), &Button::is_expand_icon);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2023-01-09 14:31:44 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_MULTILINE_TEXT), "set_text", "get_text");
|
2019-06-11 18:43:37 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_button_icon", "get_button_icon");
|
2017-02-12 00:11:37 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flat"), "set_flat", "is_flat");
|
2023-01-25 14:39:02 +00:00
|
|
|
|
|
|
|
ADD_GROUP("Text Behavior", "");
|
2021-11-25 02:58:47 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "alignment", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_text_alignment", "get_text_alignment");
|
2022-06-08 16:02:27 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "text_overrun_behavior", PROPERTY_HINT_ENUM, "Trim Nothing,Trim Characters,Trim Words,Ellipsis,Word Ellipsis"), "set_text_overrun_behavior", "get_text_overrun_behavior");
|
2023-01-25 14:39:02 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_text"), "set_clip_text", "get_clip_text");
|
|
|
|
|
|
|
|
ADD_GROUP("Icon Behavior", "");
|
2021-11-25 02:58:47 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "icon_alignment", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_icon_alignment", "get_icon_alignment");
|
2023-03-03 20:21:41 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "vertical_icon_alignment", PROPERTY_HINT_ENUM, "Top,Center,Bottom"), "set_vertical_icon_alignment", "get_vertical_icon_alignment");
|
2019-08-20 16:41:14 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "expand_icon"), "set_expand_icon", "is_expand_icon");
|
2022-05-09 09:47:10 +00:00
|
|
|
|
|
|
|
ADD_GROUP("BiDi", "");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "text_direction", PROPERTY_HINT_ENUM, "Auto,Left-to-Right,Right-to-Left,Inherited"), "set_text_direction", "get_text_direction");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "language", PROPERTY_HINT_LOCALE_ID, ""), "set_language", "get_language");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Button::Button(const String &p_text) {
|
2021-06-17 22:03:09 +00:00
|
|
|
text_buf.instantiate();
|
2022-08-30 08:56:17 +00:00
|
|
|
text_buf->set_break_flags(TextServer::BREAK_MANDATORY | TextServer::BREAK_TRIM_EDGE_SPACES);
|
2017-01-08 22:54:19 +00:00
|
|
|
set_mouse_filter(MOUSE_FILTER_STOP);
|
2022-03-04 08:18:44 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
set_text(p_text);
|
|
|
|
}
|
|
|
|
|
|
|
|
Button::~Button() {
|
|
|
|
}
|