Skip to main content

WidgetStateProperty

Struct WidgetStateProperty 

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

Source

pub fn new() -> Self

A property that answers nothing yet.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn is_empty(&self) -> bool

Has anything been said at all?

Trait Implementations§

Source§

impl<T: Clone> Clone for WidgetStateProperty<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for WidgetStateProperty<T>

Source§

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

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

impl<T> Default for WidgetStateProperty<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: PartialEq> PartialEq for WidgetStateProperty<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for WidgetStateProperty<T>

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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<Msg> IntoMsg<Msg> for Msg

Source§

fn defer(work: impl Fn() -> Msg + 'static) -> Msg

The message that stands for work’s result.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.