pub trait Var<T: VarValue>:
IntoVar<T, Var = Self>
+ AnyVar
+ Clone {
type ReadOnly: Var<T>;
type ActualVar: Var<T>;
type Downgrade: WeakVar<T>;
type Map<O: VarValue>: Var<O>;
type MapBidi<O: VarValue>: Var<O>;
type FlatMap<O: VarValue, V: Var<O>>: Var<O>;
type FilterMap<O: VarValue>: Var<O>;
type FilterMapBidi<O: VarValue>: Var<O>;
type MapRef<O: VarValue>: Var<O>;
type MapRefBidi<O: VarValue>: Var<O>;
type Easing: Var<T>;
Show 69 methods
// Required methods
fn with<R, F>(&self, read: F) -> R
where F: FnOnce(&T) -> R;
fn modify<F>(&self, modify: F) -> Result<(), VarIsReadOnlyError>
where F: FnOnce(&mut VarModify<'_, T>) + Send + 'static;
fn actual_var(self) -> Self::ActualVar;
fn downgrade(&self) -> Self::Downgrade;
fn into_value(self) -> T;
fn read_only(&self) -> Self::ReadOnly;
fn map<O, M>(&self, map: M) -> Self::Map<O>
where O: VarValue,
M: FnMut(&T) -> O + Send + 'static;
fn map_bidi<O, M, B>(&self, map: M, map_back: B) -> Self::MapBidi<O>
where O: VarValue,
M: FnMut(&T) -> O + Send + 'static,
B: FnMut(&O) -> T + Send + 'static;
fn flat_map<O, V, M>(&self, map: M) -> Self::FlatMap<O, V>
where O: VarValue,
V: Var<O>,
M: FnMut(&T) -> V + Send + 'static;
fn filter_map<O, M, I>(&self, map: M, fallback: I) -> Self::FilterMap<O>
where O: VarValue,
M: FnMut(&T) -> Option<O> + Send + 'static,
I: Fn() -> O + Send + Sync + 'static;
fn filter_map_bidi<O, M, B, I>(
&self,
map: M,
map_back: B,
fallback: I,
) -> Self::FilterMapBidi<O>
where O: VarValue,
M: FnMut(&T) -> Option<O> + Send + 'static,
B: FnMut(&O) -> Option<T> + Send + 'static,
I: Fn() -> O + Send + Sync + 'static;
fn map_ref<O, M>(&self, map: M) -> Self::MapRef<O>
where O: VarValue,
M: Fn(&T) -> &O + Send + Sync + 'static;
fn map_ref_bidi<O, M, B>(&self, map: M, map_mut: B) -> Self::MapRefBidi<O>
where O: VarValue,
M: Fn(&T) -> &O + Send + Sync + 'static,
B: Fn(&mut T) -> &mut O + Send + Sync + 'static;
fn easing<F>(&self, duration: Duration, easing: F) -> Self::Easing
where T: Transitionable,
F: Fn(EasingTime) -> EasingStep + Send + Sync + 'static;
fn easing_with<F, S>(
&self,
duration: Duration,
easing: F,
sampler: S,
) -> Self::Easing
where T: Transitionable,
F: Fn(EasingTime) -> EasingStep + Send + Sync + 'static,
S: Fn(&Transition<T>, EasingStep) -> T + Send + Sync + 'static;
// Provided methods
fn boxed(self) -> BoxedVar<T>
where Self: Sized { ... }
fn boxed_any(self) -> BoxedAnyVar
where Self: Sized { ... }
fn hook(
&self,
pos_modify_action: impl Fn(&VarHookArgs<'_, T>) -> bool + Send + Sync + 'static,
) -> VarHandle { ... }
fn wait_update(&self) -> impl Future<Output = VarUpdateId> + Send + Sync { ... }
fn wait_animation(&self) -> impl Future<Output = ()> + Send + Sync { ... }
fn wait_value(
&self,
predicate: impl Fn(&T) -> bool + Send + Sync,
) -> impl Future<Output = ()> + Send + Sync { ... }
fn with_new<R, F>(&self, read: F) -> Option<R>
where F: FnOnce(&T) -> R { ... }
fn get(&self) -> T { ... }
fn get_txt(&self) -> Txt
where T: Display { ... }
fn get_string(&self) -> String
where T: Display { ... }
fn get_into(&self, value: &mut T) { ... }
fn get_ne(&self, value: &mut T) -> bool { ... }
fn get_new(&self) -> Option<T> { ... }
fn get_new_into(&self, value: &mut T) -> bool { ... }
fn get_new_ne(&self, value: &mut T) -> bool { ... }
fn set<I>(&self, value: I) -> Result<(), VarIsReadOnlyError>
where I: Into<T> { ... }
fn set_from<I>(&self, other: &I) -> Result<(), VarIsReadOnlyError>
where I: Var<T> { ... }
fn set_from_map<Iv, I, M>(
&self,
other: &I,
map: M,
) -> Result<(), VarIsReadOnlyError>
where Iv: VarValue,
I: Var<Iv>,
M: FnOnce(&Iv) -> T + Send + 'static { ... }
fn cow(&self) -> ArcCowVar<T, Self> { ... }
fn map_into<O>(&self) -> Self::Map<O>
where O: VarValue,
T: Into<O> { ... }
fn map_to_txt(&self) -> Self::Map<Txt>
where T: ToTxt { ... }
fn map_to_string(&self) -> Self::Map<String>
where T: ToString { ... }
fn filter_try_into<O, I>(&self, fallback: I) -> Self::FilterMap<O>
where O: VarValue,
T: TryInto<O>,
I: Fn() -> O + Send + Sync + 'static { ... }
fn filter_parse<O, I>(&self, fallback: I) -> Self::FilterMap<O>
where O: VarValue + FromStr,
T: AsRef<str>,
I: Fn() -> O + Send + Sync + 'static { ... }
fn bind_map<T2, V2, M>(&self, other: &V2, map: M) -> VarHandle
where T2: VarValue,
V2: Var<T2>,
M: FnMut(&T) -> T2 + Send + 'static { ... }
fn bind_filter_map<T2, V2, F>(&self, other: &V2, map: F) -> VarHandle
where T2: VarValue,
V2: Var<T2>,
F: FnMut(&T) -> Option<T2> + Send + 'static { ... }
fn bind_map_bidi<T2, V2, M, B>(
&self,
other: &V2,
map: M,
map_back: B,
) -> VarHandles
where T2: VarValue,
V2: Var<T2>,
M: FnMut(&T) -> T2 + Send + 'static,
B: FnMut(&T2) -> T + Send + 'static { ... }
fn bind_filter_map_bidi<T2, V2, M, B>(
&self,
other: &V2,
map: M,
map_back: B,
) -> VarHandles
where T2: VarValue,
V2: Var<T2>,
M: FnMut(&T) -> Option<T2> + Send + 'static,
B: FnMut(&T2) -> Option<T> + Send + 'static { ... }
fn bind<V2>(&self, other: &V2) -> VarHandle
where V2: Var<T> { ... }
fn set_bind<V2>(&self, other: &V2) -> VarHandle
where V2: Var<T> { ... }
fn bind_bidi<V2>(&self, other: &V2) -> VarHandles
where V2: Var<T> { ... }
fn trace_value<E, S>(&self, enter_value: E) -> VarHandle
where E: FnMut(&TraceValueArgs<'_, T>) -> S + Send + 'static,
S: Send + 'static { ... }
fn animate<A>(&self, animate: A) -> AnimationHandle
where A: FnMut(&Animation, &mut VarModify<'_, T>) + Send + 'static { ... }
fn sequence<A>(&self, animate: A) -> VarHandle
where A: FnMut(&<<Self::ActualVar as Var<T>>::Downgrade as WeakVar<T>>::Upgrade) -> AnimationHandle + Send + 'static { ... }
fn set_ease<S, E, F>(
&self,
start_value: S,
end_value: E,
duration: Duration,
easing: F,
) -> AnimationHandle
where T: Transitionable,
S: Into<T>,
E: Into<T>,
F: Fn(EasingTime) -> EasingStep + Send + 'static { ... }
fn set_ease_oci<S, E, F>(
&self,
start_value: S,
end_value: E,
duration: Duration,
easing: F,
) -> AnimationHandle
where T: Transitionable,
S: Into<T>,
E: Into<T>,
F: Fn(EasingTime) -> EasingStep + Send + 'static { ... }
fn set_ease_with<S, E, F, Sa>(
&self,
start_value: S,
end_value: E,
duration: Duration,
easing: F,
sampler: Sa,
) -> AnimationHandle
where T: Transitionable,
S: Into<T>,
E: Into<T>,
F: Fn(EasingTime) -> EasingStep + Send + 'static,
Sa: Fn(&Transition<T>, EasingStep) -> T + Send + 'static { ... }
fn set_ease_oci_with<S, E, F, Sa>(
&self,
start_value: S,
end_value: E,
duration: Duration,
easing: F,
sampler: Sa,
) -> AnimationHandle
where T: Transitionable,
S: Into<T>,
E: Into<T>,
F: Fn(EasingTime) -> EasingStep + Send + 'static,
Sa: Fn(&Transition<T>, EasingStep) -> T + Send + 'static { ... }
fn ease<E, F>(
&self,
new_value: E,
duration: Duration,
easing: F,
) -> AnimationHandle
where T: Transitionable,
E: Into<T>,
F: Fn(EasingTime) -> EasingStep + Send + 'static { ... }
fn ease_oci<E, F>(
&self,
new_value: E,
duration: Duration,
easing: F,
) -> AnimationHandle
where T: Transitionable,
E: Into<T>,
F: Fn(EasingTime) -> EasingStep + Send + 'static { ... }
fn ease_with<E, F, S>(
&self,
new_value: E,
duration: Duration,
easing: F,
sampler: S,
) -> AnimationHandle
where T: Transitionable,
E: Into<T>,
F: Fn(EasingTime) -> EasingStep + Send + 'static,
S: Fn(&Transition<T>, EasingStep) -> T + Send + 'static { ... }
fn ease_oci_with<E, F, S>(
&self,
new_value: E,
duration: Duration,
easing: F,
sampler: S,
) -> AnimationHandle
where T: Transitionable,
E: Into<T>,
F: Fn(EasingTime) -> EasingStep + Send + 'static,
S: Fn(&Transition<T>, EasingStep) -> T + Send + 'static { ... }
fn set_ease_keyed<F>(
&self,
keys: Vec<(Factor, T)>,
duration: Duration,
easing: F,
) -> AnimationHandle
where T: Transitionable,
F: Fn(EasingTime) -> EasingStep + Send + 'static { ... }
fn set_ease_keyed_with<F, S>(
&self,
keys: Vec<(Factor, T)>,
duration: Duration,
easing: F,
sampler: S,
) -> AnimationHandle
where T: Transitionable,
F: Fn(EasingTime) -> EasingStep + Send + 'static,
S: Fn(&TransitionKeyed<T>, EasingStep) -> T + Send + 'static { ... }
fn ease_keyed<F>(
&self,
keys: Vec<(Factor, T)>,
duration: Duration,
easing: F,
) -> AnimationHandle
where T: Transitionable,
F: Fn(EasingTime) -> EasingStep + Send + 'static { ... }
fn ease_keyed_with<F, S>(
&self,
keys: Vec<(Factor, T)>,
duration: Duration,
easing: F,
sampler: S,
) -> AnimationHandle
where T: Transitionable,
F: Fn(EasingTime) -> EasingStep + Send + 'static,
S: Fn(&TransitionKeyed<T>, EasingStep) -> T + Send + 'static { ... }
fn step<N>(&self, new_value: N, delay: Duration) -> AnimationHandle
where N: Into<T> { ... }
fn step_oci<N>(&self, new_value: N, delay: Duration) -> AnimationHandle
where N: Into<T> { ... }
fn set_step_oci<V0, V1>(
&self,
from: V0,
to: V1,
delay: Duration,
) -> AnimationHandle
where V0: Into<T>,
V1: Into<T> { ... }
fn steps<F>(
&self,
steps: Vec<(Factor, T)>,
duration: Duration,
easing: F,
) -> AnimationHandle
where F: Fn(EasingTime) -> EasingStep + Send + 'static { ... }
fn chase<N, F>(
&self,
first_target: N,
duration: Duration,
easing: F,
) -> ChaseAnimation<T>
where N: Into<T>,
F: Fn(EasingTime) -> EasingStep + Send + 'static,
T: Transitionable { ... }
fn debug(&self) -> VarDebug<'_, T, Self> { ... }
fn display(&self) -> VarDisplay<'_, T, Self>
where T: Display { ... }
fn hold<V>(&self, value: V) -> VarHandle
where V: Any + Send { ... }
}
Expand description
Represents an observable value.
Variable types can have different capabilities, all can provide a value, in some the value can update, some
are read-only others allow modifying the value. Variables can also be contextual, meaning they have a different
value depending on the context where they are used. This trait covers all these capabilities, together with
IntoVar<T>
it enables properties to be very flexible on what input they accept.
See AnyVar
for the object safe part of variables.
This trait is sealed and cannot be implemented for types outside of this crate.
Required Associated Types§
sourcetype ReadOnly: Var<T>
type ReadOnly: Var<T>
Output of Var::read_only
.
sourcetype ActualVar: Var<T>
type ActualVar: Var<T>
Output of Var::actual_var
.
sourcetype Downgrade: WeakVar<T>
type Downgrade: WeakVar<T>
Output of Var::downgrade
.
sourcetype MapBidi<O: VarValue>: Var<O>
type MapBidi<O: VarValue>: Var<O>
Output of Var::map_bidi
.
sourcetype FilterMap<O: VarValue>: Var<O>
type FilterMap<O: VarValue>: Var<O>
Output of Var::filter_map
.
sourcetype FilterMapBidi<O: VarValue>: Var<O>
type FilterMapBidi<O: VarValue>: Var<O>
Output of Var::filter_map_bidi
.
sourcetype MapRef<O: VarValue>: Var<O>
type MapRef<O: VarValue>: Var<O>
Output of Var::map_ref
.
sourcetype MapRefBidi<O: VarValue>: Var<O>
type MapRefBidi<O: VarValue>: Var<O>
Output of Var::map_ref_bidi
.
sourcetype Easing: Var<T>
type Easing: Var<T>
Output of Var::easing
.
Required Methods§
sourcefn modify<F>(&self, modify: F) -> Result<(), VarIsReadOnlyError>
fn modify<F>(&self, modify: F) -> Result<(), VarIsReadOnlyError>
Schedule a variable update, it will be applied on the end of the current app update.
sourcefn actual_var(self) -> Self::ActualVar
fn actual_var(self) -> Self::ActualVar
Gets the current inner var represented by this var. This can be the same var or a context var.
sourcefn into_value(self) -> T
fn into_value(self) -> T
Convert this variable to the value, if possible moves the value, if it is shared clones it.
sourcefn read_only(&self) -> Self::ReadOnly
fn read_only(&self) -> Self::ReadOnly
Gets a clone of the var that is always read-only.
The returned variable can still update if self
is modified, but it does not have the MODIFY
capability.
sourcefn map<O, M>(&self, map: M) -> Self::Map<O>
fn map<O, M>(&self, map: M) -> Self::Map<O>
Creates a var that maps from this variable.
The map
closure is called once on initialization, and then once every time
the source variable updates.
The mapping variable is read-only, you can use map_bidi
to map back.
Note that the mapping var can be contextualized for context vars, meaning the map binding will initialize in
the fist usage context, not the creation context, so property = CONTEXT_VAR.map(|&b|!b);
will bind with
the CONTEXT_VAR
in the property
context, not the property instantiation. The map
closure itself runs in
the root app context, trying to read other context variables inside it will only read the default value.
For other variables types the map
can run once in the caller context.
If self
can change the output variable will keep it alive, this is to support chaining maps.
sourcefn map_bidi<O, M, B>(&self, map: M, map_back: B) -> Self::MapBidi<O>
fn map_bidi<O, M, B>(&self, map: M, map_back: B) -> Self::MapBidi<O>
Create a var that maps from this variable on read and to it on write.
The map
closure is called once on initialization, and then once every time
the source variable updates, the map_back
closure is called every time the output value is modified directly.
The mapping var can be contextualized, see Var::map
for more details.
If self
can change the output variable will keep it alive, this is to support chaining maps.
sourcefn flat_map<O, V, M>(&self, map: M) -> Self::FlatMap<O, V>
fn flat_map<O, V, M>(&self, map: M) -> Self::FlatMap<O, V>
Create a var that maps to an inner variable that is found inside the value of this variable.
The mapping var can be contextualized if self is contextual, otherwise map
evaluates immediately to start. Note
that the “mapped-to” var can be contextual even when the mapping var is not.
The mapping var has the same capabilities of the inner var, plus CAPS_CHANGE
, modifying the mapping var modifies the inner var.
If self
can change the output variable will keep it alive, this is to support chaining maps.
sourcefn filter_map<O, M, I>(&self, map: M, fallback: I) -> Self::FilterMap<O>
fn filter_map<O, M, I>(&self, map: M, fallback: I) -> Self::FilterMap<O>
Creates a ref-counted var that maps from this variable, but can retain a previous mapped value.
The map
closure is called once on initialization, if it returns None
the fallback
closure is called to generate
a fallback value, after, the map
closure is called once every time
the mapping variable reads and is out of sync with the source variable, if it returns Some(_)
the mapping variable value changes,
otherwise the previous value is retained.
The mapping variable is read-only, use filter_map_bidi
to map back.
The mapping var can be contextualized, see Var::map
for more details.
If self
can change the output variable will keep it alive, this is to support chaining maps.
sourcefn filter_map_bidi<O, M, B, I>(
&self,
map: M,
map_back: B,
fallback: I,
) -> Self::FilterMapBidi<O>
fn filter_map_bidi<O, M, B, I>( &self, map: M, map_back: B, fallback: I, ) -> Self::FilterMapBidi<O>
Create a var that maps from this variable on read and to it on write, mapping in both directions can skip updates, retaining the previous mapped value.
The map
closure is called once on initialization, if it returns None
the fallback
closure is called
to generate a fallback value, after, the map
closure is called once every time
the mapping variable reads and is out of sync with the source variable, if it returns Some(_)
the mapping variable value changes,
otherwise the previous value is retained. The map_back
closure
is called every time the output value is modified directly, if it returns Some(_)
the source variable is set.
The mapping var can be contextualized, see Var::map
for more details.
If self
can change the output variable will keep it alive, this is to support chaining maps.
sourcefn map_ref<O, M>(&self, map: M) -> Self::MapRef<O>
fn map_ref<O, M>(&self, map: M) -> Self::MapRef<O>
Create a mapping wrapper around self
. The map
closure is called for each value access, it must reference the
value O
that already exists in T
.
sourcefn map_ref_bidi<O, M, B>(&self, map: M, map_mut: B) -> Self::MapRefBidi<O>
fn map_ref_bidi<O, M, B>(&self, map: M, map_mut: B) -> Self::MapRefBidi<O>
Create a mapping wrapper around self
. The map
closure is called for each value access, it must reference the
value O
that already exists in T
, the map_mut
closure is called for every modify request, it must do the same
as map
but with mutable access.
sourcefn easing<F>(&self, duration: Duration, easing: F) -> Self::Easing
fn easing<F>(&self, duration: Duration, easing: F) -> Self::Easing
Create a vars that ease
to each new value of self
.
Note that the mapping var can be contextualized, see map
for more details.
If self
can change the output variable will keep it alive.
sourcefn easing_with<F, S>(
&self,
duration: Duration,
easing: F,
sampler: S,
) -> Self::Easingwhere
T: Transitionable,
F: Fn(EasingTime) -> EasingStep + Send + Sync + 'static,
S: Fn(&Transition<T>, EasingStep) -> T + Send + Sync + 'static,
fn easing_with<F, S>(
&self,
duration: Duration,
easing: F,
sampler: S,
) -> Self::Easingwhere
T: Transitionable,
F: Fn(EasingTime) -> EasingStep + Send + Sync + 'static,
S: Fn(&Transition<T>, EasingStep) -> T + Send + Sync + 'static,
Create a vars that ease_with
to each new value of self
.
Note that the mapping var can be contextualized, see map
for more details.
If self
can change the output variable will keep it alive.
Provided Methods§
sourcefn boxed(self) -> BoxedVar<T>where
Self: Sized,
fn boxed(self) -> BoxedVar<T>where
Self: Sized,
Gets the variable as a BoxedVar<T>
, does not double box.
sourcefn boxed_any(self) -> BoxedAnyVarwhere
Self: Sized,
fn boxed_any(self) -> BoxedAnyVarwhere
Self: Sized,
Gets the variable as a BoxedAnyVar
, does not double box.
sourcefn hook(
&self,
pos_modify_action: impl Fn(&VarHookArgs<'_, T>) -> bool + Send + Sync + 'static,
) -> VarHandle
fn hook( &self, pos_modify_action: impl Fn(&VarHookArgs<'_, T>) -> bool + Send + Sync + 'static, ) -> VarHandle
Setups a callback for just after the variable value update is applied, the closure runs in the root app context, just like
the modify
closure. The closure can return if it is retained after each call. If you modify another variable in a
hook the modification applies in the same update, variable mapping and binding is implemented using hooks.
The variable store a weak reference to the callback if it has the MODIFY
or CAPS_CHANGE
capabilities, otherwise
the callback is discarded and VarHandle::dummy
returned.
sourcefn wait_update(&self) -> impl Future<Output = VarUpdateId> + Send + Sync
fn wait_update(&self) -> impl Future<Output = VarUpdateId> + Send + Sync
Awaits for the last_update
to change.
Note that is_new
will be true
when the future elapses only when polled
in sync with the UI, but it will elapse in any thread when the variable updates after the future is instantiated.
Note that outside of the UI tree there is no variable synchronization across multiple var method calls, so
a sequence of get(); wait_update().await; get();
can miss a value between get
and wait_update
. The returned
future captures the last_update
at the moment this method is called, this can be leveraged by double-checking to
avoid race conditions, see the wait_value
default implementation for more details.
sourcefn wait_animation(&self) -> impl Future<Output = ()> + Send + Sync
fn wait_animation(&self) -> impl Future<Output = ()> + Send + Sync
Awaits for is_animating
to change from true
to false
.
If the variable is not animating at the moment of this call the future will await until the animation starts and stops.
sourcefn wait_value(
&self,
predicate: impl Fn(&T) -> bool + Send + Sync,
) -> impl Future<Output = ()> + Send + Sync
fn wait_value( &self, predicate: impl Fn(&T) -> bool + Send + Sync, ) -> impl Future<Output = ()> + Send + Sync
Awaits for a value that passes the predicate
.
sourcefn with_new<R, F>(&self, read: F) -> Option<R>
fn with_new<R, F>(&self, read: F) -> Option<R>
Visit the current value of the variable, if it is_new
.
sourcefn get_string(&self) -> Stringwhere
T: Display,
fn get_string(&self) -> Stringwhere
T: Display,
Gets the value as a display String
.
sourcefn get_ne(&self, value: &mut T) -> bool
fn get_ne(&self, value: &mut T) -> bool
Get a clone of the current value into value
if the current value is not equal to it.
sourcefn get_new_into(&self, value: &mut T) -> bool
fn get_new_into(&self, value: &mut T) -> bool
Get a clone of the current value into value
if the current value is_new
.
sourcefn get_new_ne(&self, value: &mut T) -> bool
fn get_new_ne(&self, value: &mut T) -> bool
Get a clone of the current value into value
if the variable value is_new
and not equal to the value
.
sourcefn set<I>(&self, value: I) -> Result<(), VarIsReadOnlyError>where
I: Into<T>,
fn set<I>(&self, value: I) -> Result<(), VarIsReadOnlyError>where
I: Into<T>,
Schedule a new value
for the variable, it will be set in the end of the current app update.
sourcefn set_from<I>(&self, other: &I) -> Result<(), VarIsReadOnlyError>where
I: Var<T>,
fn set_from<I>(&self, other: &I) -> Result<(), VarIsReadOnlyError>where
I: Var<T>,
Schedule a new value
for the variable, it will be set in the end of the current app update to the updated
value of other
, so if the other var has already scheduled an update, the updated value will be used.
This can be used in combination with binding to create a binding that starts with synchronized values.
sourcefn set_from_map<Iv, I, M>(
&self,
other: &I,
map: M,
) -> Result<(), VarIsReadOnlyError>
fn set_from_map<Iv, I, M>( &self, other: &I, map: M, ) -> Result<(), VarIsReadOnlyError>
Set from other
value at the time of update, mapped to the type of self
.
sourcefn cow(&self) -> ArcCowVar<T, Self>
fn cow(&self) -> ArcCowVar<T, Self>
Create a var that redirects to this variable until the first value update, then it behaves like a ArcVar<T>
.
The return variable is clone-on-write and has the MODIFY
capability independent of the source capabilities, when
a modify request is made the source value is cloned and offered for modification, if modified the source variable is dropped
and the cow var behaves like a ArcVar<T>
, if the modify closure does not update the cloned value it is dropped and the cow
continues to redirect to the source variable.
sourcefn map_to_txt(&self) -> Self::Map<Txt>where
T: ToTxt,
fn map_to_txt(&self) -> Self::Map<Txt>where
T: ToTxt,
sourcefn map_to_string(&self) -> Self::Map<String>where
T: ToString,
fn map_to_string(&self) -> Self::Map<String>where
T: ToString,
sourcefn filter_try_into<O, I>(&self, fallback: I) -> Self::FilterMap<O>
fn filter_try_into<O, I>(&self, fallback: I) -> Self::FilterMap<O>
Create a filter_map
that tries to convert from T
to O
using TryInto<O>
.
sourcefn filter_parse<O, I>(&self, fallback: I) -> Self::FilterMap<O>
fn filter_parse<O, I>(&self, fallback: I) -> Self::FilterMap<O>
Create a filter_map
that tries to convert from T
to O
using FromStr
.
sourcefn bind_map<T2, V2, M>(&self, other: &V2, map: M) -> VarHandle
fn bind_map<T2, V2, M>(&self, other: &V2, map: M) -> VarHandle
Setup a hook that assigns other
with the new values of self
transformed by map
.
Only a weak reference to the other
variable is held, both variables update in the same app update cycle.
Note that the current value is not assigned, only the subsequent updates, you can use set_from_map
to sync the initial value.
sourcefn bind_filter_map<T2, V2, F>(&self, other: &V2, map: F) -> VarHandle
fn bind_filter_map<T2, V2, F>(&self, other: &V2, map: F) -> VarHandle
Setup a hook that assigns other
with the new values of self
transformed by map
, if the closure returns a value.
Only a weak reference to the other
variable is held, both variables update in the same app update cycle.
Note that the current value is not assigned, only the subsequent updates, you can assign
other
and then bind to fully sync the variables.
sourcefn bind_map_bidi<T2, V2, M, B>(
&self,
other: &V2,
map: M,
map_back: B,
) -> VarHandles
fn bind_map_bidi<T2, V2, M, B>( &self, other: &V2, map: M, map_back: B, ) -> VarHandles
Bind self
to other
and back without causing an infinite loop.
Only a weak reference to each variable is held by the other, if both variables are scheduled to update in the same cycle both get assigned, but only one bind transfer per app cycle is allowed for each variable. Returns two handles on the the map hook and one for the map-back hook.
Note that the current value is not assigned, only the subsequent updates, you can assign
other
and self
and then bind to fully sync the variables.
sourcefn bind_filter_map_bidi<T2, V2, M, B>(
&self,
other: &V2,
map: M,
map_back: B,
) -> VarHandles
fn bind_filter_map_bidi<T2, V2, M, B>( &self, other: &V2, map: M, map_back: B, ) -> VarHandles
Bind self
to other
and back with the new values of self
transformed by map
and the new values of other
transformed
by map_back
, the value is assigned in a update only if the closures returns a value.
Only a weak reference to each variable is held by the other, both variables update in the same app update cycle.
Note that the current value is not assigned, only the subsequent updates, you can assign
other
and then bind to fully sync the variables.
sourcefn bind<V2>(&self, other: &V2) -> VarHandlewhere
V2: Var<T>,
fn bind<V2>(&self, other: &V2) -> VarHandlewhere
V2: Var<T>,
Setup a hook that assigns other
with the new values of self
.
Only a weak reference to the other
variable is held.
Note that the current value is not assigned, only the subsequent updates, you can use
set_from
to sync the initial value.
sourcefn set_bind<V2>(&self, other: &V2) -> VarHandlewhere
V2: Var<T>,
fn set_bind<V2>(&self, other: &V2) -> VarHandlewhere
V2: Var<T>,
Calls other.set_from(self)
and self.bind(other)
.
sourcefn bind_bidi<V2>(&self, other: &V2) -> VarHandleswhere
V2: Var<T>,
fn bind_bidi<V2>(&self, other: &V2) -> VarHandleswhere
V2: Var<T>,
Setup two hooks that assigns other
with the new values of self
and self
with the new values of other
.
Only a weak reference to each variable is held by the other.
Note that the current value is not assigned, only the subsequent updates, you can assign
other
using set_from
and then bind to fully sync the variables.
sourcefn trace_value<E, S>(&self, enter_value: E) -> VarHandle
fn trace_value<E, S>(&self, enter_value: E) -> VarHandle
Debug helper for tracing the lifetime of a value in this variable.
The enter_value
closure is called every time the variable updates, it can return
an implementation agnostic scope or span S
that is only dropped when the variable updates again.
The enter_value
is also called immediately when this method is called to start tracking the first value.
Returns a VarHandle
that can be used to stop tracing.
If this variable can never update the span is immediately dropped and a dummy handle is returned. Note that
the trace is set on the actual_var
.
sourcefn animate<A>(&self, animate: A) -> AnimationHandle
fn animate<A>(&self, animate: A) -> AnimationHandle
Schedule an animation that targets this variable.
If the variable is always read-only no animation is created and a dummy handle returned. The animation
targets the current actual_var
and is stopped if the variable is dropped.
The animate
closure is called every frame, starting after next frame, the closure inputs are
the Animation
args and modify access to the variable value, the args
can be used to calculate the new variable value and to control or stop the animation.
sourcefn sequence<A>(&self, animate: A) -> VarHandle
fn sequence<A>(&self, animate: A) -> VarHandle
Schedule animations started by animate
, the closure is called once at the start to begin, then again every time
the variable stops animating.
This can be used to create a sequence of animations or to repeat an animation. The sequence stops when animate
returns
a dummy handle or the variable is modified outside of animate
, or animations are disabled, or the returned handle is dropped.
sourcefn set_ease<S, E, F>(
&self,
start_value: S,
end_value: E,
duration: Duration,
easing: F,
) -> AnimationHandle
fn set_ease<S, E, F>( &self, start_value: S, end_value: E, duration: Duration, easing: F, ) -> AnimationHandle
Schedule an easing transition from the start_value
to end_value
.
The variable updates every time the EasingStep
for each frame changes and a different value is sampled.
See Var::animate
for details about animations.
sourcefn set_ease_oci<S, E, F>(
&self,
start_value: S,
end_value: E,
duration: Duration,
easing: F,
) -> AnimationHandle
fn set_ease_oci<S, E, F>( &self, start_value: S, end_value: E, duration: Duration, easing: F, ) -> AnimationHandle
Oscillate between start_value
to end_value
with an easing transition.
The duration
defines the easing duration between the two values.
Note that you can use Var::sequence
to create more complex looping animations.
sourcefn set_ease_with<S, E, F, Sa>(
&self,
start_value: S,
end_value: E,
duration: Duration,
easing: F,
sampler: Sa,
) -> AnimationHandlewhere
T: Transitionable,
S: Into<T>,
E: Into<T>,
F: Fn(EasingTime) -> EasingStep + Send + 'static,
Sa: Fn(&Transition<T>, EasingStep) -> T + Send + 'static,
fn set_ease_with<S, E, F, Sa>(
&self,
start_value: S,
end_value: E,
duration: Duration,
easing: F,
sampler: Sa,
) -> AnimationHandlewhere
T: Transitionable,
S: Into<T>,
E: Into<T>,
F: Fn(EasingTime) -> EasingStep + Send + 'static,
Sa: Fn(&Transition<T>, EasingStep) -> T + Send + 'static,
Schedule an easing transition from the start_value
to end_value
using a custom value sampler.
The variable updates every time the EasingStep
for each frame changes and a different value is sampled.
See Var::animate
for details about animations.
sourcefn set_ease_oci_with<S, E, F, Sa>(
&self,
start_value: S,
end_value: E,
duration: Duration,
easing: F,
sampler: Sa,
) -> AnimationHandlewhere
T: Transitionable,
S: Into<T>,
E: Into<T>,
F: Fn(EasingTime) -> EasingStep + Send + 'static,
Sa: Fn(&Transition<T>, EasingStep) -> T + Send + 'static,
fn set_ease_oci_with<S, E, F, Sa>(
&self,
start_value: S,
end_value: E,
duration: Duration,
easing: F,
sampler: Sa,
) -> AnimationHandlewhere
T: Transitionable,
S: Into<T>,
E: Into<T>,
F: Fn(EasingTime) -> EasingStep + Send + 'static,
Sa: Fn(&Transition<T>, EasingStep) -> T + Send + 'static,
Oscillate between start_value
to end_value
with an easing transition using a custom value sampler.
The duration
defines the easing duration between the two values.
Note that you can use Var::sequence
to create more complex looping animations.
sourcefn ease<E, F>(
&self,
new_value: E,
duration: Duration,
easing: F,
) -> AnimationHandle
fn ease<E, F>( &self, new_value: E, duration: Duration, easing: F, ) -> AnimationHandle
Schedule an easing transition from the current value to new_value
.
The variable updates every time the EasingStep
for each frame changes and a different value is sampled.
See Var::animate
for details about animations.
sourcefn ease_oci<E, F>(
&self,
new_value: E,
duration: Duration,
easing: F,
) -> AnimationHandle
fn ease_oci<E, F>( &self, new_value: E, duration: Duration, easing: F, ) -> AnimationHandle
Oscillate between the current value and new_value
with an easing transition.
The duration
defines the easing duration between the two values.
Note that you can use Var::sequence
to create more complex looping animations.
sourcefn ease_with<E, F, S>(
&self,
new_value: E,
duration: Duration,
easing: F,
sampler: S,
) -> AnimationHandlewhere
T: Transitionable,
E: Into<T>,
F: Fn(EasingTime) -> EasingStep + Send + 'static,
S: Fn(&Transition<T>, EasingStep) -> T + Send + 'static,
fn ease_with<E, F, S>(
&self,
new_value: E,
duration: Duration,
easing: F,
sampler: S,
) -> AnimationHandlewhere
T: Transitionable,
E: Into<T>,
F: Fn(EasingTime) -> EasingStep + Send + 'static,
S: Fn(&Transition<T>, EasingStep) -> T + Send + 'static,
Schedule an easing transition from the current value to new_value
using a custom value sampler.
The variable updates every time the EasingStep
for each frame changes and a different value is sampled.
See Var::animate
for details about animations.
sourcefn ease_oci_with<E, F, S>(
&self,
new_value: E,
duration: Duration,
easing: F,
sampler: S,
) -> AnimationHandlewhere
T: Transitionable,
E: Into<T>,
F: Fn(EasingTime) -> EasingStep + Send + 'static,
S: Fn(&Transition<T>, EasingStep) -> T + Send + 'static,
fn ease_oci_with<E, F, S>(
&self,
new_value: E,
duration: Duration,
easing: F,
sampler: S,
) -> AnimationHandlewhere
T: Transitionable,
E: Into<T>,
F: Fn(EasingTime) -> EasingStep + Send + 'static,
S: Fn(&Transition<T>, EasingStep) -> T + Send + 'static,
Oscillate between the current value and new_value
with an easing transition and a custom value sampler.
The duration
defines the easing duration between the two values.
Note that you can use Var::sequence
to create more complex looping animations.
sourcefn set_ease_keyed<F>(
&self,
keys: Vec<(Factor, T)>,
duration: Duration,
easing: F,
) -> AnimationHandle
fn set_ease_keyed<F>( &self, keys: Vec<(Factor, T)>, duration: Duration, easing: F, ) -> AnimationHandle
Schedule a keyframed transition animation for the variable, starting from the first key.
The variable will be set to the first keyframe, then animated across all other keys.
See Var::animate
for details about animations.
sourcefn set_ease_keyed_with<F, S>(
&self,
keys: Vec<(Factor, T)>,
duration: Duration,
easing: F,
sampler: S,
) -> AnimationHandlewhere
T: Transitionable,
F: Fn(EasingTime) -> EasingStep + Send + 'static,
S: Fn(&TransitionKeyed<T>, EasingStep) -> T + Send + 'static,
fn set_ease_keyed_with<F, S>(
&self,
keys: Vec<(Factor, T)>,
duration: Duration,
easing: F,
sampler: S,
) -> AnimationHandlewhere
T: Transitionable,
F: Fn(EasingTime) -> EasingStep + Send + 'static,
S: Fn(&TransitionKeyed<T>, EasingStep) -> T + Send + 'static,
Schedule a keyframed transition animation for the variable, starting from the first key, using a custom value sampler.
The variable will be set to the first keyframe, then animated across all other keys.
See Var::animate
for details about animations.
sourcefn ease_keyed<F>(
&self,
keys: Vec<(Factor, T)>,
duration: Duration,
easing: F,
) -> AnimationHandle
fn ease_keyed<F>( &self, keys: Vec<(Factor, T)>, duration: Duration, easing: F, ) -> AnimationHandle
Schedule a keyframed transition animation for the variable, starting from the current value.
The variable will be set to the first keyframe, then animated across all other keys.
See Var::animate
for details about animations.
sourcefn ease_keyed_with<F, S>(
&self,
keys: Vec<(Factor, T)>,
duration: Duration,
easing: F,
sampler: S,
) -> AnimationHandlewhere
T: Transitionable,
F: Fn(EasingTime) -> EasingStep + Send + 'static,
S: Fn(&TransitionKeyed<T>, EasingStep) -> T + Send + 'static,
fn ease_keyed_with<F, S>(
&self,
keys: Vec<(Factor, T)>,
duration: Duration,
easing: F,
sampler: S,
) -> AnimationHandlewhere
T: Transitionable,
F: Fn(EasingTime) -> EasingStep + Send + 'static,
S: Fn(&TransitionKeyed<T>, EasingStep) -> T + Send + 'static,
Schedule a keyframed transition animation for the variable, starting from the current value, using a custom value sampler.
The variable will be set to the first keyframe, then animated across all other keys.
See Var::animate
for details about animations.
sourcefn step<N>(&self, new_value: N, delay: Duration) -> AnimationHandlewhere
N: Into<T>,
fn step<N>(&self, new_value: N, delay: Duration) -> AnimationHandlewhere
N: Into<T>,
Set the variable to new_value
after a delay
.
The variable is_animating
until the delay elapses and the value is set.
See Var::animate
for details about animations.
sourcefn step_oci<N>(&self, new_value: N, delay: Duration) -> AnimationHandlewhere
N: Into<T>,
fn step_oci<N>(&self, new_value: N, delay: Duration) -> AnimationHandlewhere
N: Into<T>,
Oscillate between the current value and new_value
, every time the delay
elapses the variable is set to the next value.
sourcefn set_step_oci<V0, V1>(
&self,
from: V0,
to: V1,
delay: Duration,
) -> AnimationHandle
fn set_step_oci<V0, V1>( &self, from: V0, to: V1, delay: Duration, ) -> AnimationHandle
Oscillate between from
and to
, the variable is set to from
to start and every time the delay
elapses
the variable is set to the next value.
sourcefn steps<F>(
&self,
steps: Vec<(Factor, T)>,
duration: Duration,
easing: F,
) -> AnimationHandle
fn steps<F>( &self, steps: Vec<(Factor, T)>, duration: Duration, easing: F, ) -> AnimationHandle
Set the variable to a sequence of values as a time duration
elapses.
An animation curve is used to find the first factor in steps
above or at the curve line at the current time,
the variable is set to this step value, continuing animating across the next steps until the last or the animation end.
The variable is_animating
from the start, even if no step applies and stays animating until the last step applies
or the duration is reached.
§Examples
Creates a variable that outputs text every 5% of a 5 seconds animation, advanced linearly.
let steps = (0..=100).step_by(5).map(|i| (i.pct().fct(), formatx!("{i}%"))).collect();
text_var.steps(steps, 5.secs(), easing::linear)
The variable is set to "0%"
, after 5% of the duration
elapses it is set to "5%"
and so on
until the value is set to "100%
at the end of the animation.
Returns an AnimationHandle
. See Var::animate
for details about animations.
sourcefn chase<N, F>(
&self,
first_target: N,
duration: Duration,
easing: F,
) -> ChaseAnimation<T>
fn chase<N, F>( &self, first_target: N, duration: Duration, easing: F, ) -> ChaseAnimation<T>
Starts an easing animation that chases a target value that can be changed using the ChaseAnimation<T>
handle.
sourcefn debug(&self) -> VarDebug<'_, T, Self>
fn debug(&self) -> VarDebug<'_, T, Self>
Returns a wrapper that implements fmt::Debug
to write the var value.
sourcefn display(&self) -> VarDisplay<'_, T, Self>where
T: Display,
fn display(&self) -> VarDisplay<'_, T, Self>where
T: Display,
Returns a wrapper that implements fmt::Display
to write the var value.