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:
- Use
WidgetStateMouseCursor::resolve_withand pass in a callback that will be used to resolve the color in the given states. - Use
WidgetStateMouseCursor::from_mapto assign a value using aWidgetStateMap.
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:
MouseCursorfor introduction on the mouse cursor system.SystemMouseCursors, which defines cursors that are supported by native platforms.
Implementations§
Source§impl WidgetStateMouseCursor
impl WidgetStateMouseCursor
Sourcepub fn resolve_with(
callback: impl Fn(&WidgetStates) -> MouseCursorRef + 'static,
debug_description: Option<&str>,
) -> WidgetStateMouseCursor
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.
Sourcepub fn from_map(map: WidgetStateMap<MouseCursorRef>) -> WidgetStateMouseCursor
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).
Sourcepub fn clickable() -> WidgetStateMouseCursor
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.
Sourcepub fn adaptive_clickable() -> WidgetStateMouseCursor
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).
Sourcepub fn textable() -> WidgetStateMouseCursor
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
impl Debug for WidgetStateMouseCursor
Source§impl From<WidgetStateMouseCursor> for MouseCursorRef
impl From<WidgetStateMouseCursor> for MouseCursorRef
Source§fn from(cursor: WidgetStateMouseCursor) -> MouseCursorRef
fn from(cursor: WidgetStateMouseCursor) -> MouseCursorRef
Source§impl MouseCursor for WidgetStateMouseCursor
impl MouseCursor for WidgetStateMouseCursor
Source§fn create_session(&self, device: i64) -> Box<dyn MouseCursorSession>
fn create_session(&self, device: i64) -> Box<dyn MouseCursorSession>
Source§fn debug_description(&self) -> String
fn debug_description(&self) -> String
Source§fn eq_cursor(&self, other: &dyn MouseCursor) -> bool
fn eq_cursor(&self, other: &dyn MouseCursor) -> bool
==. Identity unless a class overrides it, as SystemMouseCursor does.Source§impl WidgetStateProperty<Rc<dyn MouseCursor>> for WidgetStateMouseCursor
impl WidgetStateProperty<Rc<dyn MouseCursor>> for WidgetStateMouseCursor
Source§fn resolve(&self, states: &WidgetStates) -> MouseCursorRef
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_mapper(&self) -> Option<&WidgetStateMapper<MouseCursorRef>>
fn as_mapper(&self) -> Option<&WidgetStateMapper<MouseCursorRef>>
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
fn eq_property(&self, other: &dyn WidgetStateProperty<MouseCursorRef>) -> bool
==. Identity unless a class overrides it, as WidgetStatePropertyAll and
WidgetStateMapper do.Source§fn debug_fill_properties(&self, properties: &mut DiagnosticPropertiesBuilder)
fn debug_fill_properties(&self, properties: &mut DiagnosticPropertiesBuilder)
WidgetStateProperty.debugFillProperties, from Diagnosticable: a property
adds its own fields.