Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MenuBar item order in RTL layout #77519

Merged
merged 1 commit into from
May 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions scene/gui/menu_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,18 @@ void MenuBar::_notification(int p_what) {
int MenuBar::_get_index_at_point(const Point2 &p_point) const {
Ref<StyleBox> style = theme_cache.normal;
int offset = 0;
Point2 point = p_point;
if (is_layout_rtl()) {
point.x = get_size().x - point.x;
}

for (int i = 0; i < menu_cache.size(); i++) {
if (menu_cache[i].hidden) {
continue;
}
Size2 size = menu_cache[i].text_buf->get_size() + style->get_minimum_size();
if (p_point.x > offset && p_point.x < offset + size.x) {
if (p_point.y > 0 && p_point.y < size.y) {
if (point.x > offset && point.x < offset + size.x) {
if (point.y > 0 && point.y < size.y) {
return i;
}
}
Expand All @@ -428,7 +433,12 @@ Rect2 MenuBar::_get_menu_item_rect(int p_index) const {
offset += size.x + theme_cache.h_separation;
}

return Rect2(Point2(offset, 0), menu_cache[p_index].text_buf->get_size() + style->get_minimum_size());
Size2 size = menu_cache[p_index].text_buf->get_size() + style->get_minimum_size();
if (is_layout_rtl()) {
return Rect2(Point2(get_size().x - offset - size.x, 0), size);
} else {
return Rect2(Point2(offset, 0), size);
}
}

void MenuBar::_draw_menu_item(int p_index) {
Expand Down