pub struct WidgetStateProperty<T> { /* private fields */ }Expand description
A value chosen by the states a widget is in (widget_state.dart:821).
Entries are tried in order and the first match wins, which is the reference’s
WidgetStateMapper (widget_state.dart:1009) and the reason order is worth
thinking about: put the narrow cases first.
use frus_core::Color;
use frus_widgets::{WidgetState, WidgetStateProperty, WidgetStates};
let ink = WidgetStateProperty::new()
.when(WidgetState::Pressed, Color::rgb8(200, 0, 0))
.when(WidgetState::Hovered, Color::rgb8(240, 120, 120))
.otherwise(Color::TRANSPARENT);
// Held *and* hovered, as a pressed widget always is: the narrower entry answers.
let held = WidgetState::Pressed | WidgetState::Hovered;
assert_eq!(ink.resolve(held), Some(&Color::rgb8(200, 0, 0)));
assert_eq!(ink.resolve(WidgetStates::EMPTY), Some(&Color::TRANSPARENT));A property built from closures — the reference’s resolveWith — is deliberately
not offered. A map is Clone, Debug and comparable, which is what a widget tree
that is rebuilt and diffed every frame needs; a boxed closure is none of the three,
and the reference itself documents the map as the form to reach for.
Implementations§
Source§impl<T> WidgetStateProperty<T>
impl<T> WidgetStateProperty<T>
Sourcepub fn all(value: T) -> Self
pub fn all(value: T) -> Self
The same value whatever the widget is doing — the reference’s
WidgetStatePropertyAll (widget_state.dart:1077), and what a caller who has one
colour and an API that wants a property reaches for.
Sourcepub fn when(self, filter: impl Into<StateFilter>, value: T) -> Self
pub fn when(self, filter: impl Into<StateFilter>, value: T) -> Self
The value to use when filter is satisfied, tried after everything already
added and before everything added later.
Sourcepub fn otherwise(self, value: T) -> Self
pub fn otherwise(self, value: T) -> Self
The value to use when nothing above matched. Anything added after it is
unreachable, Any being satisfied by every set.
Sourcepub fn resolve(&self, states: WidgetStates) -> Option<&T>
pub fn resolve(&self, states: WidgetStates) -> Option<&T>
The first value whose filter these states satisfy, or None when none does —
which means say nothing, and leaves the widget or the theme to answer, exactly
as the reference’s nullable properties do.