pub struct MultiProgressState { /* private fields */ }Expand description
State for the MultiProgress component.
Implementations§
Source§impl MultiProgressState
impl MultiProgressState
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new empty MultiProgress state.
§Example
use envision::component::MultiProgressState;
let state = MultiProgressState::new();
assert!(state.is_empty());Sourcepub fn with_max_visible(self, max: usize) -> Self
pub fn with_max_visible(self, max: usize) -> Self
Sets the maximum number of visible items.
§Example
use envision::component::MultiProgressState;
let state = MultiProgressState::new().with_max_visible(5);
assert_eq!(state.max_visible(), 5);Sourcepub fn with_auto_remove_completed(self, auto_remove: bool) -> Self
pub fn with_auto_remove_completed(self, auto_remove: bool) -> Self
Sets whether to auto-remove completed items.
§Example
use envision::component::MultiProgressState;
let state = MultiProgressState::new().with_auto_remove_completed(true);
assert!(state.auto_remove_completed());Sourcepub fn with_title(self, title: impl Into<String>) -> Self
pub fn with_title(self, title: impl Into<String>) -> Self
Sets the title.
§Example
use envision::component::MultiProgressState;
let state = MultiProgressState::new().with_title("Downloads");
assert_eq!(state.title(), Some("Downloads"));Sourcepub fn with_show_percentages(self, show: bool) -> Self
pub fn with_show_percentages(self, show: bool) -> Self
Sets whether to show percentages.
§Example
use envision::component::MultiProgressState;
let state = MultiProgressState::new().with_show_percentages(false);
assert!(!state.show_percentages());Sourcepub fn add(&mut self, id: impl Into<String>, label: impl Into<String>) -> bool
pub fn add(&mut self, id: impl Into<String>, label: impl Into<String>) -> bool
Adds a new progress item.
Returns true if the item was added (id was unique).
§Example
use envision::component::MultiProgressState;
let mut state = MultiProgressState::new();
assert!(state.add("task1", "Download file"));
assert!(!state.add("task1", "Duplicate")); // duplicate ID rejected
assert_eq!(state.len(), 1);Sourcepub fn items(&self) -> &[ProgressItem]
pub fn items(&self) -> &[ProgressItem]
Returns all items.
§Example
use envision::component::MultiProgressState;
let mut state = MultiProgressState::new();
state.add("t1", "Task 1");
assert_eq!(state.items().len(), 1);
assert_eq!(state.items()[0].label(), "Task 1");Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of items.
§Example
use envision::component::MultiProgressState;
let mut state = MultiProgressState::new();
assert_eq!(state.len(), 0);
state.add("t1", "Task");
assert_eq!(state.len(), 1);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if there are no items.
§Example
use envision::component::MultiProgressState;
let state = MultiProgressState::new();
assert!(state.is_empty());Sourcepub fn completed_count(&self) -> usize
pub fn completed_count(&self) -> usize
Returns the number of completed items.
§Example
use envision::component::{MultiProgress, MultiProgressState, MultiProgressMessage, Component};
let mut state = MultiProgressState::new();
state.add("t1", "Task 1");
state.add("t2", "Task 2");
MultiProgress::update(&mut state, MultiProgressMessage::Complete("t1".to_string()));
assert_eq!(state.completed_count(), 1);Sourcepub fn failed_count(&self) -> usize
pub fn failed_count(&self) -> usize
Returns the number of failed items.
§Example
use envision::component::{MultiProgress, MultiProgressState, MultiProgressMessage, Component};
let mut state = MultiProgressState::new();
state.add("t1", "Task 1");
MultiProgress::update(&mut state, MultiProgressMessage::Fail {
id: "t1".to_string(),
message: Some("timeout".to_string()),
});
assert_eq!(state.failed_count(), 1);Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Returns the number of active items.
§Example
use envision::component::{MultiProgress, MultiProgressState, MultiProgressMessage, Component};
let mut state = MultiProgressState::new();
state.add("t1", "Task 1");
MultiProgress::update(&mut state, MultiProgressMessage::SetProgress {
id: "t1".to_string(),
progress: 0.5,
});
assert_eq!(state.active_count(), 1);Sourcepub fn overall_progress(&self) -> f32
pub fn overall_progress(&self) -> f32
Returns the overall progress (average of all items).
§Example
use envision::component::{MultiProgress, MultiProgressState, MultiProgressMessage, Component};
let mut state = MultiProgressState::new();
state.add("a", "Task A");
state.add("b", "Task B");
MultiProgress::update(&mut state, MultiProgressMessage::SetProgress {
id: "a".to_string(),
progress: 1.0,
});
assert!((state.overall_progress() - 0.5).abs() < f32::EPSILON);Sourcepub fn find(&self, id: &str) -> Option<&ProgressItem>
pub fn find(&self, id: &str) -> Option<&ProgressItem>
Finds an item by ID.
§Example
use envision::component::MultiProgressState;
let mut state = MultiProgressState::new();
state.add("dl", "Download");
assert_eq!(state.find("dl").unwrap().label(), "Download");
assert!(state.find("missing").is_none());Sourcepub fn find_mut(&mut self, id: &str) -> Option<&mut ProgressItem>
pub fn find_mut(&mut self, id: &str) -> Option<&mut ProgressItem>
Finds a mutable item by ID.
§Example
use envision::component::MultiProgressState;
let mut state = MultiProgressState::new();
state.add("dl", "Download");
assert!(state.find_mut("dl").is_some());
assert!(state.find_mut("missing").is_none());Sourcepub fn remove(&mut self, id: &str) -> bool
pub fn remove(&mut self, id: &str) -> bool
Removes an item by ID.
§Example
use envision::component::MultiProgressState;
let mut state = MultiProgressState::new();
state.add("task1", "Task");
assert!(state.remove("task1"));
assert!(state.is_empty());Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears all items.
§Example
use envision::component::MultiProgressState;
let mut state = MultiProgressState::new();
state.add("t1", "Task");
state.clear();
assert!(state.is_empty());Sourcepub fn max_visible(&self) -> usize
pub fn max_visible(&self) -> usize
Returns the maximum visible items.
§Example
use envision::component::MultiProgressState;
let state = MultiProgressState::new();
assert_eq!(state.max_visible(), 8); // defaultSourcepub fn set_max_visible(&mut self, max: usize)
pub fn set_max_visible(&mut self, max: usize)
Sets the maximum visible items.
§Example
use envision::component::MultiProgressState;
let mut state = MultiProgressState::new();
state.set_max_visible(5);
assert_eq!(state.max_visible(), 5);Sourcepub fn scroll_offset(&self) -> usize
pub fn scroll_offset(&self) -> usize
Returns the scroll offset.
§Example
use envision::component::MultiProgressState;
let state = MultiProgressState::new();
assert_eq!(state.scroll_offset(), 0);Sourcepub fn selected(&self) -> Option<usize>
pub fn selected(&self) -> Option<usize>
Returns the currently selected item index.
§Example
use envision::component::MultiProgressState;
let mut state = MultiProgressState::new();
state.add("t1", "Task 1");
assert_eq!(state.selected(), Some(0));Sourcepub fn selected_item(&self) -> Option<&ProgressItem>
pub fn selected_item(&self) -> Option<&ProgressItem>
Returns a reference to the currently selected item.
§Example
use envision::component::MultiProgressState;
let mut state = MultiProgressState::new();
state.add("t1", "Task 1");
assert_eq!(state.selected_item().unwrap().label(), "Task 1");Sourcepub fn set_selected(&mut self, index: Option<usize>)
pub fn set_selected(&mut self, index: Option<usize>)
Sets the selected item index. Clamped to valid range.
§Example
use envision::component::MultiProgressState;
let mut state = MultiProgressState::new();
state.add("t1", "Task 1");
state.add("t2", "Task 2");
state.set_selected(Some(1));
assert_eq!(state.selected(), Some(1));Sourcepub fn set_scroll_offset(&mut self, offset: usize)
pub fn set_scroll_offset(&mut self, offset: usize)
Sets the viewport scroll offset.
This controls which items are visible in the viewport, independent
of which item is selected. Use set_selected
to change the highlighted item. Keyboard navigation (Up/Down)
adjusts both selection and scroll together.
§Example
use envision::component::MultiProgressState;
let mut state = MultiProgressState::new();
state.add("t1", "Task 1");
state.add("t2", "Task 2");
state.set_scroll_offset(1);
assert_eq!(state.scroll_offset(), 1);Sourcepub fn title(&self) -> Option<&str>
pub fn title(&self) -> Option<&str>
Returns the title.
§Example
use envision::component::MultiProgressState;
let state = MultiProgressState::new().with_title("Downloads");
assert_eq!(state.title(), Some("Downloads"));Sourcepub fn set_title(&mut self, title: Option<String>)
pub fn set_title(&mut self, title: Option<String>)
Sets the title.
§Example
use envision::component::MultiProgressState;
let mut state = MultiProgressState::new();
state.set_title(Some("Tasks".to_string()));
assert_eq!(state.title(), Some("Tasks"));Sourcepub fn show_percentages(&self) -> bool
pub fn show_percentages(&self) -> bool
Returns whether percentages are shown.
§Example
use envision::component::MultiProgressState;
let state = MultiProgressState::new();
assert!(state.show_percentages()); // enabled by defaultSourcepub fn set_show_percentages(&mut self, show: bool)
pub fn set_show_percentages(&mut self, show: bool)
Sets whether to show percentages.
§Example
use envision::component::MultiProgressState;
let mut state = MultiProgressState::new();
state.set_show_percentages(false);
assert!(!state.show_percentages());Sourcepub fn auto_remove_completed(&self) -> bool
pub fn auto_remove_completed(&self) -> bool
Returns whether auto-remove is enabled.
§Example
use envision::component::MultiProgressState;
let state = MultiProgressState::new();
assert!(!state.auto_remove_completed()); // disabled by defaultSourcepub fn set_auto_remove_completed(&mut self, auto_remove: bool)
pub fn set_auto_remove_completed(&mut self, auto_remove: bool)
Sets whether to auto-remove completed items.
§Example
use envision::component::MultiProgressState;
let mut state = MultiProgressState::new();
state.set_auto_remove_completed(true);
assert!(state.auto_remove_completed());Sourcepub fn update(
&mut self,
msg: MultiProgressMessage,
) -> Option<MultiProgressOutput>
pub fn update( &mut self, msg: MultiProgressMessage, ) -> Option<MultiProgressOutput>
Updates the multi-progress state with a message, returning any output.
§Example
use envision::component::{MultiProgressMessage, MultiProgressOutput, MultiProgressState};
let mut state = MultiProgressState::default();
let output = state.update(MultiProgressMessage::Add {
id: "task1".to_string(),
label: "Task 1".to_string(),
});
assert_eq!(output, Some(MultiProgressOutput::Added("task1".to_string())));Trait Implementations§
Source§impl Clone for MultiProgressState
impl Clone for MultiProgressState
Source§fn clone(&self) -> MultiProgressState
fn clone(&self) -> MultiProgressState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MultiProgressState
impl Debug for MultiProgressState
Source§impl Default for MultiProgressState
impl Default for MultiProgressState
Source§impl<'de> Deserialize<'de> for MultiProgressState
impl<'de> Deserialize<'de> for MultiProgressState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for MultiProgressState
impl PartialEq for MultiProgressState
Source§impl Serialize for MultiProgressState
impl Serialize for MultiProgressState
impl StructuralPartialEq for MultiProgressState
Auto Trait Implementations§
impl Freeze for MultiProgressState
impl RefUnwindSafe for MultiProgressState
impl Send for MultiProgressState
impl Sync for MultiProgressState
impl Unpin for MultiProgressState
impl UnsafeUnpin for MultiProgressState
impl UnwindSafe for MultiProgressState
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more