From 520435dfb0b0ac2bf6c42e390e02bb762def378c Mon Sep 17 00:00:00 2001 From: aiongg Date: Wed, 21 Oct 2026 05:28:17 +0000 Subject: [PATCH] egui: UI language and bidi text runs in the AccessKit tree `Context::set_language` sets the UI language (a BCP 47 tag, in `Options::language`), which goes on the root of the AccessKit tree. Content in another language says so with `UiBuilder::language`, which sets it on that `Ui`'s node and in `Ui::language`, or with `Response::accessible_language` for a single widget. Text runs follow the galley's bidi levels: a row is split into one run per stretch of one level, with its real direction and its logical text. Character positions of a right-to-left run count from its right edge, as AccessKit expects. --- crates/egui/src/context.rs | 28 +- crates/egui/src/memory/mod.rs | 13 + crates/egui/src/response.rs | 19 + .../egui/src/text_selection/accesskit_text.rs | 405 +++++++++++++----- .../egui/src/text_selection/cursor_range.rs | 15 +- crates/egui/src/text_selection/mod.rs | 2 +- crates/egui/src/ui.rs | 20 + crates/egui/src/ui_builder.rs | 13 + crates/egui/src/ui_stack.rs | 8 + 9 files changed, 394 insertions(+), 129 deletions(-) diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index 9f6518cd..952097cc 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -2595,6 +2595,25 @@ impl Context { self.options_mut(|opt| opt.theme_preference = theme_preference.into()); } + /// The language of the user interface, as a BCP 47 tag. + /// + /// See [`Options::language`]. + pub fn language(&self) -> Option { + self.options(|opt| opt.language.clone()) + } + + /// Set the language of the user interface, as a BCP 47 tag (`"ar"`, `"pt-BR"`). + /// + /// See [`Options::language`]. + /// + /// ``` + /// # let ctx = egui::Context::default(); + /// ctx.set_language(Some("ar".to_owned())); + /// ``` + pub fn set_language(&self, language: Option) { + self.options_mut(|opt| opt.language = language); + } + /// The currently active [`Style`] used by all subsequent popups, menus, etc. pub fn global_style(&self) -> Arc