Recreate repository due to Git object corruption (all files preserved)
This commit is contained in:
19
src/component/action.rs
Normal file
19
src/component/action.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
// path_from_the_root: src/component/action.rs
|
||||
|
||||
use crate::input::Action;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ComponentAction {
|
||||
Next,
|
||||
Prev,
|
||||
First,
|
||||
Last,
|
||||
Select,
|
||||
Cancel,
|
||||
TypeChar(char),
|
||||
Backspace,
|
||||
Delete,
|
||||
Custom(usize),
|
||||
}
|
||||
|
||||
impl Action for ComponentAction {}
|
||||
7
src/component/error.rs
Normal file
7
src/component/error.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
// path_from_the_root: src/component/error.rs
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ComponentError {
|
||||
EmptyTargets,
|
||||
InvalidFocus,
|
||||
}
|
||||
9
src/component/mod.rs
Normal file
9
src/component/mod.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
// path_from_the_root: src/component/mod.rs
|
||||
|
||||
pub mod action;
|
||||
pub mod error;
|
||||
pub mod r#trait;
|
||||
|
||||
pub use action::ComponentAction;
|
||||
pub use error::ComponentError;
|
||||
pub use r#trait::Component;
|
||||
50
src/component/trait.rs
Normal file
50
src/component/trait.rs
Normal file
@@ -0,0 +1,50 @@
|
||||
// path_from_the_root: src/component/trait.rs
|
||||
|
||||
use super::error::ComponentError;
|
||||
use crate::focus::FocusId;
|
||||
|
||||
pub trait Component {
|
||||
type Focus: FocusId;
|
||||
type Action: core::fmt::Debug + Clone;
|
||||
type Event: Clone + core::fmt::Debug;
|
||||
|
||||
fn targets(&self) -> &[Self::Focus];
|
||||
|
||||
fn handle(
|
||||
&mut self,
|
||||
focus: &Self::Focus,
|
||||
action: Self::Action,
|
||||
) -> Result<Option<Self::Event>, ComponentError>;
|
||||
|
||||
fn on_enter(&mut self) -> Result<(), ComponentError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn on_exit(&mut self) -> Result<(), ComponentError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn on_focus(&mut self, _focus: &Self::Focus) -> Result<(), ComponentError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn on_blur(&mut self, _focus: &Self::Focus) -> Result<(), ComponentError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_text(
|
||||
&mut self,
|
||||
focus: &Self::Focus,
|
||||
_ch: char,
|
||||
) -> Result<Option<Self::Event>, ComponentError> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn can_navigate_forward(&self, _focus: &Self::Focus) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn can_navigate_backward(&self, _focus: &Self::Focus) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user