summaryrefslogtreecommitdiff
path: root/scene/gui/button.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/button.cpp')
-rw-r--r--scene/gui/button.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp
index ca4c255855..784d298bff 100644
--- a/scene/gui/button.cpp
+++ b/scene/gui/button.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -40,7 +40,7 @@ Size2 Button::get_minimum_size() const {
minsize.width = 0;
if (!expand_icon) {
- Ref<Texture> _icon;
+ Ref<Texture2D> _icon;
if (icon.is_null() && has_icon("icon"))
_icon = Control::get_icon("icon");
else
@@ -106,7 +106,7 @@ void Button::_notification(int p_what) {
break;
}
- FALLTHROUGH;
+ [[fallthrough]];
}
case DRAW_PRESSED: {
@@ -150,7 +150,7 @@ void Button::_notification(int p_what) {
}
Ref<Font> font = get_font("font");
- Ref<Texture> _icon;
+ Ref<Texture2D> _icon;
if (icon.is_null() && has_icon("icon"))
_icon = Control::get_icon("icon");
else
@@ -190,6 +190,13 @@ void Button::_notification(int p_what) {
Point2 icon_ofs = !_icon.is_null() ? Point2(icon_region.size.width + get_constant("hseparation"), 0) : Point2();
int text_clip = size.width - style->get_minimum_size().width - icon_ofs.width;
+ if (_internal_margin[MARGIN_LEFT] > 0) {
+ text_clip -= _internal_margin[MARGIN_LEFT] + get_constant("hseparation");
+ }
+ if (_internal_margin[MARGIN_RIGHT] > 0) {
+ text_clip -= _internal_margin[MARGIN_RIGHT] + get_constant("hseparation");
+ }
+
Point2 text_ofs = (size - style->get_minimum_size() - icon_ofs - font->get_string_size(xl_text) - Point2(_internal_margin[MARGIN_RIGHT] - _internal_margin[MARGIN_LEFT], 0)) / 2.0;
switch (align) {
@@ -242,7 +249,7 @@ String Button::get_text() const {
return text;
}
-void Button::set_icon(const Ref<Texture> &p_icon) {
+void Button::set_icon(const Ref<Texture2D> &p_icon) {
if (icon == p_icon)
return;
@@ -252,7 +259,7 @@ void Button::set_icon(const Ref<Texture> &p_icon) {
minimum_size_changed();
}
-Ref<Texture> Button::get_icon() const {
+Ref<Texture2D> Button::get_icon() const {
return icon;
}
@@ -324,7 +331,7 @@ void Button::_bind_methods() {
BIND_ENUM_CONSTANT(ALIGN_RIGHT);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT_INTL), "set_text", "get_text");
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_button_icon", "get_button_icon");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_button_icon", "get_button_icon");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flat"), "set_flat", "is_flat");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_text"), "set_clip_text", "get_clip_text");
ADD_PROPERTY(PropertyInfo(Variant::INT, "align", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_text_align", "get_text_align");