use embedded_graphics::{pixelcolor::BinaryColor, prelude::*, primitives::Rectangle}; use embedded_layout::View; pub trait Component { fn set_top_left(&mut self, top_left: Point); fn set_size(&mut self, size: Size); } pub struct Frame { drawtarget: D, pub weight: f32, } pub struct VSplit { pub left: T, pub right: U, pub ratio: f32, } impl VSplit { pub fn new(left: T, right: U) -> Self { VSplit { left, right, ratio: 0.5, } } } impl VSplit { pub fn with_ratio(self, ratio: f32) -> Self { VSplit { ratio, ..self } } } impl Drawable for VSplit where C: PixelColor + From, T: Drawable, U: Drawable, { type Color = C; type Output = (); fn draw(&self, target: &mut D) -> Result where D: DrawTarget, { let size = target.bounding_box().size; let left_width = (size.width as f32 * self.ratio) as u32; self.left.draw(&mut target.clipped(&Rectangle::new( Point::default(), Size::new(left_width, size.height), )))?; self.right.draw(&mut target.clipped(&Rectangle::new( Point::new(left_width as i32, 0), Size::new(size.width - left_width, size.height), )))?; Ok(()) } } pub struct HSplit { pub top_left: Point, pub size: Size, pub top: T, pub bottom: T, }