pub struct DateRangePickerState { /* private fields */ }Expand description
State held by a Material date range picker.
Implementations§
Source§impl DateRangePickerState
impl DateRangePickerState
Sourcepub fn new(
selected_start_date: Option<Date>,
selected_end_date: Option<Date>,
) -> Self
pub fn new( selected_start_date: Option<Date>, selected_end_date: Option<Date>, ) -> Self
Creates date range picker state with the default Material year range (1900..=2100).
Examples found in repository?
197 fn default() -> Self {
198 Self {
199 navigation: navigation::NavigationState::new(ShowcasePage::Inputs),
200 window_size: Size::new(1080.0, 980.0),
201 count: 0,
202 note: String::new(),
203 editor_content: material::widget::text_editor::Content::with_text(
204 "Material 3 multi-line text editor",
205 ),
206 select_choice: Some("Assist"),
207 combobox_options: material::widget::combobox::State::with_selection(
208 vec!["Assist", "Suggestion", "Filter"],
209 Some(&"Suggestion"),
210 ),
211 combobox_choice: Some("Suggestion"),
212 combobox_input: String::new(),
213 search_query: String::new(),
214 date_picker: material::widget::picker::DatePickerState::new(
215 material::widget::picker::Date::new(2026, 7, 4),
216 ),
217 date_range_picker: material::widget::picker::DateRangePickerState::new(
218 material::widget::picker::Date::new(2026, 7, 4),
219 material::widget::picker::Date::new(2026, 7, 10),
220 ),
221 time_picker: material::widget::picker::TimePickerState::new(14, 30, false),
222 progress: 42.0,
223 enabled: true,
224 radio_choice: Some(RadioChoice::Standard),
225 segment_choice: SegmentChoice::List,
226 segment_state: material::widget::segmented_button::State::new(
227 SegmentChoice::List.index(),
228 ),
229 primary_tab: TabChoice::Inputs,
230 primary_tab_state: material::widget::tabs::State::new(TabChoice::Inputs.index()),
231 secondary_tab: TabChoice::Controls,
232 secondary_tab_state: material::widget::tabs::State::new(TabChoice::Controls.index()),
233 log_viewer: material::widget::log_viewer::State::new(),
234 log_entries: sample_log_entries(),
235 progress_animation: material::widget::progress_bar::IndeterminateState::new(
236 Instant::now(),
237 ),
238 alert_dialog: material::widget::dialog::Transition::default(),
239 snackbar: material::widget::snackbar::Transition::default(),
240 theme_controller: theme_picker::ThemeController::default(),
241 }
242 }pub fn year_range(self, year_range: RangeInclusive<i32>) -> Self
Sourcepub fn initial_displayed_month(self, displayed_month: YearMonth) -> Self
pub fn initial_displayed_month(self, displayed_month: YearMonth) -> Self
Sets the initially displayed month independently from the selected range.
Months outside the configured year range are ignored, matching Material state semantics.
pub fn selectable_dates(self, selectable_dates: SelectableDates) -> Self
Sourcepub fn first_day_of_week(self, first_day_of_week: Weekday) -> Self
pub fn first_day_of_week(self, first_day_of_week: Weekday) -> Self
Sets the first day of week used by the calendar grid.
Sourcepub fn formatter(self, formatter: DatePickerFormatter) -> Self
pub fn formatter(self, formatter: DatePickerFormatter) -> Self
Sets date display formatting hooks.
pub fn selected_start_date(&self) -> Option<Date>
pub fn selected_end_date(&self) -> Option<Date>
pub fn displayed_month(&self) -> YearMonth
pub fn year_picker_visible(&self) -> bool
pub fn display_mode(&self) -> DateDisplayMode
pub fn calendar_first_day_of_week(&self) -> Weekday
pub fn date_formatter(&self) -> &DatePickerFormatter
pub fn start_input_value(&self) -> &str
pub fn end_input_value(&self) -> &str
Sourcepub fn scroll_to_displayed_month<Message>(&self) -> Task<Message>where
Message: Send + 'static,
pub fn scroll_to_displayed_month<Message>(&self) -> Task<Message>where
Message: Send + 'static,
Returns a task that positions the range month list at the displayed month.
Sourcepub fn scroll_to_year<Message>(&self) -> Task<Message>where
Message: Send + 'static,
pub fn scroll_to_year<Message>(&self) -> Task<Message>where
Message: Send + 'static,
Returns a task that positions the year picker near the displayed year.
pub fn is_start_input_valid(&self) -> bool
pub fn is_end_input_valid(&self) -> bool
pub fn start_input_error(&self) -> Option<String>
pub fn end_input_error(&self) -> Option<String>
Sourcepub fn update(&mut self, action: DateRangePickerAction)
pub fn update(&mut self, action: DateRangePickerAction)
Applies a date range picker action.
Sourcepub fn update_and_scroll<Message>(
&mut self,
action: DateRangePickerAction,
) -> Task<Message>where
Message: Send + 'static,
pub fn update_and_scroll<Message>(
&mut self,
action: DateRangePickerAction,
) -> Task<Message>where
Message: Send + 'static,
Applies a date range picker action and returns the follow-up scroll task used when the year picker becomes visible.
Examples found in repository?
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 update_and_scroll_at<Message>(
&mut self,
action: DateRangePickerAction,
now: Instant,
) -> Task<Message>where
Message: Send + 'static,
pub fn update_and_scroll_at<Message>(
&mut self,
action: DateRangePickerAction,
now: Instant,
) -> Task<Message>where
Message: Send + 'static,
Applies a date range picker action at now and returns the follow-up
scroll task used when the year picker becomes visible.
Sourcepub fn update_at(&mut self, action: DateRangePickerAction, now: Instant)
pub fn update_at(&mut self, action: DateRangePickerAction, now: Instant)
Applies a date range picker action, using now as the transition start time.
Sourcepub fn advance(&mut self, now: Instant) -> bool
pub fn advance(&mut self, now: Instant) -> bool
Advances any running Material range picker transitions.
Examples found in repository?
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 is_animating(&self) -> bool
pub fn is_animating(&self) -> bool
Returns whether this range picker needs frame ticks for animations.
Examples found in repository?
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 subscription<Message, F>(&self, on_frame: F) -> Subscription<Message>
pub fn subscription<Message, F>(&self, on_frame: F) -> Subscription<Message>
Returns a frame subscription while range picker animations are running.
Trait Implementations§
Source§impl Clone for DateRangePickerState
impl Clone for DateRangePickerState
Source§fn clone(&self) -> DateRangePickerState
fn clone(&self) -> DateRangePickerState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DateRangePickerState
impl Debug for DateRangePickerState
Auto Trait Implementations§
impl !RefUnwindSafe for DateRangePickerState
impl !UnwindSafe for DateRangePickerState
impl Freeze for DateRangePickerState
impl Send for DateRangePickerState
impl Sync for DateRangePickerState
impl Unpin for DateRangePickerState
impl UnsafeUnpin for DateRangePickerState
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
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>
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>
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)
&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)
&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>)
Application.