use color_eyre::Result; use crossterm::event::{KeyEvent, MouseEvent}; use ratatui::{ layout::{Constraint, Layout, Rect, Size}, Frame, }; use tokio::sync::mpsc::UnboundedSender; use std::sync::mpsc::Sender; use crate::{palette, action::Action, config::Config, tui::Event}; pub mod fps; pub mod health; pub mod menu; pub mod version; pub mod explorer; pub mod wallet; pub mod validator; pub mod nominator; pub mod empty; pub trait Component { fn register_network_handler(&mut self, tx: Sender) -> Result<()> { let _ = tx; Ok(()) } fn register_action_handler(&mut self, tx: UnboundedSender) -> Result<()> { let _ = tx; Ok(()) } fn register_config_handler(&mut self, config: Config) -> Result<()> { let _ = config; Ok(()) } fn handle_events(&mut self, event: Option) -> Result> { let action = match event { Some(Event::Key(key_event)) => self.handle_key_event(key_event)?, Some(Event::Mouse(mouse_event)) => self.handle_mouse_event(mouse_event)?, _ => None, }; Ok(action) } fn handle_key_event(&mut self, key: KeyEvent) -> Result> { let _ = key; Ok(None) } fn handle_mouse_event(&mut self, mouse: MouseEvent) -> Result> { let _ = mouse; Ok(None) } fn init(&mut self, area: Size) -> Result<()> { let _ = area; Ok(()) } fn update(&mut self, action: Action) -> Result> { let _ = action; Ok(None) } fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()>; } pub fn global_layout(area: Rect) -> [Rect; 2] { Layout::vertical([ Constraint::Length(1), Constraint::Fill(1), ]).areas(area) } pub fn header_layout(area: Rect) -> [Rect; 2] { let [header, _] = global_layout(area); Layout::horizontal([ Constraint::Fill(1), Constraint::Length(27), ]).areas(header) } pub fn main_layout(area: Rect) -> [Rect; 2] { let [_, main] = global_layout(area); Layout::horizontal([ Constraint::Max(30), Constraint::Fill(1), ]).areas(main) } pub fn menu_layout(area: Rect) -> [Rect; 2] { let [menu, _] = main_layout(area); Layout::vertical([ Constraint::Min(0), Constraint::Length(5), ]).areas(menu) } pub fn screen_layout(area: Rect) -> Rect { let [_, screen] = main_layout(area); screen }