DirectTransition

Struct DirectTransition 

Source
pub struct DirectTransition<T: StylePropValue> {
    pub current_value: T,
    /* private fields */
}
Expand description

Direct transition controller using TransitionState without the Style system.

This allows you to animate any value that implements StylePropValue by managing the transition state directly. You control when transitions start, how they’re configured, and when to step them forward.

§Example

use std::time::{Duration, Instant};
use floem::style::{DirectTransition, Transition};

// Create a transition for animating opacity
let mut opacity = DirectTransition::new(1., None);

// Configure transition timing and easing
opacity.set_transition(Some(
    Transition::ease_in_out(Duration::from_millis(300))
));

// Start transition to new value
opacity.transition_to(0.0);

// Animation loop - call this every frame
let start_time = Instant::now();
loop {
    let now = Instant::now();

    // Step the transition forward
    let changed = opacity.step(&now);

    // Get current interpolated value
    let current_opacity = opacity.get();

    // Only update rendering if value changed
    if changed {
        println!("Current opacity: {:.3}", current_opacity);
        // render_with_opacity(current_opacity);
    }

    // Exit when transition completes
    if !opacity.is_active() {
        println!("Transition complete!");
        break;
    }

    // Wait for next frame (~60fps)
    std::thread::sleep(Duration::from_millis(16));

    // Safety timeout
    if now.duration_since(start_time) > Duration::from_secs(2) {
        break;
    }
}

// Chain multiple transitions
opacity.transition_to(0.5); // Start new transition from current position
// ... repeat animation loop

// Or jump immediately without animation
opacity.set_immediate(1.0);

Fields§

§current_value: T

Implementations§

Source§

impl<T: StylePropValue> DirectTransition<T>

Source

pub fn new(initial_value: T, transition: Option<Transition>) -> Self

Create a new transition starting at the given value

Source

pub fn set_transition(&mut self, transition: Option<Transition>)

Configure the transition timing and easing function

Pass None to disable transitions (values will change immediately)

Source

pub fn transition_to(&mut self, target: T) -> bool

Start transitioning to a new target value

Returns true if a transition was started, false if no transition is configured or the target equals the current value

Source

pub fn step(&mut self, now: &Instant) -> bool

Step the transition forward in time

Call this every frame with the current time. Returns true if the interpolated value changed this frame, false otherwise.

You can use the return value to optimize rendering - only update when something actually changed.

Source

pub fn get(&self) -> T

Get the current interpolated value

During a transition, this returns the smoothly interpolated value. When no transition is active, returns the target value.

Source

pub fn is_active(&self) -> bool

Check if a transition is currently active

Source

pub fn target(&self) -> &T

Get the target value (final destination of current/last transition)

Source

pub fn set_immediate(&mut self, value: T)

Set value immediately without any transition

This cancels any active transition and jumps directly to the new value

Source

pub fn progress(&self, now: &Instant) -> Option<f64>

Get the progress of the current transition as a value from 0.0 to 1.0

Returns None if no transition is active or configured

Trait Implementations§

Source§

impl<T: Clone + StylePropValue> Clone for DirectTransition<T>

Source§

fn clone(&self) -> DirectTransition<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + StylePropValue> Debug for DirectTransition<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for DirectTransition<T>
where T: Freeze,

§

impl<T> !RefUnwindSafe for DirectTransition<T>

§

impl<T> !Send for DirectTransition<T>

§

impl<T> !Sync for DirectTransition<T>

§

impl<T> Unpin for DirectTransition<T>
where T: Unpin,

§

impl<T> !UnwindSafe for DirectTransition<T>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,

Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,