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_domain::{BoundingBox, DisplayPort};
|
||||||
use client_application::ClientApp;
|
use client_application::ClientApp;
|
||||||
use protocol::ServerMessage;
|
use protocol::ServerMessage;
|
||||||
use crate::config::RENDER_POLL_INTERVAL;
|
use crate::config::{RENDER_POLL_INTERVAL, SCREEN};
|
||||||
use crate::adapters::display::Esp32DisplayAdapter;
|
use crate::adapters::display::Esp32DisplayAdapter;
|
||||||
use log::*;
|
use log::*;
|
||||||
|
|
||||||
|
const LINE_HEIGHT: u16 = 12;
|
||||||
|
const TEXT_PADDING: u16 = 4;
|
||||||
|
|
||||||
pub fn run(
|
pub fn run(
|
||||||
screen: BoundingBox,
|
screen: BoundingBox,
|
||||||
mut display: Esp32DisplayAdapter,
|
mut display: Esp32DisplayAdapter,
|
||||||
rx: mpsc::Receiver<ServerMessage>,
|
rx: mpsc::Receiver<ServerMessage>,
|
||||||
) {
|
) {
|
||||||
let mut app = ClientApp::new(screen);
|
let mut app = ClientApp::new(screen);
|
||||||
|
let mut first_update = true;
|
||||||
info!("Render loop started");
|
info!("Render loop started");
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match rx.recv_timeout(RENDER_POLL_INTERVAL) {
|
match rx.recv_timeout(RENDER_POLL_INTERVAL) {
|
||||||
Ok(msg) => {
|
Ok(msg) => {
|
||||||
let repaints = app.handle_message(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 {
|
for cmd in &repaints {
|
||||||
display.clear_region(cmd.bounds).unwrap();
|
display.clear_region(cmd.bounds).unwrap();
|
||||||
|
|
||||||
|
let mut y_offset = TEXT_PADDING;
|
||||||
for kv in &cmd.state.data {
|
for kv in &cmd.state.data {
|
||||||
if let protocol::WireValue::String(s) = &kv.value {
|
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(
|
display.draw_text(
|
||||||
&format!("{}: {s}", kv.key),
|
&format!("{}: {s}", kv.key),
|
||||||
cmd.bounds.x,
|
text_bounds.x,
|
||||||
cmd.bounds.y,
|
text_bounds.y,
|
||||||
cmd.bounds,
|
text_bounds,
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
y_offset += LINE_HEIGHT + 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !repaints.is_empty() {
|
if !repaints.is_empty() {
|
||||||
display.flush().unwrap();
|
display.flush().unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user