pub struct State<Id> { /* private fields */ }Expand description
Selection and scroll identity for a log viewer.
Implementations§
Source§impl<Id> State<Id>
impl<Id> State<Id>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty viewer state with an independent scroll identity.
Examples found in repository?
203 fn default() -> Self {
204 Self {
205 navigation: navigation::NavigationState::new(ShowcasePage::Inputs),
206 window_size: Size::new(1080.0, 980.0),
207 count: 0,
208 note: String::new(),
209 editor_content: material::widget::text_editor::Content::with_text(
210 "Material 3 multi-line text editor",
211 ),
212 select_choice: Some("Assist"),
213 combobox_options: material::widget::combobox::State::with_selection(
214 vec!["Assist", "Suggestion", "Filter"],
215 Some(&"Suggestion"),
216 ),
217 combobox_choice: Some("Suggestion"),
218 combobox_input: String::new(),
219 search_query: String::new(),
220 date_picker: material::widget::picker::DatePickerState::new(
221 material::widget::picker::Date::new(2026, 7, 4),
222 ),
223 date_range_picker: material::widget::picker::DateRangePickerState::new(
224 material::widget::picker::Date::new(2026, 7, 4),
225 material::widget::picker::Date::new(2026, 7, 10),
226 ),
227 time_picker: material::widget::picker::TimePickerState::new(14, 30, false),
228 progress: 42.0,
229 enabled: true,
230 radio_choice: Some(RadioChoice::Standard),
231 segment_choice: SegmentChoice::List,
232 segment_state: material::widget::segmented_button::State::new(
233 SegmentChoice::List.index(),
234 ),
235 primary_tab: TabChoice::Inputs,
236 primary_tab_state: material::widget::tabs::State::new(TabChoice::Inputs.index()),
237 secondary_tab: TabChoice::Controls,
238 secondary_tab_state: material::widget::tabs::State::new(TabChoice::Controls.index()),
239 log_viewer: material::widget::log_viewer::State::new(),
240 log_entries: sample_log_entries(),
241 progress_animation: material::widget::progress_bar::IndeterminateState::new(
242 Instant::now(),
243 ),
244 login_dialog: material::widget::dialog::Transition::default(),
245 dialog_account: String::new(),
246 dialog_password: String::new(),
247 dialog_remember_password: false,
248 snackbar: material::widget::snackbar::Transition::default(),
249 theme_controller: theme_picker::ThemeController::default(),
250 }
251 }Sourcepub fn selected_ids(&self) -> &[Id]
pub fn selected_ids(&self) -> &[Id]
Returns the selected identifiers in selection order.
Sourcepub fn clear_selection(&mut self)
pub fn clear_selection(&mut self)
Clears the current selection.
Sourcepub fn advance(&mut self, now: Instant) -> bool
pub fn advance(&mut self, now: Instant) -> bool
Advances the contextual selection bar animation.
Call this from window frame events while Self::is_animating is true.
Examples found in repository?
268fn update(state: &mut Showcase, message: Message) -> Task<Message> {
269 match message {
270 #[cfg(any(target_arch = "wasm32", test))]
271 Message::CjkCoreFontFinished => load_cjk_regional_font(),
272 #[cfg(any(target_arch = "wasm32", test))]
273 Message::CjkRegionalFontFinished => Task::none(),
274 Message::Navigate(page) => {
275 state
276 .navigation
277 .select(page, Instant::now(), state.adaptive_navigation_layout());
278 Task::none()
279 }
280 Message::Increment => {
281 state.count += 1;
282 Task::none()
283 }
284 Message::Decrement => {
285 state.count -= 1;
286 Task::none()
287 }
288 Message::TextChanged(note) => {
289 state.note = note;
290 Task::none()
291 }
292 Message::EditorAction(action) => {
293 state.editor_content.perform(action);
294 Task::none()
295 }
296 Message::SelectChanged(choice) => {
297 state.select_choice = Some(choice);
298 Task::none()
299 }
300 Message::ComboboxSelected(choice) => {
301 state.combobox_choice = Some(choice);
302 state.combobox_input.clear();
303 state.combobox_options.set_selection(Some(&choice));
304 Task::none()
305 }
306 Message::ComboboxInputChanged(input) => {
307 state.combobox_options.set_input(input.clone());
308 state.combobox_input = input;
309 state.combobox_choice = None;
310 Task::none()
311 }
312 Message::SearchChanged(query) => {
313 state.search_query = query;
314 Task::none()
315 }
316 Message::DatePickerChanged(action) => state.date_picker.update_and_scroll(action),
317 Message::DateRangePickerChanged(action) => {
318 state.date_range_picker.update_and_scroll(action)
319 }
320 Message::TimePickerChanged(action) => {
321 state.time_picker.update(action);
322 Task::none()
323 }
324 Message::SliderChanged(progress) => {
325 state.progress = progress;
326 Task::none()
327 }
328 Message::EnabledChanged(enabled) => {
329 state.enabled = enabled;
330 Task::none()
331 }
332 Message::ChoiceSelected(choice) => {
333 state.radio_choice = Some(choice);
334 Task::none()
335 }
336 Message::SegmentSelected(choice) => {
337 state.segment_choice = choice;
338 state.segment_state.select(choice.index(), Instant::now());
339 Task::none()
340 }
341 Message::PrimaryTabSelected(choice) => {
342 state.primary_tab = choice;
343 state.primary_tab_state.select(
344 choice.index(),
345 Instant::now(),
346 material::widget::tabs::Variant::Primary,
347 );
348 Task::none()
349 }
350 Message::SecondaryTabSelected(choice) => {
351 state.secondary_tab = choice;
352 state.secondary_tab_state.select(
353 choice.index(),
354 Instant::now(),
355 material::widget::tabs::Variant::Secondary,
356 );
357 Task::none()
358 }
359 Message::LogViewer(action) => state.log_viewer.update(action, &state.log_entries),
360 Message::MenuPressed => {
361 state.navigation.toggle_menu_now_for_size(state.window_size);
362 Task::none()
363 }
364 Message::DialogOpened => {
365 state.login_dialog.show(Instant::now());
366 iced::widget::operation::focus(dialog_account_input_id())
367 }
368 Message::DialogDismissed => {
369 state.login_dialog.dismiss(Instant::now());
370 Task::none()
371 }
372 Message::DialogConfirmed => {
373 state.login_dialog.dismiss(Instant::now());
374 state.count += 1;
375 Task::none()
376 }
377 Message::DialogAccountChanged(account) => {
378 state.dialog_account = account;
379 Task::none()
380 }
381 Message::DialogPasswordChanged(password) => {
382 state.dialog_password = password;
383 Task::none()
384 }
385 Message::DialogRememberPasswordChanged(remember_password) => {
386 state.dialog_remember_password = remember_password;
387 Task::none()
388 }
389 Message::ShowSnackbar => {
390 state.snackbar.show(Instant::now());
391 Task::none()
392 }
393 Message::SnackbarUndo => {
394 state.count -= 1;
395 state.snackbar.dismiss(Instant::now());
396 Task::none()
397 }
398 Message::WindowResized(size) => {
399 state.window_size = size;
400 Task::none()
401 }
402 Message::ThemeChanged(action) => {
403 state.theme_controller.update(
404 action,
405 state.window_size,
406 showcase_floating_bottom_margin(state.adaptive_navigation_layout()),
407 Instant::now(),
408 );
409 Task::none()
410 }
411 Message::Frame(now) => {
412 let _ = state.theme_controller.advance(now);
413 let _ = state.navigation.advance(now);
414 let _ = state.segment_state.advance(now);
415 let _ = state.primary_tab_state.advance(now);
416 let _ = state.secondary_tab_state.advance(now);
417 let _ = state.log_viewer.advance(now);
418 state.progress_animation.advance(now);
419 let _ = state.login_dialog.advance(now);
420 let _ = state.snackbar.advance(now);
421 let _ = state.date_picker.advance(now);
422 let _ = state.date_range_picker.advance(now);
423 let _ = state.time_picker.advance(now);
424 Task::none()
425 }
426 }
427}Sourcepub fn is_animating(&self) -> bool
pub fn is_animating(&self) -> bool
Returns whether the contextual selection bar is animating.
Examples found in repository?
595fn subscription(state: &Showcase) -> Subscription<Message> {
596 let mut subscriptions =
597 vec![iced::window::resize_events().map(|(_id, size)| Message::WindowResized(size))];
598
599 if state.theme_controller.is_animating()
600 || state.navigation.is_animating()
601 || state.segment_state.is_animating()
602 || state.primary_tab_state.is_animating()
603 || state.secondary_tab_state.is_animating()
604 || state.log_viewer.is_animating()
605 || state.login_dialog.is_animating()
606 || state.snackbar.is_active()
607 || state.date_picker.is_animating()
608 || state.date_range_picker.is_animating()
609 || state.time_picker.is_animating()
610 || (state.navigation.selected() == ShowcasePage::Feedback
611 && state.progress_animation.is_animating())
612 {
613 subscriptions.push(iced::window::frames().map(Message::Frame));
614 }
615
616 Subscription::batch(subscriptions)
617}Sourcepub fn selection_bar_progress(&self) -> f32
pub fn selection_bar_progress(&self) -> f32
Returns the contextual selection bar visibility progress.
Source§impl<Id: Eq> State<Id>
impl<Id: Eq> State<Id>
Sourcepub fn is_selected(&self, id: &Id) -> bool
pub fn is_selected(&self, id: &Id) -> bool
Returns whether an identifier is currently selected.
Sourcepub fn toggle(&mut self, id: Id) -> bool
pub fn toggle(&mut self, id: Id) -> bool
Toggles an identifier and returns its new selected state.
Sourcepub fn retain_entries(&mut self, entries: &[LogEntry<Id>])
pub fn retain_entries(&mut self, entries: &[LogEntry<Id>])
Drops selections whose entries are no longer present.
Sourcepub fn selected_count(&self, entries: &[LogEntry<Id>]) -> usize
pub fn selected_count(&self, entries: &[LogEntry<Id>]) -> usize
Counts selected entries that are still present in the supplied list.
Sourcepub fn selected_text(&self, entries: &[LogEntry<Id>]) -> String
pub fn selected_text(&self, entries: &[LogEntry<Id>]) -> String
Builds clipboard text in the current visible entry order.
Sourcepub fn update<Message>(
&mut self,
action: Action<Id>,
entries: &[LogEntry<Id>],
) -> Task<Message>
pub fn update<Message>( &mut self, action: Action<Id>, entries: &[LogEntry<Id>], ) -> Task<Message>
Applies a viewer action, including clipboard writes for copy actions.
Examples found in repository?
268fn update(state: &mut Showcase, message: Message) -> Task<Message> {
269 match message {
270 #[cfg(any(target_arch = "wasm32", test))]
271 Message::CjkCoreFontFinished => load_cjk_regional_font(),
272 #[cfg(any(target_arch = "wasm32", test))]
273 Message::CjkRegionalFontFinished => Task::none(),
274 Message::Navigate(page) => {
275 state
276 .navigation
277 .select(page, Instant::now(), state.adaptive_navigation_layout());
278 Task::none()
279 }
280 Message::Increment => {
281 state.count += 1;
282 Task::none()
283 }
284 Message::Decrement => {
285 state.count -= 1;
286 Task::none()
287 }
288 Message::TextChanged(note) => {
289 state.note = note;
290 Task::none()
291 }
292 Message::EditorAction(action) => {
293 state.editor_content.perform(action);
294 Task::none()
295 }
296 Message::SelectChanged(choice) => {
297 state.select_choice = Some(choice);
298 Task::none()
299 }
300 Message::ComboboxSelected(choice) => {
301 state.combobox_choice = Some(choice);
302 state.combobox_input.clear();
303 state.combobox_options.set_selection(Some(&choice));
304 Task::none()
305 }
306 Message::ComboboxInputChanged(input) => {
307 state.combobox_options.set_input(input.clone());
308 state.combobox_input = input;
309 state.combobox_choice = None;
310 Task::none()
311 }
312 Message::SearchChanged(query) => {
313 state.search_query = query;
314 Task::none()
315 }
316 Message::DatePickerChanged(action) => state.date_picker.update_and_scroll(action),
317 Message::DateRangePickerChanged(action) => {
318 state.date_range_picker.update_and_scroll(action)
319 }
320 Message::TimePickerChanged(action) => {
321 state.time_picker.update(action);
322 Task::none()
323 }
324 Message::SliderChanged(progress) => {
325 state.progress = progress;
326 Task::none()
327 }
328 Message::EnabledChanged(enabled) => {
329 state.enabled = enabled;
330 Task::none()
331 }
332 Message::ChoiceSelected(choice) => {
333 state.radio_choice = Some(choice);
334 Task::none()
335 }
336 Message::SegmentSelected(choice) => {
337 state.segment_choice = choice;
338 state.segment_state.select(choice.index(), Instant::now());
339 Task::none()
340 }
341 Message::PrimaryTabSelected(choice) => {
342 state.primary_tab = choice;
343 state.primary_tab_state.select(
344 choice.index(),
345 Instant::now(),
346 material::widget::tabs::Variant::Primary,
347 );
348 Task::none()
349 }
350 Message::SecondaryTabSelected(choice) => {
351 state.secondary_tab = choice;
352 state.secondary_tab_state.select(
353 choice.index(),
354 Instant::now(),
355 material::widget::tabs::Variant::Secondary,
356 );
357 Task::none()
358 }
359 Message::LogViewer(action) => state.log_viewer.update(action, &state.log_entries),
360 Message::MenuPressed => {
361 state.navigation.toggle_menu_now_for_size(state.window_size);
362 Task::none()
363 }
364 Message::DialogOpened => {
365 state.login_dialog.show(Instant::now());
366 iced::widget::operation::focus(dialog_account_input_id())
367 }
368 Message::DialogDismissed => {
369 state.login_dialog.dismiss(Instant::now());
370 Task::none()
371 }
372 Message::DialogConfirmed => {
373 state.login_dialog.dismiss(Instant::now());
374 state.count += 1;
375 Task::none()
376 }
377 Message::DialogAccountChanged(account) => {
378 state.dialog_account = account;
379 Task::none()
380 }
381 Message::DialogPasswordChanged(password) => {
382 state.dialog_password = password;
383 Task::none()
384 }
385 Message::DialogRememberPasswordChanged(remember_password) => {
386 state.dialog_remember_password = remember_password;
387 Task::none()
388 }
389 Message::ShowSnackbar => {
390 state.snackbar.show(Instant::now());
391 Task::none()
392 }
393 Message::SnackbarUndo => {
394 state.count -= 1;
395 state.snackbar.dismiss(Instant::now());
396 Task::none()
397 }
398 Message::WindowResized(size) => {
399 state.window_size = size;
400 Task::none()
401 }
402 Message::ThemeChanged(action) => {
403 state.theme_controller.update(
404 action,
405 state.window_size,
406 showcase_floating_bottom_margin(state.adaptive_navigation_layout()),
407 Instant::now(),
408 );
409 Task::none()
410 }
411 Message::Frame(now) => {
412 let _ = state.theme_controller.advance(now);
413 let _ = state.navigation.advance(now);
414 let _ = state.segment_state.advance(now);
415 let _ = state.primary_tab_state.advance(now);
416 let _ = state.secondary_tab_state.advance(now);
417 let _ = state.log_viewer.advance(now);
418 state.progress_animation.advance(now);
419 let _ = state.login_dialog.advance(now);
420 let _ = state.snackbar.advance(now);
421 let _ = state.date_picker.advance(now);
422 let _ = state.date_range_picker.advance(now);
423 let _ = state.time_picker.advance(now);
424 Task::none()
425 }
426 }
427}Trait Implementations§
Auto Trait Implementations§
impl<Id> Freeze for State<Id>
impl<Id> RefUnwindSafe for State<Id>where
Vec<Id>: RefUnwindSafe,
impl<Id> Send for State<Id>
impl<Id> Sync for State<Id>
impl<Id> Unpin for State<Id>
impl<Id> UnsafeUnpin for State<Id>where
Vec<Id>: UnsafeUnpin,
impl<Id> UnwindSafe for State<Id>where
Vec<Id>: UnwindSafe,
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> 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.