Files
rstemp/src/view.rs
RainBus c8eb942b13 Popup
2024-10-16 20:32:02 +08:00

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
}