Checkpoint
This commit is contained in:
+10
-7
@@ -20,7 +20,7 @@ const TEXT_SIZE: u32 = 160; // Size of the font in pixels
|
||||
const XOFFSET_ROUTE: u32 = 24;
|
||||
const XOFFSET_DESTINATION: u32 = 300;
|
||||
const XOFFSEET_TIME_LEFT: u32 = 1606;
|
||||
const INTER_LINE_SPACE: i32 = -15;
|
||||
const INTER_LINE_OVERLAP: u32 = 15;
|
||||
|
||||
|
||||
impl Screen<'_> {
|
||||
@@ -46,12 +46,14 @@ impl Screen<'_> {
|
||||
let due_in_mins = (entry.due_in / 60) as i32;
|
||||
let arrival_color: Color = self.color_for(due_in_mins);
|
||||
|
||||
self.do_print_at(line, entry.route, XOFFSET_ROUTE);
|
||||
self.do_print_at(line, entry.destination, XOFFSET_DESTINATION);
|
||||
self.color = COLOR_LCD_AMBER;
|
||||
self.do_print_at(line, &entry.route, XOFFSET_ROUTE);
|
||||
self.do_print_at(line, &entry.destination, XOFFSET_DESTINATION);
|
||||
self.color = arrival_color;
|
||||
self.do_print_at(line, &due_in_mins.to_string(), XOFFSEET_TIME_LEFT);
|
||||
};
|
||||
|
||||
if display_data.status.is_none() {
|
||||
if display_data.status.is_some() {
|
||||
self.do_print_at(5, display_data.status.as_ref().unwrap(), 0);
|
||||
}
|
||||
self.do_update();
|
||||
@@ -65,12 +67,12 @@ impl Screen<'_> {
|
||||
|
||||
|
||||
fn do_print_at(&mut self, line: u32, text: &str, left: u32) -> u32 {
|
||||
let rendered_text = self.font.render(text).solid(Color::RED).unwrap();
|
||||
let rendered_text = self.font.render(text).solid(self.color).unwrap();
|
||||
let texture_creator = self.canvas.texture_creator();
|
||||
let texture = rendered_text.as_texture(&texture_creator).unwrap();
|
||||
self.canvas.copy(&texture,
|
||||
let _= self.canvas.copy(&texture,
|
||||
Rect::new(0, 0, rendered_text.width(), rendered_text.height()),
|
||||
Rect::new(left.try_into().unwrap(), (line * rendered_text.height()).try_into().unwrap(), rendered_text.width(), rendered_text.height()));
|
||||
Rect::new(left.try_into().unwrap(), (line * (rendered_text.height() - INTER_LINE_OVERLAP)).try_into().unwrap(), rendered_text.width(), rendered_text.height()));
|
||||
return left + rendered_text.width();
|
||||
}
|
||||
|
||||
@@ -112,6 +114,7 @@ impl Screen<'_> {
|
||||
let mut screen: Screen = Screen {
|
||||
canvas: Box::new(window.into_canvas()),
|
||||
font: Box::new(font),
|
||||
color: COLOR_LCD_AMBER,
|
||||
context: Box::new(sdl_context),
|
||||
};
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use sdl3::{Sdl, render::Canvas, ttf::Font, video::Window};
|
||||
use sdl3::{Sdl, pixels::Color, render::Canvas, ttf::Font, video::Window};
|
||||
|
||||
|
||||
pub struct Screen<'a> {
|
||||
pub(crate) canvas: Box<Canvas<Window>>,
|
||||
pub(crate) font: Box<Font<'a>>,
|
||||
pub(crate) color: Color,
|
||||
pub(crate) context: Box<Sdl>
|
||||
}
|
||||
|
||||
@@ -14,13 +15,13 @@ pub struct Prefs {
|
||||
}
|
||||
|
||||
|
||||
pub struct DisplayEntry<'a> {
|
||||
pub route: &'a String,
|
||||
pub destination: &'a String,
|
||||
pub struct DisplayEntry {
|
||||
pub route: String,
|
||||
pub destination: String,
|
||||
pub due_in: i32,
|
||||
}
|
||||
|
||||
pub struct DisplayData<'a> {
|
||||
pub lines: Vec<DisplayEntry<'a>>,
|
||||
pub struct DisplayData {
|
||||
pub lines: Vec<DisplayEntry>,
|
||||
pub status: Option<String>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user