mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -04:00
egui_web: improve text input on mobile and for IME
This commit is contained in:
@@ -29,7 +29,11 @@ pub struct Output {
|
||||
/// Events that may be useful to e.g. a screen reader.
|
||||
pub events: Vec<OutputEvent>,
|
||||
|
||||
/// Position of text edit cursor (used for IME).
|
||||
/// Is there a mutable `TextEdit` under the cursor?
|
||||
/// Use by `egui_web` to show/hide mobile keyboard and IME agent.
|
||||
pub mutable_text_under_cursor: bool,
|
||||
|
||||
/// Screen-space position of text edit cursor (used for IME).
|
||||
pub text_cursor_pos: Option<crate::Pos2>,
|
||||
}
|
||||
|
||||
@@ -65,6 +69,7 @@ impl Output {
|
||||
copied_text,
|
||||
needs_repaint,
|
||||
mut events,
|
||||
mutable_text_under_cursor,
|
||||
text_cursor_pos,
|
||||
} = newer;
|
||||
|
||||
@@ -77,6 +82,7 @@ impl Output {
|
||||
}
|
||||
self.needs_repaint = needs_repaint; // if the last frame doesn't need a repaint, then we don't need to repaint
|
||||
self.events.append(&mut events);
|
||||
self.mutable_text_under_cursor = mutable_text_under_cursor;
|
||||
self.text_cursor_pos = text_cursor_pos.or(self.text_cursor_pos);
|
||||
}
|
||||
|
||||
|
||||
@@ -611,6 +611,10 @@ impl<'t> TextEdit<'t> {
|
||||
|
||||
if interactive {
|
||||
if let Some(pointer_pos) = ui.input().pointer.interact_pos() {
|
||||
if response.hovered() && text.is_mutable() {
|
||||
ui.output().mutable_text_under_cursor = true;
|
||||
}
|
||||
|
||||
// TODO: triple-click to select whole paragraph
|
||||
// TODO: drag selected text to either move or clone (ctrl on windows, alt on mac)
|
||||
let singleline_offset = vec2(state.singleline_offset, 0.0);
|
||||
@@ -910,7 +914,9 @@ impl<'t> TextEdit<'t> {
|
||||
&cursorp.primary,
|
||||
);
|
||||
|
||||
if interactive {
|
||||
if interactive && text.is_mutable() {
|
||||
// egui_web uses `text_cursor_pos` when showing IME,
|
||||
// so only set it when text is editable!
|
||||
ui.ctx().output().text_cursor_pos = Some(
|
||||
galley
|
||||
.pos_from_cursor(&cursorp.primary)
|
||||
|
||||
Reference in New Issue
Block a user