Browse Source

Rename Output::text_cursor to text_cursor_pos

pull/432/head
Emil Ernerfeldt 4 years ago
parent
commit
6a576f4c34
  1. 4
      egui/src/data/output.rs
  2. 12
      egui/src/widgets/button.rs
  3. 4
      egui/src/widgets/selected_label.rs
  4. 2
      egui/src/widgets/text_edit.rs
  5. 2
      egui_glium/src/lib.rs
  6. 4
      egui_web/src/backend.rs
  7. 13
      egui_web/src/lib.rs

4
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<OutputEvent>,
/// Position of text widgts' cursor
pub text_cursor: Option<crate::Pos2>,
/// Position of text edit cursor (used for IME).
pub text_cursor_pos: Option<crate::Pos2>,
}
impl Output {

12
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
}
}

4
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
}
}

2
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())

2
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()

4
egui_web/src/backend.rs

@ -141,7 +141,7 @@ pub struct AppRunner {
screen_reader: crate::screen_reader::ScreenReader,
#[cfg(feature = "http")]
http: Arc<http::WebHttp>,
pub(crate) text_cursor: Option<egui::Pos2>,
pub(crate) last_text_cursor_pos: Option<egui::Pos2>,
}
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,
})
}

13
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<bool> {
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<egui::Pos2>, 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)?;

Loading…
Cancel
Save