Recreate repository due to Git object corruption (all files preserved)
This commit is contained in:
57
examples/focus_example.rs
Normal file
57
examples/focus_example.rs
Normal file
@@ -0,0 +1,57 @@
|
||||
extern crate alloc;
|
||||
|
||||
use tui_orchestrator::focus::{FocusManager, Focusable};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
enum FormElement {
|
||||
Username,
|
||||
Password,
|
||||
RememberMe,
|
||||
Submit,
|
||||
Cancel,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
struct LoginForm {
|
||||
username: String,
|
||||
password: String,
|
||||
remember: bool,
|
||||
}
|
||||
|
||||
impl Focusable<FormElement> for LoginForm {
|
||||
fn focus_targets(&self) -> alloc::vec::Vec<FormElement> {
|
||||
vec![
|
||||
FormElement::Username,
|
||||
FormElement::Password,
|
||||
FormElement::RememberMe,
|
||||
FormElement::Submit,
|
||||
FormElement::Cancel,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let form = LoginForm {
|
||||
username: String::new(),
|
||||
password: String::new(),
|
||||
remember: false,
|
||||
};
|
||||
|
||||
let mut focus_manager: FocusManager<FormElement> = FocusManager::new();
|
||||
focus_manager.set_targets(form.focus_targets());
|
||||
|
||||
assert_eq!(focus_manager.current(), Some(&FormElement::Username));
|
||||
|
||||
focus_manager.next();
|
||||
assert_eq!(focus_manager.current(), Some(&FormElement::Password));
|
||||
|
||||
focus_manager.set_focus(FormElement::Submit).unwrap();
|
||||
assert_eq!(focus_manager.current(), Some(&FormElement::Submit));
|
||||
|
||||
let query = focus_manager.query();
|
||||
assert!(query.is_focused(&FormElement::Submit));
|
||||
|
||||
focus_manager.set_overlay(FormElement::Cancel);
|
||||
assert!(focus_manager.has_overlay());
|
||||
assert_eq!(focus_manager.current(), Some(&FormElement::Cancel));
|
||||
}
|
||||
Reference in New Issue
Block a user