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.
115 lines
2.7 KiB
115 lines
2.7 KiB
use embedded_components::{ |
|
Calendar, ComponentStyle, Gauge, List, ListItem, ListItemData, ScrollingCalendar, VSplit, |
|
}; |
|
use embedded_graphics::{ |
|
pixelcolor::{raw::RawU2, BinaryColor, Rgb888}, |
|
prelude::*, |
|
}; |
|
use embedded_graphics_simulator::{ |
|
BinaryColorTheme, OutputSettingsBuilder, SimulatorDisplay, Window, |
|
}; |
|
|
|
#[derive(Copy, Clone, PartialEq, Eq)] |
|
enum TriColor { |
|
White, |
|
Black, |
|
Red, |
|
} |
|
|
|
impl PixelColor for TriColor { |
|
type Raw = RawU2; |
|
} |
|
|
|
impl From<BinaryColor> for TriColor { |
|
fn from(value: BinaryColor) -> TriColor { |
|
match value { |
|
BinaryColor::On => TriColor::Black, |
|
BinaryColor::Off => TriColor::White, |
|
} |
|
} |
|
} |
|
|
|
impl Into<Rgb888> for TriColor { |
|
fn into(self) -> Rgb888 { |
|
match self { |
|
TriColor::Black => Rgb888::new(0, 0, 0), |
|
TriColor::White => Rgb888::new(255, 255, 255), |
|
TriColor::Red => Rgb888::new(180, 0, 0), |
|
} |
|
} |
|
} |
|
|
|
impl From<Rgb888> for TriColor { |
|
fn from(value: Rgb888) -> TriColor { |
|
match value { |
|
_ => TriColor::White, |
|
} |
|
} |
|
} |
|
|
|
fn main() -> Result<(), core::convert::Infallible> { |
|
//let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(212, 104)); |
|
//let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(800, 480)); |
|
let mut display = SimulatorDisplay::<TriColor>::new(Size::new(600, 448)); |
|
|
|
let fg_color = TriColor::Black; |
|
let bg_color = TriColor::White; |
|
let hi_color = Some(TriColor::Red); |
|
|
|
let calendar_style = ComponentStyle { |
|
border: 1, |
|
bezel: 1, |
|
fg_color, |
|
bg_color, |
|
hi_color: TriColor::Red, |
|
border_color: TriColor::Black, |
|
}; |
|
|
|
let gauge = Gauge { |
|
top_left: Point::new(300, 300), |
|
bezel: 1, |
|
border: 1, |
|
size: Size::new(200, 20), |
|
ratio: 0.5, |
|
fg_color, |
|
bg_color, |
|
text: "test test test test test", |
|
}; |
|
//gauge.draw(&mut display)?; |
|
|
|
let calendar = Calendar { |
|
top_left: Point::new(10, 10), |
|
size: Size::new(196, 196), |
|
style: calendar_style.clone(), |
|
}; |
|
//calendar.draw(&mut display)?; |
|
|
|
let list = List { |
|
style: calendar_style.clone(), |
|
items_shown: 10, |
|
list_items: vec![ |
|
ListItemData::new("I", "Test task").with_progress(100f32), |
|
ListItemData::new("O", "Other test task"), |
|
], |
|
}; |
|
//list.draw(&mut display)?; |
|
|
|
let calendar_week = ScrollingCalendar { |
|
style: calendar_style, |
|
day: chrono::Local::now().naive_local().date(), |
|
//.checked_add_signed(chrono::Duration::days(28 * 4 * 0 - 14)) |
|
//.unwrap(), |
|
prev_weeks: 2, |
|
next_weeks: 5, |
|
}; |
|
//calendar_week.draw(&mut display)?; |
|
|
|
VSplit::new(calendar_week, list).draw(&mut display)?; |
|
|
|
let output_settings = OutputSettingsBuilder::new() |
|
.theme(BinaryColorTheme::Default) |
|
.build(); |
|
Window::new("Hello World", &output_settings).show_static(&display); |
|
|
|
Ok(()) |
|
}
|
|
|