Skip to main content

WidgetStateMouseCursor

Struct WidgetStateMouseCursor 

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

Defines a MouseCursor whose value depends on a set of WidgetStates which represent the interactive state of a component.

This kind of MouseCursor is useful when the set of interactive actions a widget supports varies with its state. For example, a mouse pointer hovering over a disabled ListTile should not display SystemMouseCursors::CLICK, since a disabled list tile doesn’t respond to mouse clicks. ListTile’s default mouse cursor is a WidgetStateMouseCursor::clickable, which resolves to SystemMouseCursors::BASIC when the button is disabled.

This class should only be used for parameters that document their support for WidgetStateMouseCursor.

A WidgetStateMouseCursor can be created in one of the following ways:

  1. Use WidgetStateMouseCursor::resolve_with and pass in a callback that will be used to resolve the color in the given states.
  2. Use WidgetStateMouseCursor::from_map to assign a value using a WidgetStateMap.

This example defines a mouse cursor that resolves to SystemMouseCursors::FORBIDDEN when its widget is disabled.

let cursor = WidgetStateMouseCursor::resolve_with(
    |states| {
        if states.contains(&WidgetState::Disabled) {
            return SystemMouseCursors::FORBIDDEN.into();
        }
        SystemMouseCursors::CLICK.into()
    },
    None,
);

It is the MouseCursor it is in Dart once erased with .into(): a MouseCursorRef recovered with cursor.as_any().downcast_ref::<WidgetStateMouseCursor>().

See also:

Implementations§

Source§

impl WidgetStateMouseCursor

Source

pub fn resolve_with( callback: impl Fn(&WidgetStates) -> MouseCursorRef + 'static, debug_description: Option<&str>, ) -> WidgetStateMouseCursor

Creates a WidgetStateMouseCursor using a WidgetPropertyResolver callback.

A debug_description may optionally be provided (Dart’s default is 'WidgetStateMouseCursor()').

If used as a regular MouseCursor, the cursor resolved in the default state (the empty set of states) will be used.

Source

pub fn from_map(map: WidgetStateMap<MouseCursorRef>) -> WidgetStateMouseCursor

Creates a WidgetStateMouseCursor from a WidgetStateMap.

This constructor’s resolve method finds the first entry whose key is satisfied by the set of states, and returns its associated value. It should only be used with classes that document support for WidgetStateMouseCursor (panics if used as a regular MouseCursor with no key satisfied by the empty set of states).

Source

pub fn clickable() -> WidgetStateMouseCursor

A mouse cursor for clickable widgets, which resolves differently when the widget is disabled.

By default this cursor resolves to SystemMouseCursors::CLICK. If the widget is disabled, the cursor resolves to SystemMouseCursors::BASIC.

Source

pub fn adaptive_clickable() -> WidgetStateMouseCursor

A platform-adaptive mouse cursor for clickable widgets, which resolves differently based on the widget’s state and the platform.

On web platforms, this cursor resolves to SystemMouseCursors::CLICK by default. If the widget is disabled, it resolves to SystemMouseCursors::BASIC.

On non-web platforms, this cursor always resolves to SystemMouseCursors::BASIC.

This cursor is commonly used for interactive widgets like buttons. The difference in behavior across platforms reflects native conventions (e.g., web uses a hand pointer for buttons, while desktop platforms do not).

Source

pub fn textable() -> WidgetStateMouseCursor

A mouse cursor for widgets related to text, which resolves differently when the widget is disabled.

By default this cursor resolves to SystemMouseCursors::TEXT. If the widget is disabled, the cursor resolves to SystemMouseCursors::BASIC.

This cursor is the default for many widgets.

Trait Implementations§

Source§

impl Debug for WidgetStateMouseCursor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<WidgetStateMouseCursor> for MouseCursorRef

Source§

fn from(cursor: WidgetStateMouseCursor) -> MouseCursorRef

Converts to this type from the input type.
Source§

impl MouseCursor for WidgetStateMouseCursor

Source§

fn create_session(&self, device: i64) -> Box<dyn MouseCursorSession>

Associate a pointing device to this cursor. Read more
Source§

fn debug_description(&self) -> String

A very short description of the mouse cursor. Read more
Source§

fn as_any(&self) -> &dyn Any

Downcast support for Dart’s == between cursor classes.
Source§

fn eq_cursor(&self, other: &dyn MouseCursor) -> bool

Dart’s ==. Identity unless a class overrides it, as SystemMouseCursor does.
Source§

fn is_defer(&self) -> bool

Whether this is MouseCursor.defer.
Source§

impl WidgetStateProperty<Rc<dyn MouseCursor>> for WidgetStateMouseCursor

Source§

fn resolve(&self, states: &WidgetStates) -> MouseCursorRef

Returns a MouseCursor that’s to be used when a component is in the specified state.

Source§

fn as_any(&self) -> &dyn Any

Downcast support for Dart’s is checks in ==.
Source§

fn as_mapper(&self) -> Option<&WidgetStateMapper<MouseCursorRef>>

Dart’s other is WidgetStateMapper<T>: the mapper this property is, if it is one, as the private mapper subclasses of WidgetStateColor and the rest are.
Source§

fn eq_property(&self, other: &dyn WidgetStateProperty<MouseCursorRef>) -> bool

Dart’s ==. Identity unless a class overrides it, as WidgetStatePropertyAll and WidgetStateMapper do.
Source§

fn debug_fill_properties(&self, properties: &mut DiagnosticPropertiesBuilder)

Dart’s WidgetStateProperty.debugFillProperties, from Diagnosticable: a property adds its own fields.

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> 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>