use crossterm::event::Event; use super::{Component, Rect, View}; use crate::Result; pub struct Context { pub view: View, pub event: Option, } impl Default for Context { fn default() -> Self { Context { view: View::fullscreen(), event: None, } } } impl Context { pub fn new(width: u16, height: u16, event: Option) -> 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(()) } }