Skip to main content

MouseTracker

Struct MouseTracker 

Source
pub struct MouseTracker { /* private fields */ }
Expand description

Tracks the relationship between mouse devices and annotations, and triggers mouse events and cursor changes accordingly.

The MouseTracker tracks the relationship between mouse devices and MouseTrackerAnnotation, notified by update_with_event and update_all_devices. At every update, MouseTracker triggers the following changes if applicable:

  • Dispatches mouse-related pointer events (pointer enter, hover, and exit).
  • Changes mouse cursors.
  • Notifies when mouse_is_connected changes.

This class is a ChangeNotifier that notifies its listeners if the value of mouse_is_connected changes.

An instance of MouseTracker is owned by the global singleton RendererBinding.

Implementations§

Source§

impl MouseTracker

Source

pub fn new( app: &mut App, hit_test_in_view: MouseTrackerHitTest, ) -> Handle<MouseTracker>

Create a mouse tracker.

The hit_test_in_view is used to find the render objects on a given position in the specific view. It is typically provided by the RendererBinding.

Source

pub fn dispose(self: Handle<Self>, app: &mut App)

Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded.

Source

pub fn mouse_is_connected(self: Handle<Self>, app: &App) -> bool

Whether or not at least one mouse is connected and has produced events.

Source

pub fn update_with_event( self: Handle<Self>, app: &mut App, event: &PointerEvent, hit_test_result: Option<&HitTestResult>, )

Perform a device update for one device according to the given new event.

The update_with_event is typically called by the RendererBinding during the handler of a pointer event. All pointer events should call this method, and let MouseTracker filter which to react to.

The hit_test_result serves as an optional optimization, and is the hit test result already performed by the RendererBinding for other gestures. It can be None, but when it’s not None, it should be identical to the result from directly calling hit_test_in_view given in the constructor (which means that it must not use the cached result for PointerEvent::Move).

The update_with_event is one of the two ways of updating mouse states, the other one being update_all_devices.

Source

pub fn update_all_devices(self: Handle<Self>, app: &mut App)

Perform a device update for all devices.

This is called by the RendererBinding after a frame, since the render tree might have changed under a still mouse.

The update_all_devices is one of the two ways of updating mouse states, the other one being update_with_event.

Source

pub fn debug_device_active_cursor( self: Handle<Self>, app: &App, device: i64, ) -> Option<MouseCursorRef>

Returns the active mouse cursor for a device.

The return value is the last MouseCursorRef activated onto this device, even if the activation failed.

This function is only active in debug mode: in release it returns None.

Trait Implementations§

Source§

impl ChangeNotifier for MouseTracker

Source§

fn change_notifier_data(&self) -> &ChangeNotifierData

Source§

fn change_notifier_data_mut(&mut self) -> &mut ChangeNotifierData

Source§

fn will_add_listener(self: Handle<Self>, app: &mut App)

Runs before the listener is stored. Dart overrides of addListener that work before super.addListener go here.
Source§

fn did_remove_listener(self: Handle<Self>, app: &mut App)

Runs after the listener is removed. Dart overrides of removeListener that work after super.removeListener go here.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ListenableObject for T
where T: ChangeNotifier,

Source§

fn add_listener(self: Handle<T>, app: &mut App, listener: Listener)

Register a closure to be called when the object notifies its listeners.
Source§

fn remove_listener(self: Handle<T>, app: &mut App, listener: &Listener)

Remove a previously registered closure from the list of closures that the object notifies.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>