diff options
Diffstat (limited to 'scene/gui/control.cpp')
-rw-r--r-- | scene/gui/control.cpp | 70 |
1 files changed, 42 insertions, 28 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index c1d197ea9b..4a3f7f2414 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -44,7 +44,7 @@ #ifdef TOOLS_ENABLED #include "editor/plugins/control_editor_plugin.h" -#endif +#endif // TOOLS_ENABLED // Editor plugin interoperability. @@ -120,11 +120,11 @@ void Control::_edit_set_state(const Dictionary &p_state) { void Control::_edit_set_position(const Point2 &p_position) { ERR_FAIL_COND_MSG(!Engine::get_singleton()->is_editor_hint(), "This function can only be used from editor plugins."); set_position(p_position, ControlEditorToolbar::get_singleton()->is_anchors_mode_enabled() && get_parent_control()); -}; +} Point2 Control::_edit_get_position() const { return get_position(); -}; +} void Control::_edit_set_scale(const Size2 &p_scale) { set_scale(p_scale); @@ -140,14 +140,6 @@ void Control::_edit_set_rect(const Rect2 &p_edit_rect) { set_size(p_edit_rect.size.snappedf(1), ControlEditorToolbar::get_singleton()->is_anchors_mode_enabled()); } -Rect2 Control::_edit_get_rect() const { - return Rect2(Point2(), get_size()); -} - -bool Control::_edit_use_rect() const { - return true; -} - void Control::_edit_set_rotation(real_t p_rotation) { set_rotation(p_rotation); } @@ -178,7 +170,17 @@ bool Control::_edit_use_pivot() const { Size2 Control::_edit_get_minimum_size() const { return get_combined_minimum_size(); } -#endif +#endif // TOOLS_ENABLED + +#ifdef DEBUG_ENABLED +Rect2 Control::_edit_get_rect() const { + return Rect2(Point2(), get_size()); +} + +bool Control::_edit_use_rect() const { + return true; +} +#endif // DEBUG_ENABLED void Control::reparent(Node *p_parent, bool p_keep_global_transform) { ERR_MAIN_THREAD_GUARD; @@ -239,7 +241,7 @@ void Control::get_argument_options(const StringName &p_function, int p_idx, List } CanvasItem::get_argument_options(p_function, p_idx, r_options); } -#endif +#endif // TOOLS_ENABLED PackedStringArray Control::get_configuration_warnings() const { ERR_READ_THREAD_GUARD_V(PackedStringArray()); @@ -663,7 +665,7 @@ Rect2 Control::get_parent_anchorable_rect() const { #else parent_rect = get_viewport()->get_visible_rect(); -#endif +#endif // TOOLS_ENABLED } return parent_rect; @@ -1396,7 +1398,7 @@ void Control::set_position(const Point2 &p_point, bool p_keep_offsets) { data.pos_cache = p_point; return; } -#endif +#endif // TOOLS_ENABLED if (p_keep_offsets) { _compute_anchors(Rect2(p_point, data.size_cache), data.offset, data.anchor); @@ -1440,7 +1442,7 @@ void Control::_set_size(const Size2 &p_size) { if (data.size_warning && (data.anchor[SIDE_LEFT] != data.anchor[SIDE_RIGHT] || data.anchor[SIDE_TOP] != data.anchor[SIDE_BOTTOM])) { WARN_PRINT("Nodes with non-equal opposite anchors will have their size overridden after _ready(). \nIf you want to set size, change the anchors or consider using set_deferred()."); } -#endif +#endif // DEBUG_ENABLED set_size(p_size); } @@ -1462,7 +1464,7 @@ void Control::set_size(const Size2 &p_size, bool p_keep_offsets) { data.size_cache = new_size; return; } -#endif +#endif // TOOLS_ENABLED if (p_keep_offsets) { _compute_anchors(Rect2(data.pos_cache, new_size), data.offset, data.anchor); @@ -2745,7 +2747,7 @@ Variant Control::get_theme_item(Theme::DataType p_data_type, const StringName &p Ref<Texture2D> Control::get_editor_theme_icon(const StringName &p_name) const { return get_theme_icon(p_name, SNAME("EditorIcons")); } -#endif +#endif // TOOLS_ENABLED bool Control::has_theme_icon(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(false); @@ -3042,7 +3044,7 @@ void Control::set_layout_direction(Control::LayoutDirection p_direction) { if (data.layout_dir == p_direction) { return; } - ERR_FAIL_INDEX((int)p_direction, 4); + ERR_FAIL_INDEX(p_direction, LAYOUT_DIRECTION_MAX); data.layout_dir = p_direction; @@ -3087,7 +3089,7 @@ bool Control::is_layout_rtl() const { const_cast<Control *>(this)->data.is_rtl = true; return data.is_rtl; } -#endif +#endif // TOOLS_ENABLED Node *parent_node = get_parent(); while (parent_node) { Control *parent_control = Object::cast_to<Control>(parent_node); @@ -3115,13 +3117,20 @@ bool Control::is_layout_rtl() const { String locale = TranslationServer::get_singleton()->get_tool_locale(); const_cast<Control *>(this)->data.is_rtl = TS->is_locale_right_to_left(locale); } - } else if (data.layout_dir == LAYOUT_DIRECTION_LOCALE) { + } else if (data.layout_dir == LAYOUT_DIRECTION_APPLICATION_LOCALE) { if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) { const_cast<Control *>(this)->data.is_rtl = true; } else { String locale = TranslationServer::get_singleton()->get_tool_locale(); const_cast<Control *>(this)->data.is_rtl = TS->is_locale_right_to_left(locale); } + } else if (data.layout_dir == LAYOUT_DIRECTION_SYSTEM_LOCALE) { + if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) { + const_cast<Control *>(this)->data.is_rtl = true; + } else { + String locale = OS::get_singleton()->get_locale(); + const_cast<Control *>(this)->data.is_rtl = TS->is_locale_right_to_left(locale); + } } else { const_cast<Control *>(this)->data.is_rtl = (data.layout_dir == LAYOUT_DIRECTION_RTL); } @@ -3155,7 +3164,7 @@ bool Control::is_auto_translating() const { ERR_READ_THREAD_GUARD_V(false); return can_auto_translate(); } -#endif +#endif // DISABLE_DEPRECATED void Control::set_tooltip_auto_translate_mode(AutoTranslateMode p_mode) { ERR_MAIN_THREAD_GUARD; @@ -3208,7 +3217,7 @@ void Control::_notification(int p_notification) { case NOTIFICATION_EDITOR_POST_SAVE: { saving = false; } break; -#endif +#endif // TOOLS_ENABLED case NOTIFICATION_POSTINITIALIZE: { data.initialized = true; @@ -3254,7 +3263,7 @@ void Control::_notification(int p_notification) { case NOTIFICATION_READY: { #ifdef DEBUG_ENABLED connect(SceneStringName(ready), callable_mp(this, &Control::_clear_size_warning), CONNECT_DEFERRED | CONNECT_ONE_SHOT); -#endif +#endif // DEBUG_ENABLED } break; case NOTIFICATION_ENTER_CANVAS: { @@ -3566,7 +3575,7 @@ void Control::_bind_methods() { #ifndef DISABLE_DEPRECATED ClassDB::bind_method(D_METHOD("set_auto_translate", "enable"), &Control::set_auto_translate); ClassDB::bind_method(D_METHOD("is_auto_translating"), &Control::is_auto_translating); -#endif +#endif // DISABLE_DEPRECATED ClassDB::bind_method(D_METHOD("set_localize_numeral_system", "enable"), &Control::set_localize_numeral_system); ClassDB::bind_method(D_METHOD("is_localizing_numeral_system"), &Control::is_localizing_numeral_system); @@ -3574,7 +3583,7 @@ void Control::_bind_methods() { ADD_GROUP("Layout", ""); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_contents"), "set_clip_contents", "is_clipping_contents"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "custom_minimum_size", PROPERTY_HINT_NONE, "suffix:px"), "set_custom_minimum_size", "get_custom_minimum_size"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "layout_direction", PROPERTY_HINT_ENUM, "Inherited,Based on Locale,Left-to-Right,Right-to-Left"), "set_layout_direction", "get_layout_direction"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "layout_direction", PROPERTY_HINT_ENUM, "Inherited,Based on Application Locale,Left-to-Right,Right-to-Left,Based on System Locale"), "set_layout_direction", "get_layout_direction"); ADD_PROPERTY(PropertyInfo(Variant::INT, "layout_mode", PROPERTY_HINT_ENUM, "Position,Anchors,Container,Uncontrolled", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "_set_layout_mode", "_get_layout_mode"); ADD_PROPERTY_DEFAULT("layout_mode", LayoutMode::LAYOUT_MODE_POSITION); @@ -3621,7 +3630,7 @@ void Control::_bind_methods() { #ifndef DISABLE_DEPRECATED ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_translate", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_auto_translate", "is_auto_translating"); -#endif +#endif // DISABLE_DEPRECATED ADD_GROUP("Tooltip", "tooltip_"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "tooltip_text", PROPERTY_HINT_MULTILINE_TEXT), "set_tooltip_text", "get_tooltip_text"); @@ -3723,9 +3732,14 @@ void Control::_bind_methods() { BIND_ENUM_CONSTANT(ANCHOR_END); BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_INHERITED); - BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_LOCALE); + BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_APPLICATION_LOCALE); BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_LTR); BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_RTL); + BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_SYSTEM_LOCALE); + BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_MAX); +#ifndef DISABLE_DEPRECATED + BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_LOCALE); +#endif // DISABLE_DEPRECATED BIND_ENUM_CONSTANT(TEXT_DIRECTION_INHERITED); BIND_ENUM_CONSTANT(TEXT_DIRECTION_AUTO); |