5 changed files with 171 additions and 24 deletions
@ -0,0 +1,109 @@ |
|||||||
|
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 top_left = target.bounding_box().top_left; |
||||||
|
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( |
||||||
|
top_left, |
||||||
|
Size::new(left_width, size.height), |
||||||
|
)))?; |
||||||
|
|
||||||
|
self.right.draw(&mut target.clipped(&Rectangle::new( |
||||||
|
top_left + Point::new(left_width as i32, 0), |
||||||
|
Size::new(size.width - left_width, size.height), |
||||||
|
)))?; |
||||||
|
|
||||||
|
Ok(()) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
pub struct HSplit<T, U> { |
||||||
|
pub top_left: Point, |
||||||
|
pub size: Size, |
||||||
|
pub top: T, |
||||||
|
pub bottom: U, |
||||||
|
pub ratio: f32, |
||||||
|
} |
||||||
|
|
||||||
|
impl<T, U> HSplit<T, U> { |
||||||
|
pub fn with_ratio(self, ratio: f32) -> Self { |
||||||
|
HSplit { ratio, ..self } |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
impl<C, T, U> Drawable for HSplit<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 top_left = target.bounding_box().top_left; |
||||||
|
let size = target.bounding_box().size; |
||||||
|
let top_height = (size.height as f32 * self.ratio) as u32; |
||||||
|
|
||||||
|
self |
||||||
|
.top |
||||||
|
.draw(&mut target.clipped(&Rectangle::new(top_left, Size::new(size.width, top_height))))?; |
||||||
|
|
||||||
|
self.bottom.draw(&mut target.clipped(&Rectangle::new( |
||||||
|
top_left + Point::new(0, top_height as i32), |
||||||
|
Size::new(size.width, size.height - top_height), |
||||||
|
)))?; |
||||||
|
|
||||||
|
Ok(()) |
||||||
|
} |
||||||
|
} |
||||||
@ -1,11 +1,13 @@ |
|||||||
mod bullet_counter; |
mod bullet_counter; |
||||||
mod calendar; |
mod calendar; |
||||||
|
mod frame; |
||||||
mod gauge; |
mod gauge; |
||||||
mod list_item; |
mod list_item; |
||||||
mod style; |
mod style; |
||||||
|
|
||||||
pub use bullet_counter::BulletCounter; |
pub use bullet_counter::BulletCounter; |
||||||
pub use calendar::{Calendar, ScrollingCalendar}; |
pub use calendar::{Calendar, ScrollingCalendar}; |
||||||
|
pub use frame::{Component, HSplit, VSplit}; |
||||||
pub use gauge::Gauge; |
pub use gauge::Gauge; |
||||||
pub use list_item::{List, ListItem, ListItemData}; |
pub use list_item::{List, ListItem, ListItemData}; |
||||||
pub use style::ComponentStyle; |
pub use style::ComponentStyle; |
||||||
|
|||||||
Loading…
Reference in new issue