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 221)
220    fn theme(&self) -> Theme {
221        self.theme_controller.theme("Material 3 animated")
222    }
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 388)
384fn subscription(state: &Showcase) -> Subscription<Message> {
385    let mut subscriptions =
386        vec![iced::window::resize_events().map(|(_id, size)| Message::WindowResized(size))];
387
388    if state.theme_controller.is_animating()
389        || state.navigation.is_animating()
390        || state.segment_state.is_animating()
391        || state.primary_tab_state.is_animating()
392        || state.secondary_tab_state.is_animating()
393        || state.alert_dialog.is_animating()
394        || state.snackbar.is_active()
395        || state.date_picker.is_animating()
396        || state.date_range_picker.is_animating()
397        || state.time_picker.is_animating()
398        || (state.navigation.selected() == ShowcasePage::Feedback
399            && state.progress_animation.is_animating())
400    {
401        subscriptions.push(iced::window::frames().map(Message::Frame));
402    }
403
404    Subscription::batch(subscriptions)
405}
Source

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

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

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

Examples found in repository?
examples/showcase/app.rs (line 364)
233fn update(state: &mut Showcase, message: Message) -> Task<Message> {
234    match message {
235        Message::Navigate(page) => {
236            state
237                .navigation
238                .select(page, Instant::now(), state.adaptive_navigation_layout());
239            Task::none()
240        }
241        Message::Increment => {
242            state.count += 1;
243            Task::none()
244        }
245        Message::Decrement => {
246            state.count -= 1;
247            Task::none()
248        }
249        Message::TextChanged(note) => {
250            state.note = note;
251            Task::none()
252        }
253        Message::EditorAction(action) => {
254            state.editor_content.perform(action);
255            Task::none()
256        }
257        Message::SelectChanged(choice) => {
258            state.select_choice = Some(choice);
259            Task::none()
260        }
261        Message::ComboboxSelected(choice) => {
262            state.combobox_choice = Some(choice);
263            state.combobox_input.clear();
264            state.combobox_options.set_selection(Some(&choice));
265            Task::none()
266        }
267        Message::ComboboxInputChanged(input) => {
268            state.combobox_options.set_input(input.clone());
269            state.combobox_input = input;
270            state.combobox_choice = None;
271            Task::none()
272        }
273        Message::SearchChanged(query) => {
274            state.search_query = query;
275            Task::none()
276        }
277        Message::DatePickerChanged(action) => state
278            .date_picker
279            .update_and_scroll_to_displayed_year(action),
280        Message::DateRangePickerChanged(action) => state
281            .date_range_picker
282            .update_and_scroll_to_displayed_year(action),
283        Message::TimePickerChanged(action) => {
284            state.time_picker.update(action);
285            Task::none()
286        }
287        Message::SliderChanged(progress) => {
288            state.progress = progress;
289            Task::none()
290        }
291        Message::EnabledChanged(enabled) => {
292            state.enabled = enabled;
293            Task::none()
294        }
295        Message::ChoiceSelected(choice) => {
296            state.radio_choice = Some(choice);
297            Task::none()
298        }
299        Message::SegmentSelected(choice) => {
300            state.segment_choice = choice;
301            state.segment_state.select(choice.index(), Instant::now());
302            Task::none()
303        }
304        Message::PrimaryTabSelected(choice) => {
305            state.primary_tab = choice;
306            state.primary_tab_state.select(
307                choice.index(),
308                Instant::now(),
309                material::widget::tabs::Variant::Primary,
310            );
311            Task::none()
312        }
313        Message::SecondaryTabSelected(choice) => {
314            state.secondary_tab = choice;
315            state.secondary_tab_state.select(
316                choice.index(),
317                Instant::now(),
318                material::widget::tabs::Variant::Secondary,
319            );
320            Task::none()
321        }
322        Message::MenuPressed => {
323            state.navigation.toggle_menu_now();
324            Task::none()
325        }
326        Message::DialogOpened => {
327            state.alert_dialog.show(Instant::now());
328            Task::none()
329        }
330        Message::DialogDismissed => {
331            state.alert_dialog.dismiss(Instant::now());
332            Task::none()
333        }
334        Message::DialogConfirmed => {
335            state.alert_dialog.dismiss(Instant::now());
336            state.count += 1;
337            Task::none()
338        }
339        Message::ShowSnackbar => {
340            state.snackbar.show(Instant::now());
341            Task::none()
342        }
343        Message::SnackbarUndo => {
344            state.count -= 1;
345            state.snackbar.dismiss(Instant::now());
346            Task::none()
347        }
348        Message::WindowResized(size) => {
349            state.window_size = size;
350            Task::none()
351        }
352        Message::ThemeChanged(action) => {
353            state.theme_controller.update(
354                action,
355                state.window_size,
356                theme_picker::bottom_margin_for_navigation_layout(
357                    state.adaptive_navigation_layout(),
358                ),
359                Instant::now(),
360            );
361            Task::none()
362        }
363        Message::Frame(now) => {
364            let _ = state.theme_controller.advance(now);
365            let _ = state.navigation.advance(now);
366            let _ = state.segment_state.advance(now);
367            let _ = state.primary_tab_state.advance(now);
368            let _ = state.secondary_tab_state.advance(now);
369            state.progress_animation.advance(now);
370            let _ = state.alert_dialog.advance(now);
371            let _ = state.snackbar.advance(now);
372            let _ = state.date_picker.advance(now);
373            let _ = state.date_range_picker.advance(now);
374            let _ = state.time_picker.advance(now);
375            Task::none()
376        }
377    }
378}
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 114)
104fn selection_controls(state: &Showcase) -> material::Element<'_, Message> {
105    let switches = page::component_stack([
106        material::widget::checkbox::standard(
107            state.enabled,
108            "Enable actions",
109            Message::EnabledChanged,
110        )
111        .into(),
112        state
113            .theme_controller
114            .dark_mode_switch("Dark theme", Message::ThemeChanged)
115            .into(),
116    ]);
117
118    let radios = page::row([
119        material::widget::radio::standard(
120            "Standard",
121            RadioChoice::Standard,
122            state.radio_choice,
123            Message::ChoiceSelected,
124        )
125        .into(),
126        material::widget::radio::standard(
127            "Expressive",
128            RadioChoice::Expressive,
129            state.radio_choice,
130            Message::ChoiceSelected,
131        )
132        .into(),
133        material::widget::radio::standard(
134            "Dense",
135            RadioChoice::Dense,
136            state.radio_choice,
137            Message::ChoiceSelected,
138        )
139        .into(),
140    ]);
141
142    page::spacious_stack([switches.into(), radios.into()]).into()
143}
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 422-426)
407fn view(state: &Showcase) -> material::Element<'_, Message> {
408    let now = Instant::now();
409    let page_content = material::widget::snackbar::host_single_line_with_action(
410        pages::view(state),
411        &state.snackbar,
412        now,
413        "Photo archived",
414        "Undo",
415        Message::SnackbarUndo,
416    );
417
418    let content = navigation::suite(&NAV_DESTINATIONS, &state.navigation)
419        .layout(state.adaptive_navigation_layout())
420        .with_menu("Showcase", Message::MenuPressed)
421        .view(Message::Navigate, page_content);
422    let content = state.theme_controller.controls_over(
423        content,
424        theme_picker::bottom_margin_for_navigation_layout(state.adaptive_navigation_layout()),
425        Message::ThemeChanged,
426    );
427
428    let content = material::widget::dialog::modal_animated(
429        content,
430        &state.alert_dialog,
431        now,
432        alert_dialog(state.alert_dialog.alpha(now)),
433    );
434
435    state.theme_controller.reveal_over(content, now)
436}
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 435)
407fn view(state: &Showcase) -> material::Element<'_, Message> {
408    let now = Instant::now();
409    let page_content = material::widget::snackbar::host_single_line_with_action(
410        pages::view(state),
411        &state.snackbar,
412        now,
413        "Photo archived",
414        "Undo",
415        Message::SnackbarUndo,
416    );
417
418    let content = navigation::suite(&NAV_DESTINATIONS, &state.navigation)
419        .layout(state.adaptive_navigation_layout())
420        .with_menu("Showcase", Message::MenuPressed)
421        .view(Message::Navigate, page_content);
422    let content = state.theme_controller.controls_over(
423        content,
424        theme_picker::bottom_margin_for_navigation_layout(state.adaptive_navigation_layout()),
425        Message::ThemeChanged,
426    );
427
428    let content = material::widget::dialog::modal_animated(
429        content,
430        &state.alert_dialog,
431        now,
432        alert_dialog(state.alert_dialog.alpha(now)),
433    );
434
435    state.theme_controller.reveal_over(content, now)
436}

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 + Send + Sync>

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