Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Selectable whether to key handling in IME #5182

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions crates/egui/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`]
Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1994,6 +2016,7 @@ impl Visuals {
resize_corner_size,

text_cursor,
text_edit,

clip_rect_margin,
button_frame,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion crates/egui/src/widgets/text_edit/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_)));
}
Expand Down
Loading