diff options
author | Poommetee Ketson <poommetee@protonmail.com> | 2017-11-11 13:23:53 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-11 13:23:53 +0700 |
commit | 11b2aa2729b5d8b2c03ed0d1f2d3b58f6d90d777 (patch) | |
tree | 44fa1bae0102aad913817113b2304d9f273cd74c /scene | |
parent | 19b1ff0fc5f7acce23176ad6c8752604357472f0 (diff) | |
parent | 8cf0d6ceb4f0c6c102a3166e8feb1589dd1030a9 (diff) |
Merge pull request #12827 from djrm/pr_fixes
Some fixes and improvements.
Diffstat (limited to 'scene')
-rw-r--r-- | scene/gui/check_button.cpp | 23 | ||||
-rw-r--r-- | scene/gui/check_button.h | 1 |
2 files changed, 22 insertions, 2 deletions
diff --git a/scene/gui/check_button.cpp b/scene/gui/check_button.cpp index e68159e27f..77fdedd5e5 100644 --- a/scene/gui/check_button.cpp +++ b/scene/gui/check_button.cpp @@ -32,6 +32,23 @@ #include "print_string.h" #include "servers/visual_server.h" +Size2 CheckButton::get_minimum_size() const { + + Size2 minsize = Button::get_minimum_size(); + + Ref<Texture> on = Control::get_icon("on"); + Ref<Texture> off = Control::get_icon("off"); + Size2 tex_size = Size2(0, 0); + if (!on.is_null()) + tex_size = Size2(on->get_width(), on->get_height()); + if (!off.is_null()) + tex_size = Size2(MAX(tex_size.width, off->get_width()), MAX(tex_size.height, off->get_height())); + minsize += Size2(tex_size.width + get_constant("hseparation"), 0); + minsize.height = MAX(minsize.height, tex_size.height); + + return get_stylebox("normal")->get_minimum_size() + minsize; +} + void CheckButton::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { @@ -41,9 +58,11 @@ void CheckButton::_notification(int p_what) { Ref<Texture> on = Control::get_icon("on"); Ref<Texture> off = Control::get_icon("off"); + Ref<StyleBox> sb = get_stylebox("normal"); + Size2 sb_ofs = Size2(sb->get_margin(MARGIN_RIGHT), sb->get_margin(MARGIN_TOP)); Vector2 ofs; - ofs.x = get_size().width - on->get_width(); - ofs.y = int((get_size().height - on->get_height()) / 2); + ofs.x = get_minimum_size().width - (on->get_width() + sb_ofs.width); + ofs.y = sb_ofs.height; if (is_pressed()) on->draw(ci, ofs); diff --git a/scene/gui/check_button.h b/scene/gui/check_button.h index af3b80fe04..eb68943fe7 100644 --- a/scene/gui/check_button.h +++ b/scene/gui/check_button.h @@ -39,6 +39,7 @@ class CheckButton : public Button { GDCLASS(CheckButton, Button); protected: + virtual Size2 get_minimum_size() const; void _notification(int p_what); public: |