Skip to main content

Transition

Struct Transition 

Source
pub struct Transition { /* private fields */ }
Expand description

Android dialog visibility animation state.

Implementations§

Source§

impl Transition

Source

pub fn show(&mut self, now: Instant)

Starts showing the dialog using Android’s platform dialog window animation.

Examples found in repository?
examples/showcase/app.rs (line 350)
254fn update(state: &mut Showcase, message: Message) -> Task<Message> {
255    match message {
256        #[cfg(any(target_arch = "wasm32", test))]
257        Message::CjkCoreFontFinished => load_cjk_regional_font(),
258        #[cfg(any(target_arch = "wasm32", test))]
259        Message::CjkRegionalFontFinished => Task::none(),
260        Message::Navigate(page) => {
261            state
262                .navigation
263                .select(page, Instant::now(), state.adaptive_navigation_layout());
264            Task::none()
265        }
266        Message::Increment => {
267            state.count += 1;
268            Task::none()
269        }
270        Message::Decrement => {
271            state.count -= 1;
272            Task::none()
273        }
274        Message::TextChanged(note) => {
275            state.note = note;
276            Task::none()
277        }
278        Message::EditorAction(action) => {
279            state.editor_content.perform(action);
280            Task::none()
281        }
282        Message::SelectChanged(choice) => {
283            state.select_choice = Some(choice);
284            Task::none()
285        }
286        Message::ComboboxSelected(choice) => {
287            state.combobox_choice = Some(choice);
288            state.combobox_input.clear();
289            state.combobox_options.set_selection(Some(&choice));
290            Task::none()
291        }
292        Message::ComboboxInputChanged(input) => {
293            state.combobox_options.set_input(input.clone());
294            state.combobox_input = input;
295            state.combobox_choice = None;
296            Task::none()
297        }
298        Message::SearchChanged(query) => {
299            state.search_query = query;
300            Task::none()
301        }
302        Message::DatePickerChanged(action) => state.date_picker.update_and_scroll(action),
303        Message::DateRangePickerChanged(action) => {
304            state.date_range_picker.update_and_scroll(action)
305        }
306        Message::TimePickerChanged(action) => {
307            state.time_picker.update(action);
308            Task::none()
309        }
310        Message::SliderChanged(progress) => {
311            state.progress = progress;
312            Task::none()
313        }
314        Message::EnabledChanged(enabled) => {
315            state.enabled = enabled;
316            Task::none()
317        }
318        Message::ChoiceSelected(choice) => {
319            state.radio_choice = Some(choice);
320            Task::none()
321        }
322        Message::SegmentSelected(choice) => {
323            state.segment_choice = choice;
324            state.segment_state.select(choice.index(), Instant::now());
325            Task::none()
326        }
327        Message::PrimaryTabSelected(choice) => {
328            state.primary_tab = choice;
329            state.primary_tab_state.select(
330                choice.index(),
331                Instant::now(),
332                material::widget::tabs::Variant::Primary,
333            );
334            Task::none()
335        }
336        Message::SecondaryTabSelected(choice) => {
337            state.secondary_tab = choice;
338            state.secondary_tab_state.select(
339                choice.index(),
340                Instant::now(),
341                material::widget::tabs::Variant::Secondary,
342            );
343            Task::none()
344        }
345        Message::MenuPressed => {
346            state.navigation.toggle_menu_now();
347            Task::none()
348        }
349        Message::DialogOpened => {
350            state.alert_dialog.show(Instant::now());
351            Task::none()
352        }
353        Message::DialogDismissed => {
354            state.alert_dialog.dismiss(Instant::now());
355            Task::none()
356        }
357        Message::DialogConfirmed => {
358            state.alert_dialog.dismiss(Instant::now());
359            state.count += 1;
360            Task::none()
361        }
362        Message::ShowSnackbar => {
363            state.snackbar.show(Instant::now());
364            Task::none()
365        }
366        Message::SnackbarUndo => {
367            state.count -= 1;
368            state.snackbar.dismiss(Instant::now());
369            Task::none()
370        }
371        Message::WindowResized(size) => {
372            state.window_size = size;
373            Task::none()
374        }
375        Message::ThemeChanged(action) => {
376            state.theme_controller.update(
377                action,
378                state.window_size,
379                theme_picker::bottom_margin(state.adaptive_navigation_layout()),
380                Instant::now(),
381            );
382            Task::none()
383        }
384        Message::Frame(now) => {
385            let _ = state.theme_controller.advance(now);
386            let _ = state.navigation.advance(now);
387            let _ = state.segment_state.advance(now);
388            let _ = state.primary_tab_state.advance(now);
389            let _ = state.secondary_tab_state.advance(now);
390            state.progress_animation.advance(now);
391            let _ = state.alert_dialog.advance(now);
392            let _ = state.snackbar.advance(now);
393            let _ = state.date_picker.advance(now);
394            let _ = state.date_range_picker.advance(now);
395            let _ = state.time_picker.advance(now);
396            Task::none()
397        }
398    }
399}
Source

pub fn dismiss(&mut self, now: Instant)

Starts dismissing the dialog.

Examples found in repository?
examples/showcase/app.rs (line 354)
254fn update(state: &mut Showcase, message: Message) -> Task<Message> {
255    match message {
256        #[cfg(any(target_arch = "wasm32", test))]
257        Message::CjkCoreFontFinished => load_cjk_regional_font(),
258        #[cfg(any(target_arch = "wasm32", test))]
259        Message::CjkRegionalFontFinished => Task::none(),
260        Message::Navigate(page) => {
261            state
262                .navigation
263                .select(page, Instant::now(), state.adaptive_navigation_layout());
264            Task::none()
265        }
266        Message::Increment => {
267            state.count += 1;
268            Task::none()
269        }
270        Message::Decrement => {
271            state.count -= 1;
272            Task::none()
273        }
274        Message::TextChanged(note) => {
275            state.note = note;
276            Task::none()
277        }
278        Message::EditorAction(action) => {
279            state.editor_content.perform(action);
280            Task::none()
281        }
282        Message::SelectChanged(choice) => {
283            state.select_choice = Some(choice);
284            Task::none()
285        }
286        Message::ComboboxSelected(choice) => {
287            state.combobox_choice = Some(choice);
288            state.combobox_input.clear();
289            state.combobox_options.set_selection(Some(&choice));
290            Task::none()
291        }
292        Message::ComboboxInputChanged(input) => {
293            state.combobox_options.set_input(input.clone());
294            state.combobox_input = input;
295            state.combobox_choice = None;
296            Task::none()
297        }
298        Message::SearchChanged(query) => {
299            state.search_query = query;
300            Task::none()
301        }
302        Message::DatePickerChanged(action) => state.date_picker.update_and_scroll(action),
303        Message::DateRangePickerChanged(action) => {
304            state.date_range_picker.update_and_scroll(action)
305        }
306        Message::TimePickerChanged(action) => {
307            state.time_picker.update(action);
308            Task::none()
309        }
310        Message::SliderChanged(progress) => {
311            state.progress = progress;
312            Task::none()
313        }
314        Message::EnabledChanged(enabled) => {
315            state.enabled = enabled;
316            Task::none()
317        }
318        Message::ChoiceSelected(choice) => {
319            state.radio_choice = Some(choice);
320            Task::none()
321        }
322        Message::SegmentSelected(choice) => {
323            state.segment_choice = choice;
324            state.segment_state.select(choice.index(), Instant::now());
325            Task::none()
326        }
327        Message::PrimaryTabSelected(choice) => {
328            state.primary_tab = choice;
329            state.primary_tab_state.select(
330                choice.index(),
331                Instant::now(),
332                material::widget::tabs::Variant::Primary,
333            );
334            Task::none()
335        }
336        Message::SecondaryTabSelected(choice) => {
337            state.secondary_tab = choice;
338            state.secondary_tab_state.select(
339                choice.index(),
340                Instant::now(),
341                material::widget::tabs::Variant::Secondary,
342            );
343            Task::none()
344        }
345        Message::MenuPressed => {
346            state.navigation.toggle_menu_now();
347            Task::none()
348        }
349        Message::DialogOpened => {
350            state.alert_dialog.show(Instant::now());
351            Task::none()
352        }
353        Message::DialogDismissed => {
354            state.alert_dialog.dismiss(Instant::now());
355            Task::none()
356        }
357        Message::DialogConfirmed => {
358            state.alert_dialog.dismiss(Instant::now());
359            state.count += 1;
360            Task::none()
361        }
362        Message::ShowSnackbar => {
363            state.snackbar.show(Instant::now());
364            Task::none()
365        }
366        Message::SnackbarUndo => {
367            state.count -= 1;
368            state.snackbar.dismiss(Instant::now());
369            Task::none()
370        }
371        Message::WindowResized(size) => {
372            state.window_size = size;
373            Task::none()
374        }
375        Message::ThemeChanged(action) => {
376            state.theme_controller.update(
377                action,
378                state.window_size,
379                theme_picker::bottom_margin(state.adaptive_navigation_layout()),
380                Instant::now(),
381            );
382            Task::none()
383        }
384        Message::Frame(now) => {
385            let _ = state.theme_controller.advance(now);
386            let _ = state.navigation.advance(now);
387            let _ = state.segment_state.advance(now);
388            let _ = state.primary_tab_state.advance(now);
389            let _ = state.secondary_tab_state.advance(now);
390            state.progress_animation.advance(now);
391            let _ = state.alert_dialog.advance(now);
392            let _ = state.snackbar.advance(now);
393            let _ = state.date_picker.advance(now);
394            let _ = state.date_range_picker.advance(now);
395            let _ = state.time_picker.advance(now);
396            Task::none()
397        }
398    }
399}
Source

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

Advances timers and hides the dialog once Android’s exit animation ends.

Examples found in repository?
examples/showcase/app.rs (line 391)
254fn update(state: &mut Showcase, message: Message) -> Task<Message> {
255    match message {
256        #[cfg(any(target_arch = "wasm32", test))]
257        Message::CjkCoreFontFinished => load_cjk_regional_font(),
258        #[cfg(any(target_arch = "wasm32", test))]
259        Message::CjkRegionalFontFinished => Task::none(),
260        Message::Navigate(page) => {
261            state
262                .navigation
263                .select(page, Instant::now(), state.adaptive_navigation_layout());
264            Task::none()
265        }
266        Message::Increment => {
267            state.count += 1;
268            Task::none()
269        }
270        Message::Decrement => {
271            state.count -= 1;
272            Task::none()
273        }
274        Message::TextChanged(note) => {
275            state.note = note;
276            Task::none()
277        }
278        Message::EditorAction(action) => {
279            state.editor_content.perform(action);
280            Task::none()
281        }
282        Message::SelectChanged(choice) => {
283            state.select_choice = Some(choice);
284            Task::none()
285        }
286        Message::ComboboxSelected(choice) => {
287            state.combobox_choice = Some(choice);
288            state.combobox_input.clear();
289            state.combobox_options.set_selection(Some(&choice));
290            Task::none()
291        }
292        Message::ComboboxInputChanged(input) => {
293            state.combobox_options.set_input(input.clone());
294            state.combobox_input = input;
295            state.combobox_choice = None;
296            Task::none()
297        }
298        Message::SearchChanged(query) => {
299            state.search_query = query;
300            Task::none()
301        }
302        Message::DatePickerChanged(action) => state.date_picker.update_and_scroll(action),
303        Message::DateRangePickerChanged(action) => {
304            state.date_range_picker.update_and_scroll(action)
305        }
306        Message::TimePickerChanged(action) => {
307            state.time_picker.update(action);
308            Task::none()
309        }
310        Message::SliderChanged(progress) => {
311            state.progress = progress;
312            Task::none()
313        }
314        Message::EnabledChanged(enabled) => {
315            state.enabled = enabled;
316            Task::none()
317        }
318        Message::ChoiceSelected(choice) => {
319            state.radio_choice = Some(choice);
320            Task::none()
321        }
322        Message::SegmentSelected(choice) => {
323            state.segment_choice = choice;
324            state.segment_state.select(choice.index(), Instant::now());
325            Task::none()
326        }
327        Message::PrimaryTabSelected(choice) => {
328            state.primary_tab = choice;
329            state.primary_tab_state.select(
330                choice.index(),
331                Instant::now(),
332                material::widget::tabs::Variant::Primary,
333            );
334            Task::none()
335        }
336        Message::SecondaryTabSelected(choice) => {
337            state.secondary_tab = choice;
338            state.secondary_tab_state.select(
339                choice.index(),
340                Instant::now(),
341                material::widget::tabs::Variant::Secondary,
342            );
343            Task::none()
344        }
345        Message::MenuPressed => {
346            state.navigation.toggle_menu_now();
347            Task::none()
348        }
349        Message::DialogOpened => {
350            state.alert_dialog.show(Instant::now());
351            Task::none()
352        }
353        Message::DialogDismissed => {
354            state.alert_dialog.dismiss(Instant::now());
355            Task::none()
356        }
357        Message::DialogConfirmed => {
358            state.alert_dialog.dismiss(Instant::now());
359            state.count += 1;
360            Task::none()
361        }
362        Message::ShowSnackbar => {
363            state.snackbar.show(Instant::now());
364            Task::none()
365        }
366        Message::SnackbarUndo => {
367            state.count -= 1;
368            state.snackbar.dismiss(Instant::now());
369            Task::none()
370        }
371        Message::WindowResized(size) => {
372            state.window_size = size;
373            Task::none()
374        }
375        Message::ThemeChanged(action) => {
376            state.theme_controller.update(
377                action,
378                state.window_size,
379                theme_picker::bottom_margin(state.adaptive_navigation_layout()),
380                Instant::now(),
381            );
382            Task::none()
383        }
384        Message::Frame(now) => {
385            let _ = state.theme_controller.advance(now);
386            let _ = state.navigation.advance(now);
387            let _ = state.segment_state.advance(now);
388            let _ = state.primary_tab_state.advance(now);
389            let _ = state.secondary_tab_state.advance(now);
390            state.progress_animation.advance(now);
391            let _ = state.alert_dialog.advance(now);
392            let _ = state.snackbar.advance(now);
393            let _ = state.date_picker.advance(now);
394            let _ = state.date_range_picker.advance(now);
395            let _ = state.time_picker.advance(now);
396            Task::none()
397        }
398    }
399}
Source

pub fn is_active(&self) -> bool

Returns whether the dialog should remain in the view tree.

Source

pub fn is_animating(&self) -> bool

Returns whether the dialog is currently running an enter or exit animation.

Examples found in repository?
examples/showcase/app.rs (line 419)
410fn subscription(state: &Showcase) -> Subscription<Message> {
411    let mut subscriptions =
412        vec![iced::window::resize_events().map(|(_id, size)| Message::WindowResized(size))];
413
414    if state.theme_controller.is_animating()
415        || state.navigation.is_animating()
416        || state.segment_state.is_animating()
417        || state.primary_tab_state.is_animating()
418        || state.secondary_tab_state.is_animating()
419        || state.alert_dialog.is_animating()
420        || state.snackbar.is_active()
421        || state.date_picker.is_animating()
422        || state.date_range_picker.is_animating()
423        || state.time_picker.is_animating()
424        || (state.navigation.selected() == ShowcasePage::Feedback
425            && state.progress_animation.is_animating())
426    {
427        subscriptions.push(iced::window::frames().map(Message::Frame));
428    }
429
430    Subscription::batch(subscriptions)
431}
Source

pub fn phase(&self) -> TransitionPhase

Returns the current transition phase.

Source

pub fn scale(&self, now: Instant) -> f32

Computes the Android dialog surface scale.

Source

pub fn alpha(&self, now: Instant) -> f32

Computes the Android dialog window alpha.

Examples found in repository?
examples/showcase/app.rs (line 458)
433fn view(state: &Showcase) -> material::Element<'_, Message> {
434    let now = Instant::now();
435    let page_content = material::widget::snackbar::host(
436        pages::view(state),
437        &state.snackbar,
438        now,
439        "Photo archived",
440        "Undo",
441        Message::SnackbarUndo,
442    );
443
444    let content = navigation::suite(&NAV_DESTINATIONS, &state.navigation)
445        .layout(state.adaptive_navigation_layout())
446        .with_menu("Showcase", Message::MenuPressed)
447        .view(Message::Navigate, page_content);
448    let content = state.theme_controller.controls_over(
449        content,
450        theme_picker::bottom_margin(state.adaptive_navigation_layout()),
451        Message::ThemeChanged,
452    );
453
454    let content = material::widget::dialog::modal_animated(
455        content,
456        &state.alert_dialog,
457        now,
458        alert_dialog(state.alert_dialog.alpha(now)),
459    );
460
461    state.theme_controller.reveal_over(content, now)
462}
Source

pub fn scrim_alpha(&self, now: Instant) -> f32

Computes the modal scrim fade progress.

Trait Implementations§

Source§

impl Clone for Transition

Source§

fn clone(&self) -> Transition

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 Copy for Transition

Source§

impl Debug for Transition

Source§

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

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

impl Default for Transition

Source§

fn default() -> Self

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

impl PartialEq for Transition

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Transition

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

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

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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<State, Message> IntoBoot<State, Message> for State

Source§

fn into_boot(self) -> (State, Task<Message>)

Turns some type into the initial state of some Application.
Source§

impl<T> MaybeClone for T

Source§

impl<T> MaybeDebug for T

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSync for T
where T: Sync,

Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

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