add all crates: domain, protocol, application, client, adapters, ESP32 firmware

Server: domain (entities, value objects, ports), protocol (postcard wire types),
application (config service, data projection), adapters (config-memory, tcp-server),
bootstrap (composition root with fake data).

Client: client-domain (layout engine, render tree, HAL ports),
client-application (message handling, repaint commands),
adapters (tcp-client, display-terminal), client-desktop (end-to-end working).

ESP32: client-esp32 firmware with ILI9341 display over SPI, WiFi networking.
Display test verified on hardware — landscape orientation, text rendering works.

60 workspace tests, all passing.
This commit is contained in:
2026-06-18 21:43:59 +02:00
parent 6ad76b98a2
commit 557cceb498
83 changed files with 5844 additions and 1 deletions

View File

@@ -0,0 +1,17 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BoundingBox {
pub x: u16,
pub y: u16,
pub width: u16,
pub height: u16,
}
impl BoundingBox {
pub fn new(x: u16, y: u16, width: u16, height: u16) -> Self {
Self { x, y, width, height }
}
pub fn screen(width: u16, height: u16) -> Self {
Self { x: 0, y: 0, width, height }
}
}

View File

@@ -0,0 +1,96 @@
use std::collections::HashMap;
use domain::{LayoutNode, ContainerNode, Direction, Sizing};
use crate::{BoundingBox, RenderTree};
pub struct LayoutEngine;
impl LayoutEngine {
pub fn compute(layout: &LayoutNode, bounds: BoundingBox) -> RenderTree {
let mut widget_bounds = HashMap::new();
Self::compute_node(layout, bounds, &mut widget_bounds);
RenderTree { widget_bounds }
}
fn compute_node(
node: &LayoutNode,
bounds: BoundingBox,
out: &mut HashMap<u16, BoundingBox>,
) {
match node {
LayoutNode::Leaf(id) => {
out.insert(*id, bounds);
}
LayoutNode::Container(container) => {
Self::compute_container(container, bounds, out);
}
}
}
fn compute_container(
container: &ContainerNode,
bounds: BoundingBox,
out: &mut HashMap<u16, BoundingBox>,
) {
let inner = BoundingBox::new(
bounds.x + container.padding as u16,
bounds.y + container.padding as u16,
bounds.width.saturating_sub(container.padding as u16 * 2),
bounds.height.saturating_sub(container.padding as u16 * 2),
);
let children = &container.children;
if children.is_empty() {
return;
}
let is_row = container.direction == Direction::Row;
let total_axis = if is_row { inner.width } else { inner.height };
let total_gap = container.gap as u16 * (children.len() as u16).saturating_sub(1);
let available = total_axis.saturating_sub(total_gap);
let fixed_total: u16 = children.iter().map(|c| match c.sizing {
Sizing::Fixed(px) => px,
Sizing::Flex(_) => 0,
}).sum();
let flex_space = available.saturating_sub(fixed_total);
let flex_total: u16 = children.iter().map(|c| match c.sizing {
Sizing::Flex(w) => w as u16,
Sizing::Fixed(_) => 0,
}).sum();
let mut offset = 0u16;
for child in children {
let child_size = match child.sizing {
Sizing::Fixed(px) => px,
Sizing::Flex(w) => {
if flex_total > 0 {
(flex_space as u32 * w as u32 / flex_total as u32) as u16
} else {
0
}
}
};
let child_bounds = if is_row {
BoundingBox::new(
inner.x + offset,
inner.y,
child_size,
inner.height,
)
} else {
BoundingBox::new(
inner.x,
inner.y + offset,
inner.width,
child_size,
)
};
Self::compute_node(&child.node, child_bounds, out);
offset += child_size + container.gap as u16;
}
}
}

View File

@@ -0,0 +1,9 @@
mod bounding_box;
mod layout_engine;
mod render_tree;
pub mod ports;
pub use bounding_box::BoundingBox;
pub use layout_engine::LayoutEngine;
pub use render_tree::RenderTree;
pub use ports::{DisplayPort, NetworkPort, StoragePort, ClientConfig};

View File

@@ -0,0 +1,11 @@
use crate::BoundingBox;
pub trait DisplayPort {
type Error;
fn clear_region(&mut self, bounds: BoundingBox) -> Result<(), Self::Error>;
fn draw_text(&mut self, text: &str, x: u16, y: u16, bounds: BoundingBox) -> Result<(), Self::Error>;
fn draw_icon(&mut self, icon: &str, x: u16, y: u16) -> Result<(), Self::Error>;
fn fill_background(&mut self, bounds: BoundingBox) -> Result<(), Self::Error>;
fn flush(&mut self) -> Result<(), Self::Error>;
}

View File

@@ -0,0 +1,7 @@
mod display;
mod network;
mod storage;
pub use display::DisplayPort;
pub use network::NetworkPort;
pub use storage::{StoragePort, ClientConfig};

View File

@@ -0,0 +1,9 @@
pub trait NetworkPort {
type Error;
fn connect(&mut self, addr: &str) -> Result<(), Self::Error>;
fn disconnect(&mut self) -> Result<(), Self::Error>;
fn send(&mut self, data: &[u8]) -> Result<(), Self::Error>;
fn receive(&mut self) -> Result<Option<Vec<u8>>, Self::Error>;
fn is_connected(&self) -> bool;
}

View File

@@ -0,0 +1,11 @@
pub struct ClientConfig {
pub wifi_ssid: String,
pub wifi_password: String,
pub server_addr: String,
}
pub trait StoragePort {
type Error;
fn load_config(&self) -> Result<ClientConfig, Self::Error>;
}

View File

@@ -0,0 +1,29 @@
use std::collections::HashMap;
use domain::WidgetId;
use crate::BoundingBox;
pub struct RenderTree {
pub widget_bounds: HashMap<WidgetId, BoundingBox>,
}
impl RenderTree {
pub fn get_widget_bounds(&self, id: WidgetId) -> Option<&BoundingBox> {
self.widget_bounds.get(&id)
}
pub fn diff(&self, other: &RenderTree) -> Vec<WidgetId> {
let mut changed = Vec::new();
for (id, bounds) in &self.widget_bounds {
match other.widget_bounds.get(id) {
Some(prev) if prev == bounds => {}
_ => changed.push(*id),
}
}
for id in other.widget_bounds.keys() {
if !self.widget_bounds.contains_key(id) {
changed.push(*id);
}
}
changed
}
}