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.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp
index 6b3e89af6c..6f3d8c61cf 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 */
@@ -174,22 +174,29 @@ void Button::_notification(int p_what) {
_size.width -= get_constant("hseparation") + icon_ofs_region;
if (!clip_text)
_size.width -= get_font("font")->get_string_size(xl_text).width;
- float icon_width = icon->get_width() * _size.height / icon->get_height();
+ float icon_width = _icon->get_width() * _size.height / _icon->get_height();
float icon_height = _size.height;
if (icon_width > _size.width) {
icon_width = _size.width;
- icon_height = icon->get_height() * icon_width / icon->get_width();
+ icon_height = _icon->get_height() * icon_width / _icon->get_width();
}
icon_region = Rect2(style->get_offset() + Point2(icon_ofs_region, (_size.height - icon_height) / 2), Size2(icon_width, icon_height));
} else {
- icon_region = Rect2(style->get_offset() + Point2(icon_ofs_region, Math::floor((valign - _icon->get_height()) / 2.0)), icon->get_size());
+ icon_region = Rect2(style->get_offset() + Point2(icon_ofs_region, Math::floor((valign - _icon->get_height()) / 2.0)), _icon->get_size());
}
}
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) {
@@ -221,7 +228,7 @@ void Button::_notification(int p_what) {
font->draw(ci, text_ofs.floor(), xl_text, color, clip_text ? text_clip : -1);
if (!_icon.is_null() && icon_region.size.width > 0) {
- draw_texture_rect_region(_icon, icon_region, Rect2(Point2(), icon->get_size()), color_icon);
+ draw_texture_rect_region(_icon, icon_region, Rect2(Point2(), _icon->get_size()), color_icon);
}
} break;
}