pub struct ThemeController { /* private fields */ }Implementations§
Source§impl ThemeController
impl ThemeController
pub fn new(selected: MaterialColor, dark_mode: bool) -> Self
pub const fn picker_state(&self) -> &State
pub const fn is_picker_open(&self) -> bool
pub const fn selected_color(&self) -> MaterialColor
pub const fn dark_mode(&self) -> bool
pub const fn visible_scheme(&self) -> ColorScheme
pub const fn transition(&self) -> Option<ThemeRevealTransition>
Sourcepub const fn is_animating(&self) -> bool
pub const fn is_animating(&self) -> bool
Examples found in repository?
examples/showcase/app.rs (line 578)
574fn subscription(state: &Showcase) -> Subscription<Message> {
575 let mut subscriptions =
576 vec![iced::window::resize_events().map(|(_id, size)| Message::WindowResized(size))];
577
578 if state.theme_controller.is_animating()
579 || state.navigation.is_animating()
580 || state.segment_state.is_animating()
581 || state.primary_tab_state.is_animating()
582 || state.secondary_tab_state.is_animating()
583 || state.log_viewer.is_animating()
584 || state.alert_dialog.is_animating()
585 || state.snackbar.is_active()
586 || state.date_picker.is_animating()
587 || state.date_range_picker.is_animating()
588 || state.time_picker.is_animating()
589 || (state.navigation.selected() == ShowcasePage::Feedback
590 && state.progress_animation.is_animating())
591 {
592 subscriptions.push(iced::window::frames().map(Message::Frame));
593 }
594
595 Subscription::batch(subscriptions)
596}Sourcepub fn update(
&mut self,
action: ThemeAction,
viewport: Size,
bottom_margin: f32,
now: Instant,
)
pub fn update( &mut self, action: ThemeAction, viewport: Size, bottom_margin: f32, now: Instant, )
Examples found in repository?
examples/showcase/app.rs (lines 382-387)
259fn update(state: &mut Showcase, message: Message) -> Task<Message> {
260 match message {
261 #[cfg(any(target_arch = "wasm32", test))]
262 Message::CjkCoreFontFinished => load_cjk_regional_font(),
263 #[cfg(any(target_arch = "wasm32", test))]
264 Message::CjkRegionalFontFinished => Task::none(),
265 Message::Navigate(page) => {
266 state
267 .navigation
268 .select(page, Instant::now(), state.adaptive_navigation_layout());
269 Task::none()
270 }
271 Message::Increment => {
272 state.count += 1;
273 Task::none()
274 }
275 Message::Decrement => {
276 state.count -= 1;
277 Task::none()
278 }
279 Message::TextChanged(note) => {
280 state.note = note;
281 Task::none()
282 }
283 Message::EditorAction(action) => {
284 state.editor_content.perform(action);
285 Task::none()
286 }
287 Message::SelectChanged(choice) => {
288 state.select_choice = Some(choice);
289 Task::none()
290 }
291 Message::ComboboxSelected(choice) => {
292 state.combobox_choice = Some(choice);
293 state.combobox_input.clear();
294 state.combobox_options.set_selection(Some(&choice));
295 Task::none()
296 }
297 Message::ComboboxInputChanged(input) => {
298 state.combobox_options.set_input(input.clone());
299 state.combobox_input = input;
300 state.combobox_choice = None;
301 Task::none()
302 }
303 Message::SearchChanged(query) => {
304 state.search_query = query;
305 Task::none()
306 }
307 Message::DatePickerChanged(action) => state.date_picker.update_and_scroll(action),
308 Message::DateRangePickerChanged(action) => {
309 state.date_range_picker.update_and_scroll(action)
310 }
311 Message::TimePickerChanged(action) => {
312 state.time_picker.update(action);
313 Task::none()
314 }
315 Message::SliderChanged(progress) => {
316 state.progress = progress;
317 Task::none()
318 }
319 Message::EnabledChanged(enabled) => {
320 state.enabled = enabled;
321 Task::none()
322 }
323 Message::ChoiceSelected(choice) => {
324 state.radio_choice = Some(choice);
325 Task::none()
326 }
327 Message::SegmentSelected(choice) => {
328 state.segment_choice = choice;
329 state.segment_state.select(choice.index(), Instant::now());
330 Task::none()
331 }
332 Message::PrimaryTabSelected(choice) => {
333 state.primary_tab = choice;
334 state.primary_tab_state.select(
335 choice.index(),
336 Instant::now(),
337 material::widget::tabs::Variant::Primary,
338 );
339 Task::none()
340 }
341 Message::SecondaryTabSelected(choice) => {
342 state.secondary_tab = choice;
343 state.secondary_tab_state.select(
344 choice.index(),
345 Instant::now(),
346 material::widget::tabs::Variant::Secondary,
347 );
348 Task::none()
349 }
350 Message::LogViewer(action) => state.log_viewer.update(action, &state.log_entries),
351 Message::MenuPressed => {
352 state.navigation.toggle_menu_now_for_size(state.window_size);
353 Task::none()
354 }
355 Message::DialogOpened => {
356 state.alert_dialog.show(Instant::now());
357 Task::none()
358 }
359 Message::DialogDismissed => {
360 state.alert_dialog.dismiss(Instant::now());
361 Task::none()
362 }
363 Message::DialogConfirmed => {
364 state.alert_dialog.dismiss(Instant::now());
365 state.count += 1;
366 Task::none()
367 }
368 Message::ShowSnackbar => {
369 state.snackbar.show(Instant::now());
370 Task::none()
371 }
372 Message::SnackbarUndo => {
373 state.count -= 1;
374 state.snackbar.dismiss(Instant::now());
375 Task::none()
376 }
377 Message::WindowResized(size) => {
378 state.window_size = size;
379 Task::none()
380 }
381 Message::ThemeChanged(action) => {
382 state.theme_controller.update(
383 action,
384 state.window_size,
385 theme_picker::bottom_margin(state.adaptive_navigation_layout()),
386 Instant::now(),
387 );
388 Task::none()
389 }
390 Message::Frame(now) => {
391 let _ = state.theme_controller.advance(now);
392 let _ = state.navigation.advance(now);
393 let _ = state.segment_state.advance(now);
394 let _ = state.primary_tab_state.advance(now);
395 let _ = state.secondary_tab_state.advance(now);
396 let _ = state.log_viewer.advance(now);
397 state.progress_animation.advance(now);
398 let _ = state.alert_dialog.advance(now);
399 let _ = state.snackbar.advance(now);
400 let _ = state.date_picker.advance(now);
401 let _ = state.date_range_picker.advance(now);
402 let _ = state.time_picker.advance(now);
403 Task::none()
404 }
405 }
406}Sourcepub fn advance(&mut self, now: Instant) -> bool
pub fn advance(&mut self, now: Instant) -> bool
Examples found in repository?
examples/showcase/app.rs (line 391)
259fn update(state: &mut Showcase, message: Message) -> Task<Message> {
260 match message {
261 #[cfg(any(target_arch = "wasm32", test))]
262 Message::CjkCoreFontFinished => load_cjk_regional_font(),
263 #[cfg(any(target_arch = "wasm32", test))]
264 Message::CjkRegionalFontFinished => Task::none(),
265 Message::Navigate(page) => {
266 state
267 .navigation
268 .select(page, Instant::now(), state.adaptive_navigation_layout());
269 Task::none()
270 }
271 Message::Increment => {
272 state.count += 1;
273 Task::none()
274 }
275 Message::Decrement => {
276 state.count -= 1;
277 Task::none()
278 }
279 Message::TextChanged(note) => {
280 state.note = note;
281 Task::none()
282 }
283 Message::EditorAction(action) => {
284 state.editor_content.perform(action);
285 Task::none()
286 }
287 Message::SelectChanged(choice) => {
288 state.select_choice = Some(choice);
289 Task::none()
290 }
291 Message::ComboboxSelected(choice) => {
292 state.combobox_choice = Some(choice);
293 state.combobox_input.clear();
294 state.combobox_options.set_selection(Some(&choice));
295 Task::none()
296 }
297 Message::ComboboxInputChanged(input) => {
298 state.combobox_options.set_input(input.clone());
299 state.combobox_input = input;
300 state.combobox_choice = None;
301 Task::none()
302 }
303 Message::SearchChanged(query) => {
304 state.search_query = query;
305 Task::none()
306 }
307 Message::DatePickerChanged(action) => state.date_picker.update_and_scroll(action),
308 Message::DateRangePickerChanged(action) => {
309 state.date_range_picker.update_and_scroll(action)
310 }
311 Message::TimePickerChanged(action) => {
312 state.time_picker.update(action);
313 Task::none()
314 }
315 Message::SliderChanged(progress) => {
316 state.progress = progress;
317 Task::none()
318 }
319 Message::EnabledChanged(enabled) => {
320 state.enabled = enabled;
321 Task::none()
322 }
323 Message::ChoiceSelected(choice) => {
324 state.radio_choice = Some(choice);
325 Task::none()
326 }
327 Message::SegmentSelected(choice) => {
328 state.segment_choice = choice;
329 state.segment_state.select(choice.index(), Instant::now());
330 Task::none()
331 }
332 Message::PrimaryTabSelected(choice) => {
333 state.primary_tab = choice;
334 state.primary_tab_state.select(
335 choice.index(),
336 Instant::now(),
337 material::widget::tabs::Variant::Primary,
338 );
339 Task::none()
340 }
341 Message::SecondaryTabSelected(choice) => {
342 state.secondary_tab = choice;
343 state.secondary_tab_state.select(
344 choice.index(),
345 Instant::now(),
346 material::widget::tabs::Variant::Secondary,
347 );
348 Task::none()
349 }
350 Message::LogViewer(action) => state.log_viewer.update(action, &state.log_entries),
351 Message::MenuPressed => {
352 state.navigation.toggle_menu_now_for_size(state.window_size);
353 Task::none()
354 }
355 Message::DialogOpened => {
356 state.alert_dialog.show(Instant::now());
357 Task::none()
358 }
359 Message::DialogDismissed => {
360 state.alert_dialog.dismiss(Instant::now());
361 Task::none()
362 }
363 Message::DialogConfirmed => {
364 state.alert_dialog.dismiss(Instant::now());
365 state.count += 1;
366 Task::none()
367 }
368 Message::ShowSnackbar => {
369 state.snackbar.show(Instant::now());
370 Task::none()
371 }
372 Message::SnackbarUndo => {
373 state.count -= 1;
374 state.snackbar.dismiss(Instant::now());
375 Task::none()
376 }
377 Message::WindowResized(size) => {
378 state.window_size = size;
379 Task::none()
380 }
381 Message::ThemeChanged(action) => {
382 state.theme_controller.update(
383 action,
384 state.window_size,
385 theme_picker::bottom_margin(state.adaptive_navigation_layout()),
386 Instant::now(),
387 );
388 Task::none()
389 }
390 Message::Frame(now) => {
391 let _ = state.theme_controller.advance(now);
392 let _ = state.navigation.advance(now);
393 let _ = state.segment_state.advance(now);
394 let _ = state.primary_tab_state.advance(now);
395 let _ = state.secondary_tab_state.advance(now);
396 let _ = state.log_viewer.advance(now);
397 state.progress_animation.advance(now);
398 let _ = state.alert_dialog.advance(now);
399 let _ = state.snackbar.advance(now);
400 let _ = state.date_picker.advance(now);
401 let _ = state.date_range_picker.advance(now);
402 let _ = state.time_picker.advance(now);
403 Task::none()
404 }
405 }
406}Sourcepub fn dark_mode_switch<'a, Message, Renderer>(
&self,
label: impl IntoFragment<'a>,
on_action: impl Fn(ThemeAction) -> Message + 'a,
) -> Element<'a, Message, Theme, Renderer>
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>
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}Sourcepub 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>
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>
Examples found in repository?
examples/showcase/app.rs (lines 616-620)
598fn view(state: &Showcase) -> material::Element<'_, Message> {
599 let now = Instant::now();
600 let page_content = material::widget::snackbar::host(
601 pages::view(state),
602 &state.snackbar,
603 now,
604 "Photo archived",
605 "Undo",
606 Message::SnackbarUndo,
607 );
608
609 let navigation_suite = navigation::suite(&NAV_DESTINATIONS, &state.navigation)
610 .layout(state.adaptive_navigation_layout())
611 .with_menu("Showcase", Message::MenuPressed);
612 #[cfg(target_os = "android")]
613 let navigation_suite =
614 navigation_suite.compact_navigation(navigation::CompactNavigation::ModalDrawer);
615 let content = navigation_suite.view(Message::Navigate, page_content);
616 let content = state.theme_controller.controls_over(
617 content,
618 theme_picker::bottom_margin(state.adaptive_navigation_layout()),
619 Message::ThemeChanged,
620 );
621
622 let content = material::widget::dialog::modal_animated(
623 content,
624 &state.alert_dialog,
625 now,
626 alert_dialog(state.alert_dialog.alpha(now)),
627 );
628
629 state.theme_controller.reveal_over(content, now)
630}Sourcepub fn reveal_over<'a, Message, Renderer>(
&self,
content: impl Into<Element<'a, Message, Theme, Renderer>>,
now: Instant,
) -> Element<'a, Message, Theme, Renderer>
pub fn reveal_over<'a, Message, Renderer>( &self, content: impl Into<Element<'a, Message, Theme, Renderer>>, now: Instant, ) -> Element<'a, Message, Theme, Renderer>
Examples found in repository?
examples/showcase/app.rs (line 629)
598fn view(state: &Showcase) -> material::Element<'_, Message> {
599 let now = Instant::now();
600 let page_content = material::widget::snackbar::host(
601 pages::view(state),
602 &state.snackbar,
603 now,
604 "Photo archived",
605 "Undo",
606 Message::SnackbarUndo,
607 );
608
609 let navigation_suite = navigation::suite(&NAV_DESTINATIONS, &state.navigation)
610 .layout(state.adaptive_navigation_layout())
611 .with_menu("Showcase", Message::MenuPressed);
612 #[cfg(target_os = "android")]
613 let navigation_suite =
614 navigation_suite.compact_navigation(navigation::CompactNavigation::ModalDrawer);
615 let content = navigation_suite.view(Message::Navigate, page_content);
616 let content = state.theme_controller.controls_over(
617 content,
618 theme_picker::bottom_margin(state.adaptive_navigation_layout()),
619 Message::ThemeChanged,
620 );
621
622 let content = material::widget::dialog::modal_animated(
623 content,
624 &state.alert_dialog,
625 now,
626 alert_dialog(state.alert_dialog.alpha(now)),
627 );
628
629 state.theme_controller.reveal_over(content, now)
630}Trait Implementations§
Source§impl Clone for ThemeController
impl Clone for ThemeController
Source§fn clone(&self) -> ThemeController
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ThemeController
impl Debug for ThemeController
Auto Trait Implementations§
impl Freeze for ThemeController
impl RefUnwindSafe for ThemeController
impl Send for ThemeController
impl Sync for ThemeController
impl Unpin for ThemeController
impl UnsafeUnpin for ThemeController
impl UnwindSafe for ThemeController
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
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>
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)
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)
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> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<State, Message> IntoBoot<State, Message> for State
impl<State, Message> IntoBoot<State, Message> for State
Source§fn into_boot(self) -> (State, Task<Message>)
fn into_boot(self) -> (State, Task<Message>)
Turns some type into the initial state of some
Application.