From 6a576f4c3431bfd90171e75cfca42316fba9b1ec Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 20 May 2021 21:58:44 +0200 Subject: [PATCH] Rename Output::text_cursor to text_cursor_pos --- egui/src/data/output.rs | 4 ++-- egui/src/widgets/button.rs | 12 ++++++------ egui/src/widgets/selected_label.rs | 4 ++-- egui/src/widgets/text_edit.rs | 2 +- egui_glium/src/lib.rs | 2 +- egui_web/src/backend.rs | 4 ++-- egui_web/src/lib.rs | 13 +++++++------ 7 files changed, 21 insertions(+), 20 deletions(-) diff --git a/egui/src/data/output.rs b/egui/src/data/output.rs index 7cc8f3ee..d53778d9 100644 --- a/egui/src/data/output.rs +++ b/egui/src/data/output.rs @@ -24,8 +24,8 @@ pub struct Output { /// Events that may be useful to e.g. a screen reader. pub events: Vec, - /// Position of text widgts' cursor - pub text_cursor: Option, + /// Position of text edit cursor (used for IME). + pub text_cursor_pos: Option, } impl Output { diff --git a/egui/src/widgets/button.rs b/egui/src/widgets/button.rs index e5b5477c..782dd904 100644 --- a/egui/src/widgets/button.rs +++ b/egui/src/widgets/button.rs @@ -152,7 +152,7 @@ impl Button { if ui.clip_rect().intersects(rect) { let visuals = ui.style().interact(&response); - let text_cursor = ui + let text_pos = ui .layout() .align_size_within_rect(galley.size, rect.shrink2(button_padding)) .min; @@ -170,7 +170,7 @@ impl Button { let text_color = text_color .or(ui.visuals().override_text_color) .unwrap_or_else(|| visuals.text_color()); - ui.painter().galley(text_cursor, galley, text_color); + ui.painter().galley(text_pos, galley, text_color); } response @@ -277,7 +277,7 @@ impl<'a> Widget for Checkbox<'a> { // let visuals = ui.style().interact_selectable(&response, *checked); // too colorful let visuals = ui.style().interact(&response); - let text_cursor = pos2( + let text_pos = pos2( rect.min.x + button_padding.x + icon_width + icon_spacing, rect.center().y - 0.5 * galley.size.y, ); @@ -304,7 +304,7 @@ impl<'a> Widget for Checkbox<'a> { let text_color = text_color .or(ui.visuals().override_text_color) .unwrap_or_else(|| visuals.text_color()); - ui.painter().galley(text_cursor, galley, text_color); + ui.painter().galley(text_pos, galley, text_color); response } } @@ -392,7 +392,7 @@ impl Widget for RadioButton { response .widget_info(|| WidgetInfo::selected(WidgetType::RadioButton, checked, &galley.text)); - let text_cursor = pos2( + let text_pos = pos2( rect.min.x + button_padding.x + icon_width + icon_spacing, rect.center().y - 0.5 * galley.size.y, ); @@ -424,7 +424,7 @@ impl Widget for RadioButton { let text_color = text_color .or(ui.visuals().override_text_color) .unwrap_or_else(|| visuals.text_color()); - painter.galley(text_cursor, galley, text_color); + painter.galley(text_pos, galley, text_color); response } } diff --git a/egui/src/widgets/selected_label.rs b/egui/src/widgets/selected_label.rs index b95aa4ce..ef3fe6eb 100644 --- a/egui/src/widgets/selected_label.rs +++ b/egui/src/widgets/selected_label.rs @@ -73,7 +73,7 @@ impl Widget for SelectableLabel { WidgetInfo::selected(WidgetType::SelectableLabel, selected, &galley.text) }); - let text_cursor = ui + let text_pos = ui .layout() .align_size_within_rect(galley.size, rect.shrink2(button_padding)) .min; @@ -93,7 +93,7 @@ impl Widget for SelectableLabel { .visuals .override_text_color .unwrap_or_else(|| visuals.text_color()); - ui.painter().galley(text_cursor, galley, text_color); + ui.painter().galley(text_pos, galley, text_color); response } } diff --git a/egui/src/widgets/text_edit.rs b/egui/src/widgets/text_edit.rs index 1272e7ca..65b5a525 100644 --- a/egui/src/widgets/text_edit.rs +++ b/egui/src/widgets/text_edit.rs @@ -678,7 +678,7 @@ impl<'t, S: TextBuffer> TextEdit<'t, S> { if ui.memory().has_focus(id) { { let mut output = ui.ctx().output(); - output.text_cursor = text_cursor.map(|c| { + output.text_cursor_pos = text_cursor.map(|c| { galley .pos_from_cursor(&c.primary) .translate(response.rect.min.to_vec2()) diff --git a/egui_glium/src/lib.rs b/egui_glium/src/lib.rs index da1a0c6f..47e90e04 100644 --- a/egui_glium/src/lib.rs +++ b/egui_glium/src/lib.rs @@ -381,7 +381,7 @@ pub fn handle_output( } } - if let Some(egui::Pos2 { x, y }) = output.text_cursor { + if let Some(egui::Pos2 { x, y }) = output.text_cursor_pos { display .gl_window() .window() diff --git a/egui_web/src/backend.rs b/egui_web/src/backend.rs index a9dd9493..31eb957b 100644 --- a/egui_web/src/backend.rs +++ b/egui_web/src/backend.rs @@ -141,7 +141,7 @@ pub struct AppRunner { screen_reader: crate::screen_reader::ScreenReader, #[cfg(feature = "http")] http: Arc, - pub(crate) text_cursor: Option, + pub(crate) last_text_cursor_pos: Option, } impl AppRunner { @@ -160,7 +160,7 @@ impl AppRunner { screen_reader: Default::default(), #[cfg(feature = "http")] http: Arc::new(http::WebHttp {}), - text_cursor: None, + last_text_cursor_pos: None, }) } diff --git a/egui_web/src/lib.rs b/egui_web/src/lib.rs index b78a00bd..9571f942 100644 --- a/egui_web/src/lib.rs +++ b/egui_web/src/lib.rs @@ -299,7 +299,7 @@ pub fn handle_output(output: &egui::Output, runner: &mut AppRunner) { copied_text, needs_repaint: _, // handled elsewhere events: _, // we ignore these (TODO: accessibility screen reader) - text_cursor: cursor, + text_cursor_pos, } = output; set_cursor_icon(*cursor_icon); @@ -315,9 +315,9 @@ pub fn handle_output(output: &egui::Output, runner: &mut AppRunner) { #[cfg(not(web_sys_unstable_apis))] let _ = copied_text; - if &runner.text_cursor != cursor { - move_text_cursor(cursor, runner.canvas_id()); - runner.text_cursor = *cursor; + if &runner.last_text_cursor_pos != text_cursor_pos { + move_text_cursor(text_cursor_pos, runner.canvas_id()); + runner.last_text_cursor_pos = *text_cursor_pos; } } @@ -1119,12 +1119,13 @@ fn is_mobile() -> Option { Some(is_mobile) } -// Move angnt to text cursor's position, on desktop/laptop, candidate window moves following text elemt(agent), +// Move text agent to text cursor's position, on desktop/laptop, +// candidate window moves following text element (agent), // so it appears that the IME candidate window moves with text cursor. // On mobile devices, there is no need to do that. fn move_text_cursor(cursor: &Option, canvas_id: &str) -> Option<()> { let style = text_agent().style(); - // Note: movint agent on mobile devices will lead to unpreditable scroll. + // Note: movint agent on mobile devices will lead to unpredictable scroll. if is_mobile() == Some(false) { cursor.as_ref().and_then(|&egui::Pos2 { x, y }| { let canvas = canvas_element(canvas_id)?;