diff --git a/Cargo.toml b/Cargo.toml index ca6fcec..f34c6f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,7 @@ embedded-svc = "0.28.1" untis = {path = "../untis-test/untis-rs"} chrono = "0.4.41" embedded-layout = "0.4.2" +u8g2-fonts = { version = "0.5.2", features = ["embedded_graphics_textstyle"] } # --- Optional Embassy Integration --- # esp-idf-svc = { version = "0.51", features = ["critical-section", "embassy-time-driver", "embassy-sync"] } diff --git a/src/main.rs b/src/main.rs index c5ec5aa..d0e347c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use std::str::FromStr; -use chrono::{Datelike, Days, NaiveTime}; +use chrono::{format::Fixed, Datelike, Days, NaiveTime}; use embedded_graphics::{ mono_font::{MonoTextStyle, MonoTextStyleBuilder}, prelude::{Dimensions, Point}, @@ -22,9 +22,9 @@ use esp_idf_svc::{ nvs::EspDefaultNvsPartition, wifi::Configuration, }; -use esp_idf_sys::time; +use u8g2_fonts::U8g2TextStyle; use untis::{Date, Lesson}; -use embedded_layout::{layout::linear::LinearLayout, prelude::*}; +use embedded_layout::{layout::linear::{FixedMargin, LinearLayout}, prelude::*}; type Timetable = [[Option;8]; 5]; @@ -139,26 +139,35 @@ fn draw_text(display: &mut epd_waveshare::epd7in5_v2::Display7in5, text: &str, x fn draw_layout(display: &mut epd_waveshare::epd7in5_v2::Display7in5, timetable: &Timetable){ let display_area = display.bounding_box(); - let text_style = MonoTextStyle::new(&embedded_graphics::mono_font::ascii::FONT_6X9, Color::White); + let margin = FixedMargin(10); + // let text_style = MonoTextStyle::new(&embedded_graphics::mono_font::ascii::FONT_10X20, Color::White); + let text_style = U8g2TextStyle::new(u8g2_fonts::fonts::u8g2_font_inr21_mf, Color::White); + let empty_str = String::from(" "); - let empty_str = String::new(); - - let mut texts = timetable[0].iter().map(|l| { + let mut texts = timetable.iter().map(|day| day.iter().map(|l| { if let Some(l) = l{ Some(l.subjects.first().unwrap().name.as_str()) }else{ None } }).map(|s|{ - Text::new(s.unwrap_or_else(|| &empty_str), Point::zero(), text_style) - }).collect::>(); + Text::new(s.unwrap_or_else(|| &empty_str), Point::zero(), &text_style) + }).collect::>()).collect::>(); - let vg = Views::new(&mut texts); + let mut columns = texts.iter_mut().map(|day| + LinearLayout::vertical(Views::new(day)) + .align_to(&display_area, horizontal::Center, vertical::Top) + .with_spacing(margin) + .arrange() + ).collect::>(); - LinearLayout::vertical(vg) - .with_alignment(horizontal::Center) + let columns = Views::new(&mut columns); + + LinearLayout::horizontal(columns) + .with_alignment(vertical::Center) + .with_spacing(margin) .arrange() - .align_to(&display_area, horizontal::Center, vertical::Center) + .align_to(&display_area, horizontal::Center, vertical::Top) .draw(display) .unwrap(); }