35 lines
759 B
Rust
35 lines
759 B
Rust
use crossterm::event::Event;
|
|
|
|
use super::{Component, Rect, View};
|
|
use crate::Result;
|
|
|
|
pub struct Context {
|
|
pub view: View,
|
|
pub event: Option<Event>,
|
|
}
|
|
|
|
impl Default for Context {
|
|
fn default() -> Self {
|
|
Context {
|
|
view: View::fullscreen(),
|
|
event: None,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Context {
|
|
pub fn new(width: u16, height: u16, event: Option<Event>) -> Self {
|
|
Context {
|
|
view: View::new(width, height),
|
|
event,
|
|
}
|
|
}
|
|
|
|
pub fn add_component(&mut self, rect: Rect, cmp: &mut impl Component) -> Result<()> {
|
|
let mut ctx = Context::new(rect.width, rect.height, self.event);
|
|
cmp.view(&mut ctx)?;
|
|
self.view.merge(rect.pos, ctx.view);
|
|
Ok(())
|
|
}
|
|
}
|