summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/check_button.cpp23
-rw-r--r--scene/gui/check_button.h1
-rw-r--r--scene/gui/control.cpp10
-rw-r--r--scene/gui/control.h4
4 files changed, 29 insertions, 9 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:
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 1f230e95c7..e73ada9f31 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -2416,11 +2416,11 @@ float Control::get_rotation() const {
return data.rotation;
}
-void Control::set_rotation_deg(float p_degrees) {
+void Control::set_rotation_degrees(float p_degrees) {
set_rotation(Math::deg2rad(p_degrees));
}
-float Control::get_rotation_deg() const {
+float Control::get_rotation_degrees() const {
return Math::rad2deg(get_rotation());
}
@@ -2596,7 +2596,7 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_custom_minimum_size", "size"), &Control::set_custom_minimum_size);
ClassDB::bind_method(D_METHOD("set_global_position", "position"), &Control::set_global_position);
ClassDB::bind_method(D_METHOD("set_rotation", "radians"), &Control::set_rotation);
- ClassDB::bind_method(D_METHOD("set_rotation_deg", "degrees"), &Control::set_rotation_deg);
+ ClassDB::bind_method(D_METHOD("set_rotation_degrees", "degrees"), &Control::set_rotation_degrees);
ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Control::set_scale);
ClassDB::bind_method(D_METHOD("set_pivot_offset", "pivot_offset"), &Control::set_pivot_offset);
ClassDB::bind_method(D_METHOD("get_margin", "margin"), &Control::get_margin);
@@ -2605,7 +2605,7 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_position"), &Control::get_position);
ClassDB::bind_method(D_METHOD("get_size"), &Control::get_size);
ClassDB::bind_method(D_METHOD("get_rotation"), &Control::get_rotation);
- ClassDB::bind_method(D_METHOD("get_rotation_deg"), &Control::get_rotation_deg);
+ ClassDB::bind_method(D_METHOD("get_rotation_degrees"), &Control::get_rotation_degrees);
ClassDB::bind_method(D_METHOD("get_scale"), &Control::get_scale);
ClassDB::bind_method(D_METHOD("get_pivot_offset"), &Control::get_pivot_offset);
ClassDB::bind_method(D_METHOD("get_custom_minimum_size"), &Control::get_custom_minimum_size);
@@ -2724,7 +2724,7 @@ void Control::_bind_methods() {
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_position", "get_position");
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_size", "get_size");
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_min_size"), "set_custom_minimum_size", "get_custom_minimum_size");
- ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "rect_rotation", PROPERTY_HINT_RANGE, "-1080,1080,0.01"), "set_rotation_deg", "get_rotation_deg");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "rect_rotation", PROPERTY_HINT_RANGE, "-1080,1080,0.01"), "set_rotation_degrees", "get_rotation_degrees");
ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2, "rect_scale"), "set_scale", "get_scale");
ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2, "rect_pivot_offset"), "set_pivot_offset", "get_pivot_offset");
ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "rect_clip_content"), "set_clip_contents", "is_clipping_contents");
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 8c1df6784a..4d0e3934ad 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -328,9 +328,9 @@ public:
Rect2 get_window_rect() const; ///< use with care, as it blocks waiting for the visual server
void set_rotation(float p_radians);
- void set_rotation_deg(float p_degrees);
+ void set_rotation_degrees(float p_degrees);
float get_rotation() const;
- float get_rotation_deg() const;
+ float get_rotation_degrees() const;
void set_h_grow_direction(GrowDirection p_direction);
GrowDirection get_h_grow_direction() const;