30 lines
681 B
Rust
30 lines
681 B
Rust
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
|
|
}
|