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:
parent
ab0f0b7b64
commit
943e3618fc
|
|
@ -796,13 +796,16 @@ impl Galley {
|
|||
/// same as a cursor at the end.
|
||||
/// This allows implementing text-selection by dragging above/below the galley.
|
||||
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 pos.y < first_row.min_y() {
|
||||
if pos.y < first_row.min_y() - VMARGIN {
|
||||
return self.begin();
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue