Skip to content

desktop: Add basic support for RTL scripts in GUI #20265

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kjarosh
Copy link
Member

@kjarosh kjarosh commented Apr 26, 2025

This patch implements a workaround for egui not supporting RTL scripts. RTL text runs are being reversed and some characters are being mirrored.

It does not fix the interface being LTR though, and I assume ligatures also won't be drawn properly. But at least RTL text is readable now. Also text selection will not work properly (text will be reversed), and user-inputted text will not be fixed.

Before After

This refactors moves locale-related code away from
generic GUI-related code into a separate file.
@kjarosh kjarosh added A-desktop Area: Desktop Application T-feature Type: New Feature (that Flash doesn't have) rtl Issues related to directionality of text and interface (LTR vs RTL) labels Apr 26, 2025
@torokati44
Copy link
Member

Given that RTL support in egui is closer than ever with emilk/egui#5784, I'm not sure this hack is worth it still - but of course I can't tell the future of that PR either...

@kjarosh
Copy link
Member Author

kjarosh commented Apr 26, 2025

I'm not sure if it's a hack, as something like that is done normally but on a different level. (But here, e.g. text selection will not work properly.)

But IMO this workaround is so simple and so loosely coupled to the existing code that we might as well do it instead of waiting for several months for RTL support in egui. Removing it will be very easy in the future.

@danielhjacobs
Copy link
Contributor

https://github.com/emilk/egui/blob/ba67ccc81eabe156dc0519e54571592f64d0bc20/parley-todo.md is also still somewhat of a long list.

Comment on lines +104 to +105
fn mirror_char(c: char) -> char {
match c {
'(' => ')',
')' => '(',
'[' => ']',
']' => '[',
'{' => '}',
'}' => '{',
'<' => '>',
'>' => '<',
_ => c,
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it's worth adding another dependency, as the set of strings we mirror is finite (we do that only for translated strings), but I'll add it if you think it's better :D

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, either way is fine for me.

This patch implements a workaround for egui not supporting RTL scripts.
RTL text runs are being reversed and some characters are being mirrored.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-desktop Area: Desktop Application newsworthy rtl Issues related to directionality of text and interface (LTR vs RTL) T-feature Type: New Feature (that Flash doesn't have)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problem in the hebrew language GUI chosen font for menus doesn't support Arabic
4 participants