You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.4 KiB

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<D> {
drawtarget: D,
pub weight: f32,
}
pub struct VSplit<T, U> {
pub left: T,
pub right: U,
pub ratio: f32,
}
impl<T, U> VSplit<T, U> {
pub fn new(left: T, right: U) -> Self {
VSplit {
left,
right,
ratio: 0.5,
}
}
}
impl<T, U> VSplit<T, U> {
pub fn with_ratio(self, ratio: f32) -> Self {
VSplit { ratio, ..self }
}
}
impl<C, T, U> Drawable for VSplit<T, U>
where
C: PixelColor + From<BinaryColor>,
T: Drawable<Color = C>,
U: Drawable<Color = C>,
{
type Color = C;
type Output = ();
fn draw<D>(&self, target: &mut D) -> Result<Self::Output, D::Error>
where
D: DrawTarget<Color = C>,
{
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<T> {
pub top_left: Point,
pub size: Size,
pub top: T,
pub bottom: T,
}