pub struct TimePickerState { /* private fields */ }Expand description
State held by a Material time picker.
Implementations§
Source§impl TimePickerState
impl TimePickerState
Sourcepub fn new(hour: u8, minute: u8, is_24_hour: bool) -> Self
pub fn new(hour: u8, minute: u8, is_24_hour: bool) -> Self
Creates time picker state. Invalid initial values are clamped to official ranges.
Examples found in repository?
examples/showcase/app.rs (line 218)
194 fn default() -> Self {
195 Self {
196 navigation: navigation::NavigationState::new(ShowcasePage::Inputs),
197 window_size: Size::new(1080.0, 980.0),
198 count: 0,
199 note: String::new(),
200 editor_content: material::widget::text_editor::Content::with_text(
201 "Material 3 multi-line text editor",
202 ),
203 select_choice: Some("Assist"),
204 combobox_options: material::widget::combobox::State::with_selection(
205 vec!["Assist", "Suggestion", "Filter"],
206 Some(&"Suggestion"),
207 ),
208 combobox_choice: Some("Suggestion"),
209 combobox_input: String::new(),
210 search_query: String::new(),
211 date_picker: material::widget::picker::DatePickerState::new(
212 material::widget::picker::Date::new(2026, 7, 4),
213 ),
214 date_range_picker: material::widget::picker::DateRangePickerState::new(
215 material::widget::picker::Date::new(2026, 7, 4),
216 material::widget::picker::Date::new(2026, 7, 10),
217 ),
218 time_picker: material::widget::picker::TimePickerState::new(14, 30, false),
219 progress: 42.0,
220 enabled: true,
221 radio_choice: Some(RadioChoice::Standard),
222 segment_choice: SegmentChoice::List,
223 segment_state: material::widget::segmented_button::State::new(
224 SegmentChoice::List.index(),
225 ),
226 primary_tab: TabChoice::Inputs,
227 primary_tab_state: material::widget::tabs::State::new(TabChoice::Inputs.index()),
228 secondary_tab: TabChoice::Controls,
229 secondary_tab_state: material::widget::tabs::State::new(TabChoice::Controls.index()),
230 progress_animation: material::widget::progress_bar::IndeterminateState::new(
231 Instant::now(),
232 ),
233 alert_dialog: material::widget::dialog::Transition::default(),
234 snackbar: material::widget::snackbar::Transition::default(),
235 theme_controller: theme_picker::ThemeController::default(),
236 }
237 }Sourcepub fn auto_switch_to_minute(self, auto_switch_to_minute: bool) -> Self
pub fn auto_switch_to_minute(self, auto_switch_to_minute: bool) -> Self
Sets whether analog hour taps automatically move focus to minute selection.
pub fn hour(&self) -> u8
pub fn minute(&self) -> u8
pub fn is_24_hour(&self) -> bool
pub fn selection(&self) -> TimePickerSelectionMode
pub fn auto_switches_to_minute(&self) -> bool
pub fn hour_input(&self) -> &str
pub fn minute_input(&self) -> &str
pub fn period(&self) -> Period
pub fn hour_for_display(&self) -> u8
pub fn formatted_time(&self) -> String
pub fn is_hour_input_valid(&self) -> bool
pub fn is_minute_input_valid(&self) -> bool
pub fn is_input_valid(&self) -> bool
Sourcepub fn update(&mut self, action: TimePickerAction)
pub fn update(&mut self, action: TimePickerAction)
Applies a time picker action.
Examples found in repository?
examples/showcase/app.rs (line 307)
254fn update(state: &mut Showcase, message: Message) -> Task<Message> {
255 match message {
256 #[cfg(any(target_arch = "wasm32", test))]
257 Message::CjkCoreFontFinished => load_cjk_regional_font(),
258 #[cfg(any(target_arch = "wasm32", test))]
259 Message::CjkRegionalFontFinished => Task::none(),
260 Message::Navigate(page) => {
261 state
262 .navigation
263 .select(page, Instant::now(), state.adaptive_navigation_layout());
264 Task::none()
265 }
266 Message::Increment => {
267 state.count += 1;
268 Task::none()
269 }
270 Message::Decrement => {
271 state.count -= 1;
272 Task::none()
273 }
274 Message::TextChanged(note) => {
275 state.note = note;
276 Task::none()
277 }
278 Message::EditorAction(action) => {
279 state.editor_content.perform(action);
280 Task::none()
281 }
282 Message::SelectChanged(choice) => {
283 state.select_choice = Some(choice);
284 Task::none()
285 }
286 Message::ComboboxSelected(choice) => {
287 state.combobox_choice = Some(choice);
288 state.combobox_input.clear();
289 state.combobox_options.set_selection(Some(&choice));
290 Task::none()
291 }
292 Message::ComboboxInputChanged(input) => {
293 state.combobox_options.set_input(input.clone());
294 state.combobox_input = input;
295 state.combobox_choice = None;
296 Task::none()
297 }
298 Message::SearchChanged(query) => {
299 state.search_query = query;
300 Task::none()
301 }
302 Message::DatePickerChanged(action) => state.date_picker.update_and_scroll(action),
303 Message::DateRangePickerChanged(action) => {
304 state.date_range_picker.update_and_scroll(action)
305 }
306 Message::TimePickerChanged(action) => {
307 state.time_picker.update(action);
308 Task::none()
309 }
310 Message::SliderChanged(progress) => {
311 state.progress = progress;
312 Task::none()
313 }
314 Message::EnabledChanged(enabled) => {
315 state.enabled = enabled;
316 Task::none()
317 }
318 Message::ChoiceSelected(choice) => {
319 state.radio_choice = Some(choice);
320 Task::none()
321 }
322 Message::SegmentSelected(choice) => {
323 state.segment_choice = choice;
324 state.segment_state.select(choice.index(), Instant::now());
325 Task::none()
326 }
327 Message::PrimaryTabSelected(choice) => {
328 state.primary_tab = choice;
329 state.primary_tab_state.select(
330 choice.index(),
331 Instant::now(),
332 material::widget::tabs::Variant::Primary,
333 );
334 Task::none()
335 }
336 Message::SecondaryTabSelected(choice) => {
337 state.secondary_tab = choice;
338 state.secondary_tab_state.select(
339 choice.index(),
340 Instant::now(),
341 material::widget::tabs::Variant::Secondary,
342 );
343 Task::none()
344 }
345 Message::MenuPressed => {
346 state.navigation.toggle_menu_now();
347 Task::none()
348 }
349 Message::DialogOpened => {
350 state.alert_dialog.show(Instant::now());
351 Task::none()
352 }
353 Message::DialogDismissed => {
354 state.alert_dialog.dismiss(Instant::now());
355 Task::none()
356 }
357 Message::DialogConfirmed => {
358 state.alert_dialog.dismiss(Instant::now());
359 state.count += 1;
360 Task::none()
361 }
362 Message::ShowSnackbar => {
363 state.snackbar.show(Instant::now());
364 Task::none()
365 }
366 Message::SnackbarUndo => {
367 state.count -= 1;
368 state.snackbar.dismiss(Instant::now());
369 Task::none()
370 }
371 Message::WindowResized(size) => {
372 state.window_size = size;
373 Task::none()
374 }
375 Message::ThemeChanged(action) => {
376 state.theme_controller.update(
377 action,
378 state.window_size,
379 theme_picker::bottom_margin(state.adaptive_navigation_layout()),
380 Instant::now(),
381 );
382 Task::none()
383 }
384 Message::Frame(now) => {
385 let _ = state.theme_controller.advance(now);
386 let _ = state.navigation.advance(now);
387 let _ = state.segment_state.advance(now);
388 let _ = state.primary_tab_state.advance(now);
389 let _ = state.secondary_tab_state.advance(now);
390 state.progress_animation.advance(now);
391 let _ = state.alert_dialog.advance(now);
392 let _ = state.snackbar.advance(now);
393 let _ = state.date_picker.advance(now);
394 let _ = state.date_range_picker.advance(now);
395 let _ = state.time_picker.advance(now);
396 Task::none()
397 }
398 }
399}Sourcepub fn update_at(&mut self, action: TimePickerAction, now: Instant)
pub fn update_at(&mut self, action: TimePickerAction, now: Instant)
Applies a time 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 time picker transitions.
Examples found in repository?
examples/showcase/app.rs (line 395)
254fn update(state: &mut Showcase, message: Message) -> Task<Message> {
255 match message {
256 #[cfg(any(target_arch = "wasm32", test))]
257 Message::CjkCoreFontFinished => load_cjk_regional_font(),
258 #[cfg(any(target_arch = "wasm32", test))]
259 Message::CjkRegionalFontFinished => Task::none(),
260 Message::Navigate(page) => {
261 state
262 .navigation
263 .select(page, Instant::now(), state.adaptive_navigation_layout());
264 Task::none()
265 }
266 Message::Increment => {
267 state.count += 1;
268 Task::none()
269 }
270 Message::Decrement => {
271 state.count -= 1;
272 Task::none()
273 }
274 Message::TextChanged(note) => {
275 state.note = note;
276 Task::none()
277 }
278 Message::EditorAction(action) => {
279 state.editor_content.perform(action);
280 Task::none()
281 }
282 Message::SelectChanged(choice) => {
283 state.select_choice = Some(choice);
284 Task::none()
285 }
286 Message::ComboboxSelected(choice) => {
287 state.combobox_choice = Some(choice);
288 state.combobox_input.clear();
289 state.combobox_options.set_selection(Some(&choice));
290 Task::none()
291 }
292 Message::ComboboxInputChanged(input) => {
293 state.combobox_options.set_input(input.clone());
294 state.combobox_input = input;
295 state.combobox_choice = None;
296 Task::none()
297 }
298 Message::SearchChanged(query) => {
299 state.search_query = query;
300 Task::none()
301 }
302 Message::DatePickerChanged(action) => state.date_picker.update_and_scroll(action),
303 Message::DateRangePickerChanged(action) => {
304 state.date_range_picker.update_and_scroll(action)
305 }
306 Message::TimePickerChanged(action) => {
307 state.time_picker.update(action);
308 Task::none()
309 }
310 Message::SliderChanged(progress) => {
311 state.progress = progress;
312 Task::none()
313 }
314 Message::EnabledChanged(enabled) => {
315 state.enabled = enabled;
316 Task::none()
317 }
318 Message::ChoiceSelected(choice) => {
319 state.radio_choice = Some(choice);
320 Task::none()
321 }
322 Message::SegmentSelected(choice) => {
323 state.segment_choice = choice;
324 state.segment_state.select(choice.index(), Instant::now());
325 Task::none()
326 }
327 Message::PrimaryTabSelected(choice) => {
328 state.primary_tab = choice;
329 state.primary_tab_state.select(
330 choice.index(),
331 Instant::now(),
332 material::widget::tabs::Variant::Primary,
333 );
334 Task::none()
335 }
336 Message::SecondaryTabSelected(choice) => {
337 state.secondary_tab = choice;
338 state.secondary_tab_state.select(
339 choice.index(),
340 Instant::now(),
341 material::widget::tabs::Variant::Secondary,
342 );
343 Task::none()
344 }
345 Message::MenuPressed => {
346 state.navigation.toggle_menu_now();
347 Task::none()
348 }
349 Message::DialogOpened => {
350 state.alert_dialog.show(Instant::now());
351 Task::none()
352 }
353 Message::DialogDismissed => {
354 state.alert_dialog.dismiss(Instant::now());
355 Task::none()
356 }
357 Message::DialogConfirmed => {
358 state.alert_dialog.dismiss(Instant::now());
359 state.count += 1;
360 Task::none()
361 }
362 Message::ShowSnackbar => {
363 state.snackbar.show(Instant::now());
364 Task::none()
365 }
366 Message::SnackbarUndo => {
367 state.count -= 1;
368 state.snackbar.dismiss(Instant::now());
369 Task::none()
370 }
371 Message::WindowResized(size) => {
372 state.window_size = size;
373 Task::none()
374 }
375 Message::ThemeChanged(action) => {
376 state.theme_controller.update(
377 action,
378 state.window_size,
379 theme_picker::bottom_margin(state.adaptive_navigation_layout()),
380 Instant::now(),
381 );
382 Task::none()
383 }
384 Message::Frame(now) => {
385 let _ = state.theme_controller.advance(now);
386 let _ = state.navigation.advance(now);
387 let _ = state.segment_state.advance(now);
388 let _ = state.primary_tab_state.advance(now);
389 let _ = state.secondary_tab_state.advance(now);
390 state.progress_animation.advance(now);
391 let _ = state.alert_dialog.advance(now);
392 let _ = state.snackbar.advance(now);
393 let _ = state.date_picker.advance(now);
394 let _ = state.date_range_picker.advance(now);
395 let _ = state.time_picker.advance(now);
396 Task::none()
397 }
398 }
399}Sourcepub fn is_animating(&self) -> bool
pub fn is_animating(&self) -> bool
Returns whether this picker needs frame ticks for animations.
Examples found in repository?
examples/showcase/app.rs (line 423)
410fn subscription(state: &Showcase) -> Subscription<Message> {
411 let mut subscriptions =
412 vec![iced::window::resize_events().map(|(_id, size)| Message::WindowResized(size))];
413
414 if state.theme_controller.is_animating()
415 || state.navigation.is_animating()
416 || state.segment_state.is_animating()
417 || state.primary_tab_state.is_animating()
418 || state.secondary_tab_state.is_animating()
419 || state.alert_dialog.is_animating()
420 || state.snackbar.is_active()
421 || state.date_picker.is_animating()
422 || state.date_range_picker.is_animating()
423 || state.time_picker.is_animating()
424 || (state.navigation.selected() == ShowcasePage::Feedback
425 && state.progress_animation.is_animating())
426 {
427 subscriptions.push(iced::window::frames().map(Message::Frame));
428 }
429
430 Subscription::batch(subscriptions)
431}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 picker animations are running.
Trait Implementations§
Source§impl Clone for TimePickerState
impl Clone for TimePickerState
Source§fn clone(&self) -> TimePickerState
fn clone(&self) -> TimePickerState
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 TimePickerState
impl Debug for TimePickerState
Auto Trait Implementations§
impl Freeze for TimePickerState
impl RefUnwindSafe for TimePickerState
impl Send for TimePickerState
impl Sync for TimePickerState
impl Unpin for TimePickerState
impl UnsafeUnpin for TimePickerState
impl UnwindSafe for TimePickerState
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.