mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 21:30:03 -04:00
TextEdit: click to move cursor
This commit is contained in:
@@ -2,7 +2,8 @@ use crate::*;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, serde_derive::Deserialize, serde_derive::Serialize)]
|
||||
pub(crate) struct State {
|
||||
/// Charctaer based, NOT bytes
|
||||
/// Charctaer based, NOT bytes.
|
||||
/// TODO: store as line + row
|
||||
pub cursor: Option<usize>,
|
||||
}
|
||||
|
||||
@@ -62,6 +63,9 @@ impl<'t> Widget for TextEdit<'t> {
|
||||
|
||||
if interact.clicked {
|
||||
ui.request_kb_focus(id);
|
||||
if let Some(mouse_pos) = ui.input().mouse_pos {
|
||||
state.cursor = Some(galley.char_at(mouse_pos - interact.rect.min));
|
||||
}
|
||||
}
|
||||
if interact.hovered {
|
||||
ui.output().cursor_icon = CursorIcon::Text;
|
||||
|
||||
Reference in New Issue
Block a user