mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
add more convenience apis
This commit is contained in:
parent
9512defd2d
commit
0e5410eb36
1 changed files with 29 additions and 0 deletions
|
|
@ -214,6 +214,18 @@ impl ScrollableList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn delete_selected(&mut self) -> String {
|
||||||
|
if self.items[self.select_index.0].len() > self.select_index.1 {
|
||||||
|
let removed = self.items[self.select_index.0].remove(self.select_index.1);
|
||||||
|
if self.select_index.1 >= self.items[self.select_index.0].len() {
|
||||||
|
self.select_index.1 = self.items.len().saturating_sub(1);
|
||||||
|
}
|
||||||
|
removed
|
||||||
|
} else {
|
||||||
|
"".to_owned()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Set the scroll offset. The selected element is the start of list rendering, and
|
/// Set the scroll offset. The selected element is the start of list rendering, and
|
||||||
/// it designates the top left element on the screen.
|
/// it designates the top left element on the screen.
|
||||||
///
|
///
|
||||||
|
|
@ -298,6 +310,23 @@ impl ScrollableList {
|
||||||
self.items[self.select_index.0][self.select_index.1] = contents.to_owned();
|
self.items[self.select_index.0][self.select_index.1] = contents.to_owned();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Replaces every instance of a `original` string with `replacement` string in a given column
|
||||||
|
/// Returns the number of instances replaced.
|
||||||
|
pub fn replace_with(&mut self, column: usize, original: &str, replacement: &str) -> usize {
|
||||||
|
if column >= self.items.len() {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
let mut count = 0;
|
||||||
|
for item in self.items[column].iter_mut() {
|
||||||
|
if item == original {
|
||||||
|
*item = replacement.to_string();
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
count
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns all the items as a nested iterator.
|
/// Returns all the items as a nested iterator.
|
||||||
pub fn get_all(&self) -> impl Iterator<Item = impl Iterator<Item = &str>> {
|
pub fn get_all(&self) -> impl Iterator<Item = impl Iterator<Item = &str>> {
|
||||||
self.items.iter().map(|inner_vec| inner_vec.iter().map(|s| s.as_str()))
|
self.items.iter().map(|inner_vec| inner_vec.iter().map(|s| s.as_str()))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue