This commit is contained in:
RainBus
2024-10-16 20:32:02 +08:00
parent ef6f088fde
commit c8eb942b13
13 changed files with 269 additions and 63 deletions

View File

@@ -1,7 +1,29 @@
use component::Component;
use std::io;
use crossterm::event::Event;
use ratatui::{
layout::{Flex, Layout, Rect},
Frame,
};
pub mod component;
pub mod home;
pub mod setting;
pub trait View {
fn draw(&self, frame: &mut Frame);
fn handle_event(&mut self, event: &Event) -> io::Result<()>;
}
pub trait PopupView {
fn draw(&self, frame: &mut Frame);
fn handle_event(&mut self, event: &Event);
}
fn center_rect(area: Rect, width: u16, height: u16) -> Rect {
let horizontal = Layout::horizontal([width]).flex(Flex::Center);
let vertical = Layout::vertical([height]).flex(Flex::Center);
let [area] = vertical.areas(area);
let [area] = horizontal.areas(area);
area
}