fix rendering: clear boot logo on first update, stack text vertically
This commit is contained in:
@@ -2,36 +2,55 @@ use std::sync::mpsc;
|
||||
use client_domain::{BoundingBox, DisplayPort};
|
||||
use client_application::ClientApp;
|
||||
use protocol::ServerMessage;
|
||||
use crate::config::RENDER_POLL_INTERVAL;
|
||||
use crate::config::{RENDER_POLL_INTERVAL, SCREEN};
|
||||
use crate::adapters::display::Esp32DisplayAdapter;
|
||||
use log::*;
|
||||
|
||||
const LINE_HEIGHT: u16 = 12;
|
||||
const TEXT_PADDING: u16 = 4;
|
||||
|
||||
pub fn run(
|
||||
screen: BoundingBox,
|
||||
mut display: Esp32DisplayAdapter,
|
||||
rx: mpsc::Receiver<ServerMessage>,
|
||||
) {
|
||||
let mut app = ClientApp::new(screen);
|
||||
let mut first_update = true;
|
||||
info!("Render loop started");
|
||||
|
||||
loop {
|
||||
match rx.recv_timeout(RENDER_POLL_INTERVAL) {
|
||||
Ok(msg) => {
|
||||
let repaints = app.handle_message(msg);
|
||||
|
||||
if !repaints.is_empty() && first_update {
|
||||
display.fill_background(SCREEN).unwrap();
|
||||
first_update = false;
|
||||
}
|
||||
|
||||
for cmd in &repaints {
|
||||
display.clear_region(cmd.bounds).unwrap();
|
||||
|
||||
let mut y_offset = TEXT_PADDING;
|
||||
for kv in &cmd.state.data {
|
||||
if let protocol::WireValue::String(s) = &kv.value {
|
||||
let text_bounds = BoundingBox::new(
|
||||
cmd.bounds.x + TEXT_PADDING,
|
||||
cmd.bounds.y + y_offset,
|
||||
cmd.bounds.width.saturating_sub(TEXT_PADDING * 2),
|
||||
LINE_HEIGHT,
|
||||
);
|
||||
display.draw_text(
|
||||
&format!("{}: {s}", kv.key),
|
||||
cmd.bounds.x,
|
||||
cmd.bounds.y,
|
||||
cmd.bounds,
|
||||
text_bounds.x,
|
||||
text_bounds.y,
|
||||
text_bounds,
|
||||
).unwrap();
|
||||
y_offset += LINE_HEIGHT + 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !repaints.is_empty() {
|
||||
display.flush().unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user