diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index a0ee81fa139..cf4d0233f6e 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -857,6 +857,22 @@ 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_support: bool, +} + +impl Default for TextEditStyle { + fn default() -> Self { + Self { ime_support: true } + } +} + /// Controls the visual style (colors etc) of egui. /// /// You can change the visuals of a [`Ui`] with [`Ui::visuals_mut`] @@ -935,6 +951,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 +1336,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 +2014,7 @@ impl Visuals { resize_corner_size, text_cursor, + text_edit, clip_rect_margin, button_frame, @@ -2053,6 +2074,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 +2211,14 @@ impl TextCursorStyle { } } +impl TextEditStyle { + fn ui(&mut self, ui: &mut Ui) { + let Self { ime_support } = self; + + ui.checkbox(ime_support, "IME Support"); + } +} + #[cfg(debug_assertions)] impl DebugOptions { pub fn ui(&mut self, ui: &mut crate::Ui) { diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index 3ca36608c47..061aa689775 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -881,7 +881,9 @@ 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_support { + remove_ime_incompatible_events(&mut events); + } // Process IME events first: events.sort_by_key(|e| !matches!(e, Event::Ime(_))); }