Prevent text selection
This commit is contained in:
parent
a134a59917
commit
964e342f69
4 changed files with 39 additions and 28 deletions
|
|
@ -235,13 +235,21 @@ impl Canvas {
|
|||
.on_mouse_release(&self.common, mouse_handler, touch_handler)
|
||||
}
|
||||
|
||||
pub fn on_mouse_press<M, T>(&mut self, mouse_handler: M, touch_handler: T)
|
||||
where
|
||||
pub fn on_mouse_press<M, T>(
|
||||
&mut self,
|
||||
mouse_handler: M,
|
||||
touch_handler: T,
|
||||
prevent_default: bool,
|
||||
) where
|
||||
M: 'static + FnMut(i32, PhysicalPosition<f64>, MouseButton, ModifiersState),
|
||||
T: 'static + FnMut(i32, PhysicalPosition<f64>, Force),
|
||||
{
|
||||
self.pointer_handler
|
||||
.on_mouse_press(&self.common, mouse_handler, touch_handler)
|
||||
self.pointer_handler.on_mouse_press(
|
||||
&self.common,
|
||||
mouse_handler,
|
||||
touch_handler,
|
||||
prevent_default,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn on_cursor_move<MOD, M, T, B>(
|
||||
|
|
|
|||
|
|
@ -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()),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue