pub struct RippleState { /* private fields */ }Expand description
§RippleState
Manage ripple animations and hover state for interactive UI components.
Use with remember to create persistent state across frames.
Implementations§
Source§impl RippleState
impl RippleState
Sourcepub const ANIMATION_DURATION: Duration
pub const ANIMATION_DURATION: Duration
The default duration of the ripple animation.
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new RippleState with default values.
§Example
use tessera_components::ripple_state::RippleState;
let state = RippleState::new();Sourcepub fn start_animation(&mut self, click_pos: [f32; 2])
pub fn start_animation(&mut self, click_pos: [f32; 2])
Starts a new ripple animation from the given click position.
§Arguments
click_pos- The normalized[x, y]position in 0.0..=1.0 where the ripple originates.
§Example
use tessera_components::ripple_state::RippleState;
let session = tessera_ui::RuntimeSession::new();
let _scope = session.enter();
let mut state = RippleState::new();
state.start_animation([0.5, 0.5]);Sourcepub fn start_animation_with_spec(
&mut self,
click_pos: [f32; 2],
size: PxSize,
spec: RippleSpec,
)
pub fn start_animation_with_spec( &mut self, click_pos: [f32; 2], size: PxSize, spec: RippleSpec, )
Starts a ripple animation using the provided size and spec.
Sourcepub fn set_pressed(&mut self, pressed: bool)
pub fn set_pressed(&mut self, pressed: bool)
Sets whether the component is pressed.
Sourcepub fn animation(&mut self) -> Option<RippleAnimation>
pub fn animation(&mut self) -> Option<RippleAnimation>
Returns the current ripple animation snapshot.
Sourcepub fn animation_snapshot(&self) -> Option<RippleAnimation>
pub fn animation_snapshot(&self) -> Option<RippleAnimation>
Returns a read-only snapshot of the current ripple animation.
Sourcepub fn animation_snapshot_at(&self, now: Instant) -> Option<RippleAnimation>
pub fn animation_snapshot_at(&self, now: Instant) -> Option<RippleAnimation>
Returns a read-only animation snapshot at now.
Sourcepub fn animation_at(&mut self, now: Instant) -> Option<RippleAnimation>
pub fn animation_at(&mut self, now: Instant) -> Option<RippleAnimation>
Returns the current ripple animation snapshot at now.
Sourcepub fn animation_snapshot_at_frame_nanos(
&self,
frame_nanos: u64,
) -> Option<RippleAnimation>
pub fn animation_snapshot_at_frame_nanos( &self, frame_nanos: u64, ) -> Option<RippleAnimation>
Returns a read-only animation snapshot at frame_nanos.
Sourcepub fn animation_at_frame_nanos(
&mut self,
frame_nanos: u64,
) -> Option<RippleAnimation>
pub fn animation_at_frame_nanos( &mut self, frame_nanos: u64, ) -> Option<RippleAnimation>
Returns the current ripple animation snapshot at frame_nanos.
Sourcepub fn get_animation_progress(&mut self) -> Option<(f32, [f32; 2])>
pub fn get_animation_progress(&mut self) -> Option<(f32, [f32; 2])>
Returns the current progress of the ripple animation and the origin position.
Returns Some((progress, [x, y])) if the animation is active, where:
progressis a value in[0.0, 1.0)representing the animation progress.[x, y]is the normalized origin of the ripple in 0.0..=1.0.
Returns None if the animation is not active or has completed.
§Example
use tessera_components::ripple_state::RippleState;
let session = tessera_ui::RuntimeSession::new();
let _scope = session.enter();
let mut state = RippleState::new();
state.start_animation([0.5, 0.5]);
let (progress, center) = state.get_animation_progress().expect("active ripple");
assert_eq!(progress, 0.0);
assert_eq!(center, [0.5, 0.5]);Sourcepub fn set_hovered(&mut self, hovered: bool)
pub fn set_hovered(&mut self, hovered: bool)
Sets whether the component is hovered.
Sourcepub fn is_hovered(&self) -> bool
pub fn is_hovered(&self) -> bool
Returns whether the component is hovered.
Sourcepub fn set_focused(&mut self, focused: bool)
pub fn set_focused(&mut self, focused: bool)
Sets whether the component is focused.
Sourcepub fn is_focused(&self) -> bool
pub fn is_focused(&self) -> bool
Returns whether the component is focused.
Sourcepub fn set_dragged(&mut self, dragged: bool)
pub fn set_dragged(&mut self, dragged: bool)
Sets whether the component is dragged.
Sourcepub fn is_dragged(&self) -> bool
pub fn is_dragged(&self) -> bool
Returns whether the component is dragged.
Sourcepub fn is_pressed(&self) -> bool
pub fn is_pressed(&self) -> bool
Returns whether the component is pressed.
Sourcepub fn state_layer_alpha(&self) -> f32
pub fn state_layer_alpha(&self) -> f32
Returns the state-layer alpha derived from the current interactions.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RippleState
impl RefUnwindSafe for RippleState
impl Send for RippleState
impl Sync for RippleState
impl Unpin for RippleState
impl UnsafeUnpin for RippleState
impl UnwindSafe for RippleState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.