Implemented an actual timetable layout with u8g2 fonts
This commit is contained in:
@@ -36,6 +36,7 @@ embedded-svc = "0.28.1"
|
|||||||
untis = {path = "../untis-test/untis-rs"}
|
untis = {path = "../untis-test/untis-rs"}
|
||||||
chrono = "0.4.41"
|
chrono = "0.4.41"
|
||||||
embedded-layout = "0.4.2"
|
embedded-layout = "0.4.2"
|
||||||
|
u8g2-fonts = { version = "0.5.2", features = ["embedded_graphics_textstyle"] }
|
||||||
|
|
||||||
# --- Optional Embassy Integration ---
|
# --- Optional Embassy Integration ---
|
||||||
# esp-idf-svc = { version = "0.51", features = ["critical-section", "embassy-time-driver", "embassy-sync"] }
|
# esp-idf-svc = { version = "0.51", features = ["critical-section", "embassy-time-driver", "embassy-sync"] }
|
||||||
|
|||||||
35
src/main.rs
35
src/main.rs
@@ -1,7 +1,7 @@
|
|||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use chrono::{Datelike, Days, NaiveTime};
|
use chrono::{format::Fixed, Datelike, Days, NaiveTime};
|
||||||
use embedded_graphics::{
|
use embedded_graphics::{
|
||||||
mono_font::{MonoTextStyle, MonoTextStyleBuilder},
|
mono_font::{MonoTextStyle, MonoTextStyleBuilder},
|
||||||
prelude::{Dimensions, Point},
|
prelude::{Dimensions, Point},
|
||||||
@@ -22,9 +22,9 @@ use esp_idf_svc::{
|
|||||||
nvs::EspDefaultNvsPartition,
|
nvs::EspDefaultNvsPartition,
|
||||||
wifi::Configuration,
|
wifi::Configuration,
|
||||||
};
|
};
|
||||||
use esp_idf_sys::time;
|
use u8g2_fonts::U8g2TextStyle;
|
||||||
use untis::{Date, Lesson};
|
use untis::{Date, Lesson};
|
||||||
use embedded_layout::{layout::linear::LinearLayout, prelude::*};
|
use embedded_layout::{layout::linear::{FixedMargin, LinearLayout}, prelude::*};
|
||||||
|
|
||||||
type Timetable = [[Option<Lesson>;8]; 5];
|
type Timetable = [[Option<Lesson>;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){
|
fn draw_layout(display: &mut epd_waveshare::epd7in5_v2::Display7in5, timetable: &Timetable){
|
||||||
let display_area = display.bounding_box();
|
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.iter().map(|day| day.iter().map(|l| {
|
||||||
|
|
||||||
let mut texts = timetable[0].iter().map(|l| {
|
|
||||||
if let Some(l) = l{
|
if let Some(l) = l{
|
||||||
Some(l.subjects.first().unwrap().name.as_str())
|
Some(l.subjects.first().unwrap().name.as_str())
|
||||||
}else{
|
}else{
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}).map(|s|{
|
}).map(|s|{
|
||||||
Text::new(s.unwrap_or_else(|| &empty_str), Point::zero(), text_style)
|
Text::new(s.unwrap_or_else(|| &empty_str), Point::zero(), &text_style)
|
||||||
}).collect::<Vec<_>>();
|
}).collect::<Vec<_>>()).collect::<Vec<_>>();
|
||||||
|
|
||||||
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::<Vec<_>>();
|
||||||
|
|
||||||
LinearLayout::vertical(vg)
|
let columns = Views::new(&mut columns);
|
||||||
.with_alignment(horizontal::Center)
|
|
||||||
|
LinearLayout::horizontal(columns)
|
||||||
|
.with_alignment(vertical::Center)
|
||||||
|
.with_spacing(margin)
|
||||||
.arrange()
|
.arrange()
|
||||||
.align_to(&display_area, horizontal::Center, vertical::Center)
|
.align_to(&display_area, horizontal::Center, vertical::Top)
|
||||||
.draw(display)
|
.draw(display)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user