From f8bfef893aae496ed29bf2c5ce696279eaa61b8e Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 28 Sep 2024 21:36:53 +0900 Subject: [PATCH 1/5] Update style.rs --- crates/egui/src/style.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index a0ee81fa139..fa4fa3f1209 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -857,6 +857,24 @@ impl Default for TextCursorStyle { } } +/// Defines the style and behavior of a `TextEdit`. +#[derive(Clone, Debug, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "serde", serde(default))] +pub struct TextEditStyle { + /// Indicates whether to provide assistance for IME input. + /// Such as backspace and arrow keys handling. + pub ime_key_handling: bool, +} + +impl Default for TextEditStyle { + fn default() -> Self { + Self { + ime_key_handling: true, + } + } +} + /// Controls the visual style (colors etc) of egui. /// /// You can change the visuals of a [`Ui`] with [`Ui::visuals_mut`] @@ -935,6 +953,9 @@ pub struct Visuals { /// How the text cursor acts. pub text_cursor: TextCursorStyle, + /// Defines the style and behavior of a TextEdit. + pub text_edit: TextEditStyle, + /// Allow child widgets to be just on the border and still have a stroke with some thickness pub clip_rect_margin: f32, @@ -1317,6 +1338,7 @@ impl Visuals { resize_corner_size: 12.0, text_cursor: Default::default(), + text_edit: Default::default(), clip_rect_margin: 3.0, // should be at least half the size of the widest frame stroke + max WidgetVisuals::expansion button_frame: true, @@ -1994,6 +2016,7 @@ impl Visuals { resize_corner_size, text_cursor, + text_edit, clip_rect_margin, button_frame, @@ -2053,6 +2076,10 @@ impl Visuals { text_cursor.ui(ui); }); + ui.collapsing("Text Edit", |ui| { + text_edit.ui(ui); + }); + ui.collapsing("Window", |ui| { Grid::new("window") .num_columns(2) @@ -2186,6 +2213,14 @@ impl TextCursorStyle { } } +impl TextEditStyle { + fn ui(&mut self, ui: &mut Ui) { + let Self { ime_key_handling } = self; + + ui.checkbox(ime_key_handling, "IME key handling"); + } +} + #[cfg(debug_assertions)] impl DebugOptions { pub fn ui(&mut self, ui: &mut crate::Ui) { From ca893431567cd5f3d95d38e27449fe9668dfb4c2 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 28 Sep 2024 21:38:13 +0900 Subject: [PATCH 2/5] Update builder.rs --- crates/egui/src/widgets/text_edit/builder.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index 3ca36608c47..8787bbbe4c7 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -881,7 +881,10 @@ fn events( let mut events = ui.input(|i| i.filtered_events(&event_filter)); if state.ime_enabled { - remove_ime_incompatible_events(&mut events); + if ui.visuals().text_edit.ime_key_handling { + remove_ime_incompatible_events(&mut events); + } + // Process IME events first: events.sort_by_key(|e| !matches!(e, Event::Ime(_))); } From a88da61191e42042a9d99e1610c5454039eab877 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 28 Sep 2024 22:02:55 +0900 Subject: [PATCH 3/5] Update style.rs --- crates/egui/src/style.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index fa4fa3f1209..a1a144d6375 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -870,7 +870,7 @@ pub struct TextEditStyle { impl Default for TextEditStyle { fn default() -> Self { Self { - ime_key_handling: true, + ime_key_handling: !cfg!(target_os = "linux"), } } } From be4a0a0e9e83ec2ae4a40d067e9256308230fa74 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 28 Sep 2024 22:12:02 +0900 Subject: [PATCH 4/5] Update style.rs --- crates/egui/src/style.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index a1a144d6375..328a99ce214 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -870,7 +870,10 @@ pub struct TextEditStyle { impl Default for TextEditStyle { fn default() -> Self { Self { - ime_key_handling: !cfg!(target_os = "linux"), + #[cfg(target_os = "linux")] + ime_key_handling: false, + #[cfg(not(target_os = "linux"))] + ime_key_handling: true, } } } From 60052a290d57148bcebab9009e98cf1763fc405a Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 29 Sep 2024 10:08:18 +0900 Subject: [PATCH 5/5] Update style.rs --- crates/egui/src/style.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index 328a99ce214..fa4fa3f1209 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -870,9 +870,6 @@ pub struct TextEditStyle { impl Default for TextEditStyle { fn default() -> Self { Self { - #[cfg(target_os = "linux")] - ime_key_handling: false, - #[cfg(not(target_os = "linux"))] ime_key_handling: true, } }