97 lines
2.3 KiB
Rust
97 lines
2.3 KiB
Rust
use color_eyre::Result;
|
|
use crossterm::event::{KeyEvent, MouseEvent};
|
|
use ratatui::{
|
|
layout::{Constraint, Layout, Rect, Size},
|
|
Frame,
|
|
};
|
|
use tokio::sync::mpsc::UnboundedSender;
|
|
|
|
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 empty;
|
|
|
|
pub trait Component {
|
|
fn register_action_handler(&mut self, tx: UnboundedSender<Action>) -> Result<()> {
|
|
let _ = tx;
|
|
Ok(())
|
|
}
|
|
|
|
fn register_config_handler(&mut self, config: Config) -> Result<()> {
|
|
let _ = config;
|
|
Ok(())
|
|
}
|
|
|
|
fn handle_events(&mut self, event: Option<Event>) -> Result<Option<Action>> {
|
|
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<Option<Action>> {
|
|
let _ = key;
|
|
Ok(None)
|
|
}
|
|
|
|
fn handle_mouse_event(&mut self, mouse: MouseEvent) -> Result<Option<Action>> {
|
|
let _ = mouse;
|
|
Ok(None)
|
|
}
|
|
|
|
fn init(&mut self, area: Size) -> Result<()> {
|
|
let _ = area;
|
|
Ok(())
|
|
}
|
|
|
|
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
|
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::Percentage(50),
|
|
Constraint::Percentage(50),
|
|
]).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
|
|
}
|