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?
173 fn default() -> Self {
174 Self {
175 navigation: navigation::NavigationState::new(ShowcasePage::Inputs),
176 window_size: Size::new(1080.0, 980.0),
177 count: 0,
178 note: String::new(),
179 editor_content: material::widget::text_editor::Content::with_text(
180 "Material 3 multi-line text editor",
181 ),
182 select_choice: Some("Assist"),
183 combobox_options: material::widget::combobox::State::with_selection(
184 vec!["Assist", "Suggestion", "Filter"],
185 Some(&"Suggestion"),
186 ),
187 combobox_choice: Some("Suggestion"),
188 combobox_input: String::new(),
189 search_query: String::new(),
190 date_picker: material::widget::picker::DatePickerState::new(
191 material::widget::picker::Date::new(2026, 7, 4),
192 ),
193 date_range_picker: material::widget::picker::DateRangePickerState::new(
194 material::widget::picker::Date::new(2026, 7, 4),
195 material::widget::picker::Date::new(2026, 7, 10),
196 ),
197 time_picker: material::widget::picker::TimePickerState::new(14, 30, false),
198 progress: 42.0,
199 enabled: true,
200 radio_choice: Some(RadioChoice::Standard),
201 segment_choice: SegmentChoice::List,
202 segment_state: material::widget::segmented_button::State::new(
203 SegmentChoice::List.index(),
204 ),
205 primary_tab: TabChoice::Inputs,
206 primary_tab_state: material::widget::tabs::State::new(TabChoice::Inputs.index()),
207 secondary_tab: TabChoice::Controls,
208 secondary_tab_state: material::widget::tabs::State::new(TabChoice::Controls.index()),
209 progress_animation: material::widget::progress_bar::IndeterminateState::new(
210 Instant::now(),
211 ),
212 alert_dialog: material::widget::dialog::Transition::default(),
213 snackbar: material::widget::snackbar::Transition::default(),
214 theme_controller: theme_picker::ThemeController::default(),
215 }
216 }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_year_picker_to_displayed_year<Message>(&self) -> Task<Message>where
Message: Send + 'static,
pub fn scroll_year_picker_to_displayed_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_to_displayed_year<Message>(
&mut self,
action: DateRangePickerAction,
) -> Task<Message>where
Message: Send + 'static,
pub fn update_and_scroll_to_displayed_year<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?
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}Sourcepub fn update_and_scroll_to_displayed_year_at<Message>(
&mut self,
action: DateRangePickerAction,
now: Instant,
) -> Task<Message>where
Message: Send + 'static,
pub fn update_and_scroll_to_displayed_year_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?
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}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?
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}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.