diff options
author | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2023-02-22 00:08:05 +0200 |
---|---|---|
committer | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2023-02-22 08:37:14 +0200 |
commit | 82d7923c653b6328ba279bd4183b63b69e21edfc (patch) | |
tree | e96f0b1a01df1da8bd4fd40c252150afcee809fc /scene/main/window.cpp | |
parent | e13fae1414b0369fdd3f51b4e3529fd3f272b0e1 (diff) | |
download | redot-engine-82d7923c653b6328ba279bd4183b63b69e21edfc.tar.gz |
Improve layout direction/locale automatic selection.
Diffstat (limited to 'scene/main/window.cpp')
-rw-r--r-- | scene/main/window.cpp | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/scene/main/window.cpp b/scene/main/window.cpp index 59e3d307c6..4739f201dc 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -2113,22 +2113,39 @@ Window::LayoutDirection Window::get_layout_direction() const { bool Window::is_layout_rtl() const { if (layout_dir == LAYOUT_DIRECTION_INHERITED) { - Window *parent_w = Object::cast_to<Window>(get_parent()); - if (parent_w) { - return parent_w->is_layout_rtl(); - } else { - if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) { - return true; + if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) { + return true; + } + Node *parent_node = get_parent(); + while (parent_node) { + Control *parent_control = Object::cast_to<Control>(parent_node); + if (parent_control) { + return parent_control->is_layout_rtl(); } + + Window *parent_window = Object::cast_to<Window>(parent_node); + if (parent_window) { + return parent_window->is_layout_rtl(); + } + parent_node = parent_node->get_parent(); + } + + int root_dir = GLOBAL_GET(SNAME("internationalization/rendering/root_node_layout_direction")); + if (root_dir == 1) { + return false; + } else if (root_dir == 2) { + return true; + } else { String locale = TranslationServer::get_singleton()->get_tool_locale(); return TS->is_locale_right_to_left(locale); } } else if (layout_dir == LAYOUT_DIRECTION_LOCALE) { if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) { return true; + } else { + String locale = TranslationServer::get_singleton()->get_tool_locale(); + return TS->is_locale_right_to_left(locale); } - String locale = TranslationServer::get_singleton()->get_tool_locale(); - return TS->is_locale_right_to_left(locale); } else { return (layout_dir == LAYOUT_DIRECTION_RTL); } |