ferroui_base/input/i_pointer.rs
1use super::InputElement;
2use crate::Ref;
3use std::any::Any;
4
5/// Identifies a specific input pointer, e.g. a mouse, a touch contact or a
6/// pen.
7pub trait IPointer {
8 /// The unique identifier of the pointer.
9 fn id(&self) -> i32;
10
11 /// Captures pointer input to the specified control.
12 ///
13 /// When an element captures the pointer, it receives pointer input
14 /// whether the cursor is within the control's bounds or not. The current
15 /// pointer capture control is exposed by [`captured`](Self::captured).
16 fn capture(&self, control: Option<&Ref<InputElement>>);
17
18 /// The control that is currently capturing the pointer, if any.
19 fn captured(&self) -> Option<Ref<InputElement>>;
20
21 /// The type of the pointer.
22 fn type_(&self) -> PointerType;
23
24 /// Whether the pointer is the primary pointer of its type.
25 fn is_primary(&self) -> bool;
26
27 /// The pointer as [`Any`], for downcasting to the concrete pointer.
28 fn as_any(&self) -> &dyn Any;
29}
30
31/// Enumerates the types of pointer devices.
32#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
33pub enum PointerType {
34 /// The pointer device is a mouse.
35 #[default]
36 Mouse,
37 /// The pointer device is a touch contact.
38 Touch,
39 /// The pointer device is a pen.
40 Pen,
41}