Added room info and massively improved layout
This commit is contained in:
40
src/main.rs
40
src/main.rs
@@ -10,6 +10,7 @@ use embedded_graphics::{
|
||||
text::{Text},
|
||||
Drawable,
|
||||
};
|
||||
use embedded_layout::layout::linear::ElementSpacing;
|
||||
use epd_waveshare::{color::Color, epd7in5_v2::Epd7in5, prelude::WaveshareDisplay};
|
||||
use esp_idf_hal::modem::Modem;
|
||||
use esp_idf_hal::{
|
||||
@@ -291,12 +292,13 @@ fn fetch_data(modem: Modem) -> anyhow::Result<(Box<Timetable>, DateTime<FixedOff
|
||||
}
|
||||
|
||||
|
||||
fn is_lesson_cancelled(l: &Lesson) -> bool{
|
||||
l.code == LessonCode::Cancelled || l.subst_text.as_ref().is_some_and(|s| s == "Aufgaben")
|
||||
}
|
||||
|
||||
fn draw_layout(display: &mut epd_waveshare::epd7in5_v2::Display7in5, timetable: &Timetable, now: DateTime<FixedOffset>, next_wakeup_time: DateTime<FixedOffset>){
|
||||
let display_area = display.bounding_box();
|
||||
|
||||
let margin = FixedMargin(15);
|
||||
|
||||
|
||||
// let text_style = MonoTextStyle::new(&embedded_graphics::mono_font::ascii::FONT_10X20, Color::White);
|
||||
let text_style = U8g2TextStyle::new(u8g2_fonts::fonts::u8g2_font_profont22_mr, Color::White);
|
||||
|
||||
@@ -312,24 +314,42 @@ fn draw_layout(display: &mut epd_waveshare::epd7in5_v2::Display7in5, timetable:
|
||||
let current_period = get_school_period(now.time());
|
||||
|
||||
let mut texts = timetable.iter().enumerate().map(|(day_index, day)| day.iter().enumerate().map(|(period, l)| {
|
||||
let s = if let Some(l) = l && l.code != LessonCode::Cancelled{
|
||||
Some(l.subjects.first().unwrap().name.as_str())
|
||||
let s = if let Some(l) = l && !is_lesson_cancelled(l){
|
||||
(||{
|
||||
Some(l.subjects.first()?.name.as_str())
|
||||
})()
|
||||
}else{
|
||||
None
|
||||
}.and_then(get_full_subject_name);
|
||||
|
||||
let room_str = if let Some(l) = l && !is_lesson_cancelled(l){
|
||||
(||{
|
||||
Some(l.rooms.first()?.name.as_str())
|
||||
})()
|
||||
}else{
|
||||
None
|
||||
};
|
||||
|
||||
let text_style = if period as u8 == current_period && day_index as u32 == day_of_week{
|
||||
&inverted_text_style
|
||||
}else{
|
||||
&text_style
|
||||
};
|
||||
//LinearLayout::horizontal(Chain::new(Text::new()))
|
||||
LinearLayout::vertical(
|
||||
Chain::new(
|
||||
Text::new(s.unwrap_or_else(|| &empty_str), Point::zero(), text_style)
|
||||
).append(
|
||||
Text::new(room_str.unwrap_or_else(|| &empty_str), Point::zero(), &text_style_small)
|
||||
)
|
||||
)
|
||||
.with_spacing(FixedMargin(2)).arrange()
|
||||
|
||||
}).collect::<Vec<_>>()).collect::<Vec<_>>();
|
||||
|
||||
let mut columns = texts.iter_mut().map(|day|
|
||||
LinearLayout::vertical(Views::new(day))
|
||||
.align_to(&display_area, horizontal::Center, vertical::Top)
|
||||
.with_spacing(margin)
|
||||
.with_spacing(FixedMargin(15))
|
||||
.arrange()
|
||||
).collect::<Vec<_>>();
|
||||
|
||||
@@ -343,16 +363,16 @@ fn draw_layout(display: &mut epd_waveshare::epd7in5_v2::Display7in5, timetable:
|
||||
|
||||
let time_table_grid = LinearLayout::horizontal(columns)
|
||||
.with_alignment(vertical::Center)
|
||||
.with_spacing(margin)
|
||||
.with_spacing(FixedMargin(18))
|
||||
.arrange();
|
||||
|
||||
let subtext = LinearLayout::vertical(Chain::new(time_text).append(Text::new(&next_wakeup_time_str, Point::zero(), &text_style_small))).with_alignment(horizontal::Center).with_spacing(FixedMargin(2)).arrange();
|
||||
|
||||
LinearLayout::vertical(Chain::new(time_table_grid).append(subtext))
|
||||
.with_alignment(horizontal::Center)
|
||||
.with_spacing(DistributeFill(display_area.size.height-20))
|
||||
.with_spacing(DistributeFill(display_area.size.height-10))
|
||||
.arrange()
|
||||
.align_to(&display_area, horizontal::Center, vertical::Center)
|
||||
.align_to(&display_area, horizontal::Center, vertical::Bottom)
|
||||
.draw(display)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user