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 384)
380fn subscription(state: &Showcase) -> Subscription<Message> {
381 let mut subscriptions =
382 vec![iced::window::resize_events().map(|(_id, size)| Message::WindowResized(size))];
383
384 if state.theme_controller.is_animating()
385 || state.navigation.is_animating()
386 || state.segment_state.is_animating()
387 || state.primary_tab_state.is_animating()
388 || state.secondary_tab_state.is_animating()
389 || state.alert_dialog.is_animating()
390 || state.snackbar.is_active()
391 || state.date_picker.is_animating()
392 || state.date_range_picker.is_animating()
393 || state.time_picker.is_animating()
394 || (state.navigation.selected() == ShowcasePage::Feedback
395 && state.progress_animation.is_animating())
396 {
397 subscriptions.push(iced::window::frames().map(Message::Frame));
398 }
399
400 Subscription::batch(subscriptions)
401}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 351-356)
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.date_picker.update_and_scroll(action),
278 Message::DateRangePickerChanged(action) => {
279 state.date_range_picker.update_and_scroll(action)
280 }
281 Message::TimePickerChanged(action) => {
282 state.time_picker.update(action);
283 Task::none()
284 }
285 Message::SliderChanged(progress) => {
286 state.progress = progress;
287 Task::none()
288 }
289 Message::EnabledChanged(enabled) => {
290 state.enabled = enabled;
291 Task::none()
292 }
293 Message::ChoiceSelected(choice) => {
294 state.radio_choice = Some(choice);
295 Task::none()
296 }
297 Message::SegmentSelected(choice) => {
298 state.segment_choice = choice;
299 state.segment_state.select(choice.index(), Instant::now());
300 Task::none()
301 }
302 Message::PrimaryTabSelected(choice) => {
303 state.primary_tab = choice;
304 state.primary_tab_state.select(
305 choice.index(),
306 Instant::now(),
307 material::widget::tabs::Variant::Primary,
308 );
309 Task::none()
310 }
311 Message::SecondaryTabSelected(choice) => {
312 state.secondary_tab = choice;
313 state.secondary_tab_state.select(
314 choice.index(),
315 Instant::now(),
316 material::widget::tabs::Variant::Secondary,
317 );
318 Task::none()
319 }
320 Message::MenuPressed => {
321 state.navigation.toggle_menu_now();
322 Task::none()
323 }
324 Message::DialogOpened => {
325 state.alert_dialog.show(Instant::now());
326 Task::none()
327 }
328 Message::DialogDismissed => {
329 state.alert_dialog.dismiss(Instant::now());
330 Task::none()
331 }
332 Message::DialogConfirmed => {
333 state.alert_dialog.dismiss(Instant::now());
334 state.count += 1;
335 Task::none()
336 }
337 Message::ShowSnackbar => {
338 state.snackbar.show(Instant::now());
339 Task::none()
340 }
341 Message::SnackbarUndo => {
342 state.count -= 1;
343 state.snackbar.dismiss(Instant::now());
344 Task::none()
345 }
346 Message::WindowResized(size) => {
347 state.window_size = size;
348 Task::none()
349 }
350 Message::ThemeChanged(action) => {
351 state.theme_controller.update(
352 action,
353 state.window_size,
354 theme_picker::bottom_margin(state.adaptive_navigation_layout()),
355 Instant::now(),
356 );
357 Task::none()
358 }
359 Message::Frame(now) => {
360 let _ = state.theme_controller.advance(now);
361 let _ = state.navigation.advance(now);
362 let _ = state.segment_state.advance(now);
363 let _ = state.primary_tab_state.advance(now);
364 let _ = state.secondary_tab_state.advance(now);
365 state.progress_animation.advance(now);
366 let _ = state.alert_dialog.advance(now);
367 let _ = state.snackbar.advance(now);
368 let _ = state.date_picker.advance(now);
369 let _ = state.date_range_picker.advance(now);
370 let _ = state.time_picker.advance(now);
371 Task::none()
372 }
373 }
374}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 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.date_picker.update_and_scroll(action),
278 Message::DateRangePickerChanged(action) => {
279 state.date_range_picker.update_and_scroll(action)
280 }
281 Message::TimePickerChanged(action) => {
282 state.time_picker.update(action);
283 Task::none()
284 }
285 Message::SliderChanged(progress) => {
286 state.progress = progress;
287 Task::none()
288 }
289 Message::EnabledChanged(enabled) => {
290 state.enabled = enabled;
291 Task::none()
292 }
293 Message::ChoiceSelected(choice) => {
294 state.radio_choice = Some(choice);
295 Task::none()
296 }
297 Message::SegmentSelected(choice) => {
298 state.segment_choice = choice;
299 state.segment_state.select(choice.index(), Instant::now());
300 Task::none()
301 }
302 Message::PrimaryTabSelected(choice) => {
303 state.primary_tab = choice;
304 state.primary_tab_state.select(
305 choice.index(),
306 Instant::now(),
307 material::widget::tabs::Variant::Primary,
308 );
309 Task::none()
310 }
311 Message::SecondaryTabSelected(choice) => {
312 state.secondary_tab = choice;
313 state.secondary_tab_state.select(
314 choice.index(),
315 Instant::now(),
316 material::widget::tabs::Variant::Secondary,
317 );
318 Task::none()
319 }
320 Message::MenuPressed => {
321 state.navigation.toggle_menu_now();
322 Task::none()
323 }
324 Message::DialogOpened => {
325 state.alert_dialog.show(Instant::now());
326 Task::none()
327 }
328 Message::DialogDismissed => {
329 state.alert_dialog.dismiss(Instant::now());
330 Task::none()
331 }
332 Message::DialogConfirmed => {
333 state.alert_dialog.dismiss(Instant::now());
334 state.count += 1;
335 Task::none()
336 }
337 Message::ShowSnackbar => {
338 state.snackbar.show(Instant::now());
339 Task::none()
340 }
341 Message::SnackbarUndo => {
342 state.count -= 1;
343 state.snackbar.dismiss(Instant::now());
344 Task::none()
345 }
346 Message::WindowResized(size) => {
347 state.window_size = size;
348 Task::none()
349 }
350 Message::ThemeChanged(action) => {
351 state.theme_controller.update(
352 action,
353 state.window_size,
354 theme_picker::bottom_margin(state.adaptive_navigation_layout()),
355 Instant::now(),
356 );
357 Task::none()
358 }
359 Message::Frame(now) => {
360 let _ = state.theme_controller.advance(now);
361 let _ = state.navigation.advance(now);
362 let _ = state.segment_state.advance(now);
363 let _ = state.primary_tab_state.advance(now);
364 let _ = state.secondary_tab_state.advance(now);
365 state.progress_animation.advance(now);
366 let _ = state.alert_dialog.advance(now);
367 let _ = state.snackbar.advance(now);
368 let _ = state.date_picker.advance(now);
369 let _ = state.date_range_picker.advance(now);
370 let _ = state.time_picker.advance(now);
371 Task::none()
372 }
373 }
374}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 418-422)
403fn view(state: &Showcase) -> material::Element<'_, Message> {
404 let now = Instant::now();
405 let page_content = material::widget::snackbar::host(
406 pages::view(state),
407 &state.snackbar,
408 now,
409 "Photo archived",
410 "Undo",
411 Message::SnackbarUndo,
412 );
413
414 let content = navigation::suite(&NAV_DESTINATIONS, &state.navigation)
415 .layout(state.adaptive_navigation_layout())
416 .with_menu("Showcase", Message::MenuPressed)
417 .view(Message::Navigate, page_content);
418 let content = state.theme_controller.controls_over(
419 content,
420 theme_picker::bottom_margin(state.adaptive_navigation_layout()),
421 Message::ThemeChanged,
422 );
423
424 let content = material::widget::dialog::modal_animated(
425 content,
426 &state.alert_dialog,
427 now,
428 alert_dialog(state.alert_dialog.alpha(now)),
429 );
430
431 state.theme_controller.reveal_over(content, now)
432}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 431)
403fn view(state: &Showcase) -> material::Element<'_, Message> {
404 let now = Instant::now();
405 let page_content = material::widget::snackbar::host(
406 pages::view(state),
407 &state.snackbar,
408 now,
409 "Photo archived",
410 "Undo",
411 Message::SnackbarUndo,
412 );
413
414 let content = navigation::suite(&NAV_DESTINATIONS, &state.navigation)
415 .layout(state.adaptive_navigation_layout())
416 .with_menu("Showcase", Message::MenuPressed)
417 .view(Message::Navigate, page_content);
418 let content = state.theme_controller.controls_over(
419 content,
420 theme_picker::bottom_margin(state.adaptive_navigation_layout()),
421 Message::ThemeChanged,
422 );
423
424 let content = material::widget::dialog::modal_animated(
425 content,
426 &state.alert_dialog,
427 now,
428 alert_dialog(state.alert_dialog.alpha(now)),
429 );
430
431 state.theme_controller.reveal_over(content, now)
432}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.