Refactored to require handlers to specify the components they rely on and to specify when they are ready. This fixes a lot of bugs with the UI when users try to press buttons while the application is still loading.
This commit is contained in:
@@ -52,6 +52,10 @@ impl ScrollableText {
|
||||
pub fn get_text(&self) -> String {
|
||||
self.items.join("\n")
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.items.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
impl Scrollable for ScrollableText {
|
||||
|
||||
@@ -41,6 +41,18 @@ mod tests {
|
||||
assert_str_eq!(scrollable_text.get_text(), test_text);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_scrollable_text_is_empty() {
|
||||
let scrollable_text = ScrollableText::default();
|
||||
|
||||
assert!(scrollable_text.is_empty());
|
||||
|
||||
let test_text = "Test \nString";
|
||||
let scrollable_text = ScrollableText::with_string(test_text.to_owned());
|
||||
|
||||
assert!(!scrollable_text.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_scrollable_text_scroll() {
|
||||
let mut scrollable_text = ScrollableText::with_string("Test \nString".to_owned());
|
||||
|
||||
@@ -92,4 +92,8 @@ where
|
||||
pub fn current_selection(&self) -> &T {
|
||||
&self.items[self.state.selected().unwrap_or(0)]
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.items.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +102,17 @@ mod tests {
|
||||
assert_eq!(stateful_list.state.selected(), Some(0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stateful_list_is_empty() {
|
||||
let mut stateful_list = create_test_stateful_list();
|
||||
|
||||
assert!(!stateful_list.is_empty());
|
||||
|
||||
stateful_list = StatefulList::default();
|
||||
|
||||
assert!(stateful_list.is_empty());
|
||||
}
|
||||
|
||||
fn create_test_stateful_list() -> StatefulList<&'static str> {
|
||||
let mut stateful_list = StatefulList::default();
|
||||
stateful_list.set_items(vec!["Test 1", "Test 2"]);
|
||||
|
||||
@@ -302,4 +302,8 @@ where
|
||||
pub fn reset_search(&mut self) {
|
||||
self.search = None;
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.items.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -638,6 +638,17 @@ mod tests {
|
||||
assert_eq!(stateful_table.search, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stateful_table_is_empty() {
|
||||
let mut stateful_table = create_test_stateful_table();
|
||||
|
||||
assert!(!stateful_table.is_empty());
|
||||
|
||||
stateful_table = StatefulTable::default();
|
||||
|
||||
assert!(stateful_table.is_empty());
|
||||
}
|
||||
|
||||
fn create_test_stateful_table() -> StatefulTable<&'static str> {
|
||||
let mut stateful_table = StatefulTable::default();
|
||||
stateful_table.set_items(vec!["Test 1", "Test 2"]);
|
||||
|
||||
Reference in New Issue
Block a user