diff options
Diffstat (limited to 'scene/gui/check_box.cpp')
-rw-r--r-- | scene/gui/check_box.cpp | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/scene/gui/check_box.cpp b/scene/gui/check_box.cpp index df6f38f65d..9df328dd11 100644 --- a/scene/gui/check_box.cpp +++ b/scene/gui/check_box.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 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 */ @@ -62,14 +62,20 @@ Size2 CheckBox::get_minimum_size() const { minsize.width += get_theme_constant("hseparation"); } Ref<StyleBox> sb = get_theme_stylebox("normal"); - minsize.height = MAX(minsize.height, tex_size.height + sb->get_margin(MARGIN_TOP) + sb->get_margin(MARGIN_BOTTOM)); + minsize.height = MAX(minsize.height, tex_size.height + sb->get_margin(SIDE_TOP) + sb->get_margin(SIDE_BOTTOM)); return minsize; } void CheckBox::_notification(int p_what) { - if (p_what == NOTIFICATION_THEME_CHANGED) { - _set_internal_margin(MARGIN_LEFT, get_icon_size().width); + if ((p_what == NOTIFICATION_THEME_CHANGED) || (p_what == NOTIFICATION_LAYOUT_DIRECTION_CHANGED || (p_what == NOTIFICATION_TRANSLATION_CHANGED))) { + if (is_layout_rtl()) { + _set_internal_margin(SIDE_LEFT, 0.f); + _set_internal_margin(SIDE_RIGHT, get_icon_size().width); + } else { + _set_internal_margin(SIDE_LEFT, get_icon_size().width); + _set_internal_margin(SIDE_RIGHT, 0.f); + } } else if (p_what == NOTIFICATION_DRAW) { RID ci = get_canvas_item(); @@ -78,7 +84,11 @@ void CheckBox::_notification(int p_what) { Ref<StyleBox> sb = get_theme_stylebox("normal"); Vector2 ofs; - ofs.x = sb->get_margin(MARGIN_LEFT); + if (is_layout_rtl()) { + ofs.x = get_size().x - sb->get_margin(SIDE_RIGHT) - get_icon_size().width; + } else { + ofs.x = sb->get_margin(SIDE_LEFT); + } ofs.y = int((get_size().height - get_icon_size().height) / 2) + get_theme_constant("check_vadjust"); if (is_pressed()) { @@ -96,8 +106,14 @@ bool CheckBox::is_radio() { CheckBox::CheckBox(const String &p_text) : Button(p_text) { set_toggle_mode(true); + set_text_align(ALIGN_LEFT); - _set_internal_margin(MARGIN_LEFT, get_icon_size().width); + + if (is_layout_rtl()) { + _set_internal_margin(SIDE_RIGHT, get_icon_size().width); + } else { + _set_internal_margin(SIDE_LEFT, get_icon_size().width); + } } CheckBox::~CheckBox() { |