Struct AnimationTimer

Source
pub struct AnimationTimer {
    pub handle: ControlHandle,
}
Expand description

A timer is an invisible UI component that trigger the OnTimerTick event at the specified interval. Timers are mosty used to handle animations OR to create a timeout. To sync multithreaded action see the Notice object.

AnimationTimer is controlled from a singletion running in another thread. All instance of AnimationTimer will live on that thread.

A timer still requires a top level window parent. If the top level window parent is destroyed, the timer becomes invalid.

AnimationTimer replaces the default winapi timer. Please, for the love of god, do not use the default timer.

Builder parameters: * parent: Required. The timer parent container that will receive the timer event. Should be a top level window * interval: The timer tick interval as a rust Duration. Minimum is 1 ms * lifetime: The timer should automatically stop after the selected Duration. Defaults to None. * max_tick: The timer should automatically stop after sending X amount of OnTImerTick events. Defaults to None. * active: If the timer should start right away. Default to false

Control events: * OnTimerTick: When the timer ticks * OnTimerStop: When the timer stops itself (due to max_tick_count or lifetime being reached, not user actions)

use native_windows_gui as nwg;
use std::time::Duration;

/// Builds a timer that will animation something at 60fps for 3 sec
fn build_timer(parent: &nwg::Window)  {
    let mut timer = Default::default();
    nwg::AnimationTimer::builder()
        .parent(parent)
        .interval(Duration::from_millis(1000/60))
        .lifetime(Some(Duration::from_millis(3000)))
        .build(&mut timer);
}

Fields§

§handle: ControlHandle

Implementations§

Source§

impl AnimationTimer

Source

pub fn builder() -> AnimationTimerBuilder

Source

pub fn valid(&self) -> bool

Checks if the timer is still usable. A timer becomes unusable when the parent window is destroyed. This will also return false if the timer is not initialized.

Source

pub fn start(&self)

Start the selected timer. If the timer is already running this resets it. This resets the life time and tick count if relevant.

Source

pub fn stop(&self)

Stop the selected timer. If the timer is already stopped, this does nothing.

Source

pub fn set_interval(&self, i: Duration)

Sets the interval on the this timer

Source

pub fn set_lifetime(&self, life: Option<Duration>)

Sets the life time on the this timer

Source

pub fn set_max_tick(&self, max_tick: Option<u64>)

Sets the max tick count on the this timer

Trait Implementations§

Source§

impl Default for AnimationTimer

Source§

fn default() -> AnimationTimer

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

impl Drop for AnimationTimer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl From<&AnimationTimer> for ControlHandle

Source§

fn from(control: &AnimationTimer) -> Self

Converts to this type from the input type.
Source§

impl From<&mut AnimationTimer> for ControlHandle

Source§

fn from(control: &mut AnimationTimer) -> Self

Converts to this type from the input type.
Source§

impl PartialEq<AnimationTimer> for ControlHandle

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<ControlHandle> for AnimationTimer

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for AnimationTimer

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for AnimationTimer

Source§

impl StructuralPartialEq for AnimationTimer

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