Skip to main content

ThemeController

Struct ThemeController 

Source
pub struct ThemeController { /* private fields */ }

Implementations§

Source§

impl ThemeController

Source

pub fn new(selected: MaterialColor, dark_mode: bool) -> Self

Source

pub fn theme(&self, name: impl Into<Cow<'static, str>>) -> Theme

Examples found in repository?
examples/showcase/app.rs (line 256)
255    fn theme(&self) -> Theme {
256        self.theme_controller.theme("Material 3 animated")
257    }
Source

pub const fn picker_state(&self) -> &State

Source

pub const fn is_picker_open(&self) -> bool

Source

pub const fn selected_color(&self) -> MaterialColor

Source

pub const fn dark_mode(&self) -> bool

Source

pub const fn visible_scheme(&self) -> ColorScheme

Source

pub const fn transition(&self) -> Option<ThemeRevealTransition>

Source

pub const fn is_animating(&self) -> bool

Examples found in repository?
examples/showcase/app.rs (line 599)
595fn subscription(state: &Showcase) -> Subscription<Message> {
596    let mut subscriptions =
597        vec![iced::window::resize_events().map(|(_id, size)| Message::WindowResized(size))];
598
599    if state.theme_controller.is_animating()
600        || state.navigation.is_animating()
601        || state.segment_state.is_animating()
602        || state.primary_tab_state.is_animating()
603        || state.secondary_tab_state.is_animating()
604        || state.log_viewer.is_animating()
605        || state.login_dialog.is_animating()
606        || state.snackbar.is_active()
607        || state.date_picker.is_animating()
608        || state.date_range_picker.is_animating()
609        || state.time_picker.is_animating()
610        || (state.navigation.selected() == ShowcasePage::Feedback
611            && state.progress_animation.is_animating())
612    {
613        subscriptions.push(iced::window::frames().map(Message::Frame));
614    }
615
616    Subscription::batch(subscriptions)
617}
Source

pub fn floating_clearance(&self) -> f32

Returns the vertical space occupied by the floating theme controls.

Examples found in repository?
examples/showcase/pages/mod.rs (line 34)
32pub(super) fn floating_content_inset(state: &Showcase) -> f32 {
33    (theme_picker::FLOATING_MARGIN
34        + state.theme_controller.floating_clearance()
35        + material::tokens::component::snackbar::BOTTOM_MARGIN
36        - page::PADDING)
37        .max(0.0)
38}
More examples
Hide additional examples
examples/showcase/app.rs (line 658)
653fn snackbar_host_options(
654    theme_controller: &theme_picker::ThemeController,
655) -> material::widget::snackbar::HostOptions {
656    material::widget::snackbar::HostOptions::default().bottom_margin(
657        theme_picker::FLOATING_MARGIN
658            + theme_controller.floating_clearance()
659            + material::tokens::component::snackbar::BOTTOM_MARGIN,
660    )
661}
Source

pub fn update( &mut self, action: ThemeAction, viewport: Size, bottom_margin: f32, now: Instant, )

Examples found in repository?
examples/showcase/app.rs (lines 403-408)
268fn update(state: &mut Showcase, message: Message) -> Task<Message> {
269    match message {
270        #[cfg(any(target_arch = "wasm32", test))]
271        Message::CjkCoreFontFinished => load_cjk_regional_font(),
272        #[cfg(any(target_arch = "wasm32", test))]
273        Message::CjkRegionalFontFinished => Task::none(),
274        Message::Navigate(page) => {
275            state
276                .navigation
277                .select(page, Instant::now(), state.adaptive_navigation_layout());
278            Task::none()
279        }
280        Message::Increment => {
281            state.count += 1;
282            Task::none()
283        }
284        Message::Decrement => {
285            state.count -= 1;
286            Task::none()
287        }
288        Message::TextChanged(note) => {
289            state.note = note;
290            Task::none()
291        }
292        Message::EditorAction(action) => {
293            state.editor_content.perform(action);
294            Task::none()
295        }
296        Message::SelectChanged(choice) => {
297            state.select_choice = Some(choice);
298            Task::none()
299        }
300        Message::ComboboxSelected(choice) => {
301            state.combobox_choice = Some(choice);
302            state.combobox_input.clear();
303            state.combobox_options.set_selection(Some(&choice));
304            Task::none()
305        }
306        Message::ComboboxInputChanged(input) => {
307            state.combobox_options.set_input(input.clone());
308            state.combobox_input = input;
309            state.combobox_choice = None;
310            Task::none()
311        }
312        Message::SearchChanged(query) => {
313            state.search_query = query;
314            Task::none()
315        }
316        Message::DatePickerChanged(action) => state.date_picker.update_and_scroll(action),
317        Message::DateRangePickerChanged(action) => {
318            state.date_range_picker.update_and_scroll(action)
319        }
320        Message::TimePickerChanged(action) => {
321            state.time_picker.update(action);
322            Task::none()
323        }
324        Message::SliderChanged(progress) => {
325            state.progress = progress;
326            Task::none()
327        }
328        Message::EnabledChanged(enabled) => {
329            state.enabled = enabled;
330            Task::none()
331        }
332        Message::ChoiceSelected(choice) => {
333            state.radio_choice = Some(choice);
334            Task::none()
335        }
336        Message::SegmentSelected(choice) => {
337            state.segment_choice = choice;
338            state.segment_state.select(choice.index(), Instant::now());
339            Task::none()
340        }
341        Message::PrimaryTabSelected(choice) => {
342            state.primary_tab = choice;
343            state.primary_tab_state.select(
344                choice.index(),
345                Instant::now(),
346                material::widget::tabs::Variant::Primary,
347            );
348            Task::none()
349        }
350        Message::SecondaryTabSelected(choice) => {
351            state.secondary_tab = choice;
352            state.secondary_tab_state.select(
353                choice.index(),
354                Instant::now(),
355                material::widget::tabs::Variant::Secondary,
356            );
357            Task::none()
358        }
359        Message::LogViewer(action) => state.log_viewer.update(action, &state.log_entries),
360        Message::MenuPressed => {
361            state.navigation.toggle_menu_now_for_size(state.window_size);
362            Task::none()
363        }
364        Message::DialogOpened => {
365            state.login_dialog.show(Instant::now());
366            iced::widget::operation::focus(dialog_account_input_id())
367        }
368        Message::DialogDismissed => {
369            state.login_dialog.dismiss(Instant::now());
370            Task::none()
371        }
372        Message::DialogConfirmed => {
373            state.login_dialog.dismiss(Instant::now());
374            state.count += 1;
375            Task::none()
376        }
377        Message::DialogAccountChanged(account) => {
378            state.dialog_account = account;
379            Task::none()
380        }
381        Message::DialogPasswordChanged(password) => {
382            state.dialog_password = password;
383            Task::none()
384        }
385        Message::DialogRememberPasswordChanged(remember_password) => {
386            state.dialog_remember_password = remember_password;
387            Task::none()
388        }
389        Message::ShowSnackbar => {
390            state.snackbar.show(Instant::now());
391            Task::none()
392        }
393        Message::SnackbarUndo => {
394            state.count -= 1;
395            state.snackbar.dismiss(Instant::now());
396            Task::none()
397        }
398        Message::WindowResized(size) => {
399            state.window_size = size;
400            Task::none()
401        }
402        Message::ThemeChanged(action) => {
403            state.theme_controller.update(
404                action,
405                state.window_size,
406                showcase_floating_bottom_margin(state.adaptive_navigation_layout()),
407                Instant::now(),
408            );
409            Task::none()
410        }
411        Message::Frame(now) => {
412            let _ = state.theme_controller.advance(now);
413            let _ = state.navigation.advance(now);
414            let _ = state.segment_state.advance(now);
415            let _ = state.primary_tab_state.advance(now);
416            let _ = state.secondary_tab_state.advance(now);
417            let _ = state.log_viewer.advance(now);
418            state.progress_animation.advance(now);
419            let _ = state.login_dialog.advance(now);
420            let _ = state.snackbar.advance(now);
421            let _ = state.date_picker.advance(now);
422            let _ = state.date_range_picker.advance(now);
423            let _ = state.time_picker.advance(now);
424            Task::none()
425        }
426    }
427}
Source

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

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

pub fn dark_mode_switch<'a, Message, Renderer>( &self, label: impl IntoFragment<'a>, on_action: impl Fn(ThemeAction) -> Message + 'a, ) -> Element<'a, Message, Theme, Renderer>
where Message: 'a, Renderer: Renderer + Renderer + Renderer + 'a,

Examples found in repository?
examples/showcase/pages/controls.rs (line 121)
112fn selection_controls(state: &Showcase) -> material::Element<'_, Message> {
113    let switches = page::component_stack([
114        material::widget::checkbox::standard(
115            state.enabled,
116            "Enable actions",
117            Message::EnabledChanged,
118        ),
119        state
120            .theme_controller
121            .dark_mode_switch("Dark theme", Message::ThemeChanged),
122    ]);
123
124    let radios = page::row([
125        material::widget::radio::standard(
126            "Standard",
127            RadioChoice::Standard,
128            state.radio_choice,
129            Message::ChoiceSelected,
130        ),
131        material::widget::radio::standard(
132            "Expressive",
133            RadioChoice::Expressive,
134            state.radio_choice,
135            Message::ChoiceSelected,
136        ),
137        material::widget::radio::standard(
138            "Dense",
139            RadioChoice::Dense,
140            state.radio_choice,
141            Message::ChoiceSelected,
142        ),
143    ]);
144
145    page::spacious_stack([switches.into(), radios.into()]).into()
146}
Source

pub fn controls_over<'a, Message, Renderer>( &self, content: impl Into<Element<'a, Message, Theme, Renderer>>, bottom_margin: f32, on_action: impl Fn(ThemeAction) -> Message + 'a, ) -> Element<'a, Message, Theme, Renderer>
where Message: Clone + 'a, Renderer: Renderer + Renderer + Renderer + Renderer + 'a, Font: Into<Renderer::Font>,

Examples found in repository?
examples/showcase/app.rs (lines 637-641)
619fn view(state: &Showcase) -> material::Element<'_, Message> {
620    let now = Instant::now();
621    let navigation_layout = state.adaptive_navigation_layout();
622    let page_content = material::widget::snackbar::host_with(
623        pages::view(state),
624        &state.snackbar,
625        now,
626        "Photo archived",
627        "Undo",
628        Message::SnackbarUndo,
629        snackbar_host_options(&state.theme_controller),
630    );
631
632    let navigation_suite = navigation::suite(&NAV_DESTINATIONS, &state.navigation)
633        .layout(navigation_layout)
634        .with_menu("Showcase", Message::MenuPressed)
635        .compact_navigation(showcase_compact_navigation());
636    let content = navigation_suite.view(Message::Navigate, page_content);
637    let content = state.theme_controller.controls_over(
638        content,
639        showcase_floating_bottom_margin(navigation_layout),
640        Message::ThemeChanged,
641    );
642
643    let content = material::widget::dialog::modal_animated(
644        content,
645        &state.login_dialog,
646        now,
647        login_dialog(state, state.login_dialog.alpha(now)),
648    );
649
650    state.theme_controller.reveal_over(content, now)
651}
Source

pub fn reveal_over<'a, Message, Renderer>( &self, content: impl Into<Element<'a, Message, Theme, Renderer>>, now: Instant, ) -> Element<'a, Message, Theme, Renderer>
where Message: 'a, Renderer: Renderer + Renderer + 'a,

Examples found in repository?
examples/showcase/app.rs (line 650)
619fn view(state: &Showcase) -> material::Element<'_, Message> {
620    let now = Instant::now();
621    let navigation_layout = state.adaptive_navigation_layout();
622    let page_content = material::widget::snackbar::host_with(
623        pages::view(state),
624        &state.snackbar,
625        now,
626        "Photo archived",
627        "Undo",
628        Message::SnackbarUndo,
629        snackbar_host_options(&state.theme_controller),
630    );
631
632    let navigation_suite = navigation::suite(&NAV_DESTINATIONS, &state.navigation)
633        .layout(navigation_layout)
634        .with_menu("Showcase", Message::MenuPressed)
635        .compact_navigation(showcase_compact_navigation());
636    let content = navigation_suite.view(Message::Navigate, page_content);
637    let content = state.theme_controller.controls_over(
638        content,
639        showcase_floating_bottom_margin(navigation_layout),
640        Message::ThemeChanged,
641    );
642
643    let content = material::widget::dialog::modal_animated(
644        content,
645        &state.login_dialog,
646        now,
647        login_dialog(state, state.login_dialog.alpha(now)),
648    );
649
650    state.theme_controller.reveal_over(content, now)
651}

Trait Implementations§

Source§

impl Clone for ThemeController

Source§

fn clone(&self) -> ThemeController

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 Debug for ThemeController

Source§

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

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

impl Default for ThemeController

Source§

fn default() -> Self

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

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 = !

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

fn try_from(value: U) -> Result<T, !>

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