1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -04:00

Make legacy ime visuals a runtime feature

This commit is contained in:
lucasmerlin
2026-06-25 17:52:39 +02:00
parent 5c2174d8e8
commit 9ea7ccc09f
4 changed files with 34 additions and 31 deletions

View File

@@ -101,10 +101,6 @@ wgpu = ["wgpu_no_default_features", "egui-wgpu/default"]
## ``` ## ```
wgpu_no_default_features = ["dep:wgpu", "dep:egui-wgpu", "dep:pollster"] 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. ## Enables compiling for x11.
x11 = [ x11 = [
"egui-winit/x11", "egui-winit/x11",
@@ -189,11 +185,6 @@ objc2-app-kit = { workspace = true, default-features = false, features = [
# windows: # windows:
[target.'cfg(any(target_os = "windows"))'.dependencies] [target.'cfg(any(target_os = "windows"))'.dependencies]
egui = { workspace = true, default-features = false, features = [
"bytemuck",
"legacy_ime_composition_visuals",
] }
windows-sys = { workspace = true, features = [ windows-sys = { workspace = true, features = [
"Win32_Foundation", "Win32_Foundation",
"Win32_System_Com", "Win32_System_Com",

View File

@@ -44,21 +44,6 @@ color-hex = ["epaint/color-hex"]
## If you plan on specifying your own fonts you may disable this feature. ## If you plan on specifying your own fonts you may disable this feature.
default_fonts = ["epaint/default_fonts"] 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`](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"] mint = ["epaint/mint"]
@@ -77,9 +62,6 @@ serde = ["dep:serde", "epaint/serde", "accesskit/serde"]
## Change Vertex layout to be compatible with unity ## Change Vertex layout to be compatible with unity
unity = ["epaint/unity"] unity = ["epaint/unity"]
## Override and disable the legacy_ime_composition_visuals feature.
_override_legacy_ime_composition_visuals = []
## Override and disable the unity feature ## Override and disable the unity feature
## This exists, so that when testing with --all-features, snapshots render correctly. ## This exists, so that when testing with --all-features, snapshots render correctly.
_override_unity = ["epaint/_override_unity"] _override_unity = ["epaint/_override_unity"]

View File

@@ -1204,6 +1204,24 @@ pub struct ImeComposition {
/// Stroke used to underline those non-active segments. /// Stroke used to underline those non-active segments.
pub inactive_underline_stroke: Stroke, 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. /// Shape of the handle for sliders and similar widgets.
@@ -1621,6 +1639,7 @@ impl ImeComposition {
Self { Self {
active_underline_stroke, active_underline_stroke,
inactive_underline_stroke, inactive_underline_stroke,
legacy_visuals: Self::default_legacy_visuals(),
} }
} }
@@ -1634,8 +1653,15 @@ impl ImeComposition {
Self { Self {
active_underline_stroke, active_underline_stroke,
inactive_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 { impl Default for ImeComposition {
@@ -2168,10 +2194,17 @@ impl ImeComposition {
let Self { let Self {
active_underline_stroke, active_underline_stroke,
inactive_underline_stroke, inactive_underline_stroke,
legacy_visuals,
} = self; } = self;
ui.label("IME composition"); 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| { Grid::new("ime_composition").num_columns(2).show(ui, |ui| {
ui.label("Active underline stroke"); ui.label("Active underline stroke");
ui.add(active_underline_stroke); ui.add(active_underline_stroke);

View File

@@ -827,10 +827,7 @@ impl TextEdit<'_> {
false false
}; };
let should_paint_ime_visuals_the_legacy_way = cfg!(all( let should_paint_ime_visuals_the_legacy_way = ui.visuals().ime_composition.legacy_visuals;
feature = "legacy_ime_composition_visuals",
not(feature = "_override_legacy_ime_composition_visuals"),
));
if ui.is_rect_visible(inner_rect) { if ui.is_rect_visible(inner_rect) {
let has_focus = ui.memory(|mem| mem.has_focus(id)); let has_focus = ui.memory(|mem| mem.has_focus(id));