Move IME candidate window following text cursor (#258)
* egui_web: enable IME support on web. * Move candidate window following text cursor. * Preclude too frequent agent movement. * IME candidate window move on native app.
This commit is contained in:
@@ -23,6 +23,9 @@ 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>,
|
||||
}
|
||||
|
||||
impl Output {
|
||||
|
||||
@@ -382,6 +382,7 @@ impl<'t> TextEdit<'t> {
|
||||
ui.output().cursor_icon = CursorIcon::Text;
|
||||
}
|
||||
|
||||
let mut text_cursor = None;
|
||||
if ui.memory().has_focus(id) && enabled {
|
||||
let mut cursorp = state
|
||||
.cursorp
|
||||
@@ -495,6 +496,7 @@ impl<'t> TextEdit<'t> {
|
||||
};
|
||||
}
|
||||
}
|
||||
text_cursor = Some(cursorp);
|
||||
state.cursorp = Some(cursorp);
|
||||
|
||||
state
|
||||
@@ -503,6 +505,15 @@ impl<'t> TextEdit<'t> {
|
||||
}
|
||||
|
||||
if ui.memory().has_focus(id) {
|
||||
{
|
||||
let mut output = ui.ctx().output();
|
||||
output.text_cursor = text_cursor.map(|c| {
|
||||
galley
|
||||
.pos_from_cursor(&c.primary)
|
||||
.translate(response.rect.min.to_vec2())
|
||||
.left_top()
|
||||
});
|
||||
}
|
||||
if let Some(cursorp) = state.cursorp {
|
||||
paint_cursor_selection(ui, response.rect.min, &galley, &cursorp);
|
||||
paint_cursor_end(ui, response.rect.min, &galley, &cursorp.primary);
|
||||
|
||||
Reference in New Issue
Block a user