2023-05-28 22:18:30 -07:00
|
|
|
|
2023-05-31 22:27:26 -07:00
|
|
|
use crate::uis::new_transaction::NewTransactionTabState;
|
|
|
|
|
2023-05-31 18:00:17 -07:00
|
|
|
pub type AppResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
2023-05-28 22:18:30 -07:00
|
|
|
|
2023-05-31 22:27:26 -07:00
|
|
|
pub enum FocusedBlock {
|
|
|
|
Navigation,
|
|
|
|
Body,
|
|
|
|
}
|
|
|
|
|
2023-05-28 22:18:30 -07:00
|
|
|
pub struct App<'a> {
|
|
|
|
pub running: bool,
|
2023-05-31 18:00:17 -07:00
|
|
|
pub tabs: Vec<&'a str>,
|
|
|
|
pub tab_index: usize,
|
2023-05-31 22:27:26 -07:00
|
|
|
pub focus: FocusedBlock,
|
|
|
|
|
|
|
|
pub new_transaction_tab_state: NewTransactionTabState<'a>,
|
|
|
|
|
2023-05-28 22:18:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> App<'a> {
|
2023-05-31 18:00:17 -07:00
|
|
|
pub fn new() -> App<'a> {
|
|
|
|
App {
|
|
|
|
running: true,
|
2023-05-28 22:18:30 -07:00
|
|
|
|
2023-05-31 22:27:26 -07:00
|
|
|
tabs: vec!["History", "Tab2", "Tab3"],
|
2023-05-31 18:00:17 -07:00
|
|
|
tab_index: 0,
|
2023-05-31 22:27:26 -07:00
|
|
|
focus: FocusedBlock::Navigation,
|
|
|
|
|
|
|
|
new_transaction_tab_state: NewTransactionTabState::new(),
|
2023-05-31 18:00:17 -07:00
|
|
|
}
|
2023-05-28 22:18:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn next_tab(&mut self) {
|
2023-05-31 18:00:17 -07:00
|
|
|
self.tab_index = (self.tab_index + 1) % self.tabs.len();
|
2023-05-28 22:18:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn prev_tab(&mut self) {
|
2023-05-31 18:00:17 -07:00
|
|
|
if self.tab_index > 0 {
|
|
|
|
self.tab_index -= 1;
|
2023-05-28 22:18:30 -07:00
|
|
|
} else {
|
2023-05-31 18:00:17 -07:00
|
|
|
self.tab_index = self.tabs.len() - 1;
|
2023-05-28 22:18:30 -07:00
|
|
|
}
|
2023-05-31 22:27:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn focus_navigation(&mut self) {
|
|
|
|
self.focus = FocusedBlock::Navigation;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn focus_body(&mut self) {
|
|
|
|
self.focus = FocusedBlock::Body;
|
|
|
|
}
|
|
|
|
}
|