Prevent text selection

This commit is contained in:
dAxpeDDa 2023-06-04 01:50:30 +02:00 committed by daxpedda
parent a134a59917
commit 964e342f69
4 changed files with 39 additions and 28 deletions

View file

@ -104,6 +104,7 @@ impl PointerHandler {
canvas_common: &Common,
mut mouse_handler: M,
mut touch_handler: T,
prevent_default: bool,
) where
M: 'static + FnMut(i32, PhysicalPosition<f64>, MouseButton, ModifiersState),
T: 'static + FnMut(i32, PhysicalPosition<f64>, Force),
@ -112,6 +113,13 @@ impl PointerHandler {
self.on_pointer_press = Some(canvas_common.add_user_event(
"pointerdown",
move |event: PointerEvent| {
if prevent_default {
// prevent text selection
event.prevent_default();
// but still focus element
let _ = canvas.focus();
}
match event.pointer_type().as_str() {
"touch" => {
touch_handler(
@ -192,6 +200,13 @@ impl PointerHandler {
"expect pointer type of a chorded button event to be a mouse"
);
if prevent_default {
// prevent text selection
event.prevent_default();
// but still focus element
let _ = canvas.focus();
}
button_handler(
id,
event::mouse_position(&event).to_physical(super::scale_factor()),