Skip to main content

MouseCursorSession

Trait MouseCursorSession 

Source
pub trait MouseCursorSession {
    // Required methods
    fn cursor(&self) -> MouseCursorRef;
    fn device(&self) -> i64;
    fn activate(&mut self, platform: &dyn Platform, view: ViewId);
    fn dispose(&mut self);
}
Expand description

Manages the duration that a pointing device should display a specific mouse cursor.

While MouseCursor classes describe the kind of cursors, MouseCursorSession classes represent a continuous use of the cursor on a pointing device. The MouseCursorSession classes can be stateful. For example, a cursor that needs to load resources might want to try a fallback cursor first, and switch to the target cursor when the resources are loaded.

A MouseCursorSession has the following lifecycle:

  • When a pointing device should start displaying a cursor, MouseTracker creates a session by calling MouseCursor::create_session on the target cursor, and stores it in a table associated with the device.
  • MouseTracker then immediately calls the session’s activate, where the session should fetch resources and make system calls.
  • When the pointing device should start displaying another cursor, MouseTracker calls dispose on this session. After dispose, this session will no longer be used in the future.

Required Methods§

Source

fn cursor(&self) -> MouseCursorRef

The cursor that created this session.

Source

fn device(&self) -> i64

The device ID of the pointing device.

Source

fn activate(&mut self, platform: &dyn Platform, view: ViewId)

Override this method to do the work of changing the cursor of the device.

Called right after this session is created.

This method has full control over the cursor until the dispose call, and can make system calls to change the pointer cursor as many times as necessary (usually through the system cursor request of the host of view, the one the device is on, which platform finds; a session that changes the cursor later keeps it).

Source

fn dispose(&mut self)

Called when device stops displaying the cursor.

After this call, this session instance will no longer be used in the future.

When implementing this method in subclasses, you should release resources and prevent activate from causing side effects after disposal.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§