mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 22:00:03 -04:00
Improve drag-to-select text (add margins) (#5797)
Might want to draw from `interaction.interact_radius` style instead of hard-coding the margin, but I didn't want to create a breaking change. If desired, I can follow up with a separate PR to address that concern. * Closes <https://github.com/emilk/egui/issues/5796> * [x] I have followed the instructions in the PR template
This commit is contained in:
@@ -796,13 +796,16 @@ impl Galley {
|
|||||||
/// same as a cursor at the end.
|
/// same as a cursor at the end.
|
||||||
/// This allows implementing text-selection by dragging above/below the galley.
|
/// This allows implementing text-selection by dragging above/below the galley.
|
||||||
pub fn cursor_from_pos(&self, pos: Vec2) -> CCursor {
|
pub fn cursor_from_pos(&self, pos: Vec2) -> CCursor {
|
||||||
|
// Vertical margin around galley improves text selection UX
|
||||||
|
const VMARGIN: f32 = 5.0;
|
||||||
|
|
||||||
if let Some(first_row) = self.rows.first() {
|
if let Some(first_row) = self.rows.first() {
|
||||||
if pos.y < first_row.min_y() {
|
if pos.y < first_row.min_y() - VMARGIN {
|
||||||
return self.begin();
|
return self.begin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(last_row) = self.rows.last() {
|
if let Some(last_row) = self.rows.last() {
|
||||||
if last_row.max_y() < pos.y {
|
if last_row.max_y() + VMARGIN < pos.y {
|
||||||
return self.end();
|
return self.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user