diff --git a/crates/eframe/Cargo.toml b/crates/eframe/Cargo.toml index d085658f4..c063ae087 100644 --- a/crates/eframe/Cargo.toml +++ b/crates/eframe/Cargo.toml @@ -101,10 +101,6 @@ wgpu = ["wgpu_no_default_features", "egui-wgpu/default"] ## ``` wgpu_no_default_features = ["dep:wgpu", "dep:egui-wgpu", "dep:pollster"] -## Enable the new IME composition visuals on Windows. The legacy visuals remain -## the default on Windows due to known issues with the new implementation. -windows_new_ime_composition_visuals = ["egui/_override_legacy_ime_composition_visuals"] - ## Enables compiling for x11. x11 = [ "egui-winit/x11", @@ -189,11 +185,6 @@ objc2-app-kit = { workspace = true, default-features = false, features = [ # windows: [target.'cfg(any(target_os = "windows"))'.dependencies] -egui = { workspace = true, default-features = false, features = [ - "bytemuck", - "legacy_ime_composition_visuals", -] } - windows-sys = { workspace = true, features = [ "Win32_Foundation", "Win32_System_Com", diff --git a/crates/egui/Cargo.toml b/crates/egui/Cargo.toml index 83fdff3a4..fadc27c6c 100644 --- a/crates/egui/Cargo.toml +++ b/crates/egui/Cargo.toml @@ -44,21 +44,6 @@ color-hex = ["epaint/color-hex"] ## If you plan on specifying your own fonts you may disable this feature. default_fonts = ["epaint/default_fonts"] -## The legacy IME composition visuals have several shortcomings. Most notably, -## they are visually identical to text selection, making it impossible to tell -## the two apart if there is no candidate window (e.g. when using a Korean IME). -## In addition, the cursor is always shown at the end of the composition no -## matter where the actual cursor is, which makes composing Chinese and Japanese -## text confusing. -## -## However, the new composition visuals are not yet fully reliable either. For -## example, on Windows, `winit` currently reports an incorrect cursor position -## for Korean IMEs: the cursor should be at the end of the composition, but -## `winit` reports it at the beginning. Therefore, we keep the legacy visuals -## as an option for now and plan to remove them once the new visuals work -## correctly across all supported platforms. -legacy_ime_composition_visuals = [] - ## [`mint`](https://docs.rs/mint) enables interoperability with other math libraries such as [`glam`](https://docs.rs/glam) and [`nalgebra`](https://docs.rs/nalgebra). mint = ["epaint/mint"] @@ -77,9 +62,6 @@ serde = ["dep:serde", "epaint/serde", "accesskit/serde"] ## Change Vertex layout to be compatible with unity unity = ["epaint/unity"] -## Override and disable the legacy_ime_composition_visuals feature. -_override_legacy_ime_composition_visuals = [] - ## Override and disable the unity feature ## This exists, so that when testing with --all-features, snapshots render correctly. _override_unity = ["epaint/_override_unity"] diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index 6599da39d..d5c89a6ac 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -1204,6 +1204,24 @@ pub struct ImeComposition { /// Stroke used to underline those non-active segments. pub inactive_underline_stroke: Stroke, + + /// If `true`, IME (Input Method Editor) composition (preedit) text is rendered + /// the legacy way: visually indistinguishable from a text selection, with the + /// cursor always shown at the end of the composition. + /// + /// If `false`, egui renders proper IME composition visuals: the cursor position + /// inside the composition is shown, and the active conversion segment is + /// highlighted (using the strokes configured above) distinctly from the rest of the + /// composition. This makes composing Chinese, Japanese and Korean text much + /// clearer. + /// + /// The legacy visuals have known shortcomings, but the new visuals are not yet + /// fully reliable on every platform either (e.g. `winit` reports an incorrect + /// cursor position for Korean IMEs on Windows), so this remains configurable. + /// + /// Defaults to `true` on Windows (because of the aforementioned `winit` bug) and + /// to `false` everywhere else. + pub legacy_visuals: bool, } /// Shape of the handle for sliders and similar widgets. @@ -1621,6 +1639,7 @@ impl ImeComposition { Self { active_underline_stroke, inactive_underline_stroke, + legacy_visuals: Self::default_legacy_visuals(), } } @@ -1634,8 +1653,15 @@ impl ImeComposition { Self { active_underline_stroke, inactive_underline_stroke, + legacy_visuals: Self::default_legacy_visuals(), } } + + /// The default of [`Self::legacy_visuals`]: `true` on Windows (where `winit` + /// reports an incorrect cursor position for Korean IMEs), `false` elsewhere. + const fn default_legacy_visuals() -> bool { + cfg!(windows) + } } impl Default for ImeComposition { @@ -2168,10 +2194,17 @@ impl ImeComposition { let Self { active_underline_stroke, inactive_underline_stroke, + legacy_visuals, } = self; ui.label("IME composition"); + ui.checkbox(legacy_visuals, "Legacy visuals").on_hover_text( + "If enabled, IME composition (preedit) text looks like a text selection \ + with the cursor at the end. If disabled, the cursor position and active \ + conversion segment are shown.", + ); + Grid::new("ime_composition").num_columns(2).show(ui, |ui| { ui.label("Active underline stroke"); ui.add(active_underline_stroke); diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index a7984882b..bb2f40a6f 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -827,10 +827,7 @@ impl TextEdit<'_> { false }; - let should_paint_ime_visuals_the_legacy_way = cfg!(all( - feature = "legacy_ime_composition_visuals", - not(feature = "_override_legacy_ime_composition_visuals"), - )); + let should_paint_ime_visuals_the_legacy_way = ui.visuals().ime_composition.legacy_visuals; if ui.is_rect_visible(inner_rect) { let has_focus = ui.memory(|mem| mem.has_focus(id));