theme config, layout preview, container alignment
Server: ThemeConfig entity + CRUD (GET/PUT /theme), SQLite persistence, ThemeUpdate broadcast to ESP32 on save and initial connect. Client: render engine uses theme colors, full-screen redraw on theme change. SPA: theme page with color pickers + presets, layout preview with TS port of layout engine, justify/align controls on containers. DisplayHint refactored to struct (kind + h_align + v_align).
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
use client_domain::{BoundingBox, LayoutEngine, RenderTree};
|
||||
use domain::{AlignItems, ContainerNode, Direction, JustifyContent, LayoutChild, LayoutNode, Sizing};
|
||||
use domain::{
|
||||
AlignItems, ContainerNode, Direction, JustifyContent, LayoutChild, LayoutNode, Sizing,
|
||||
};
|
||||
|
||||
fn screen() -> BoundingBox {
|
||||
BoundingBox::screen(240, 320)
|
||||
@@ -230,8 +232,14 @@ fn justify_center_centers_fixed_children_on_main_axis() {
|
||||
});
|
||||
let tree = LayoutEngine::compute(&layout, screen());
|
||||
|
||||
assert_eq!(tree.get_widget_bounds(1), Some(&BoundingBox::new(80, 0, 40, 320)));
|
||||
assert_eq!(tree.get_widget_bounds(2), Some(&BoundingBox::new(120, 0, 40, 320)));
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(1),
|
||||
Some(&BoundingBox::new(80, 0, 40, 320))
|
||||
);
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(2),
|
||||
Some(&BoundingBox::new(120, 0, 40, 320))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -247,7 +255,10 @@ fn justify_end_pushes_to_end() {
|
||||
});
|
||||
let tree = LayoutEngine::compute(&layout, screen());
|
||||
|
||||
assert_eq!(tree.get_widget_bounds(1), Some(&BoundingBox::new(200, 0, 40, 320)));
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(1),
|
||||
Some(&BoundingBox::new(200, 0, 40, 320))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -263,9 +274,18 @@ fn justify_space_between_distributes_gaps() {
|
||||
});
|
||||
let tree = LayoutEngine::compute(&layout, screen());
|
||||
|
||||
assert_eq!(tree.get_widget_bounds(1), Some(&BoundingBox::new(0, 0, 40, 320)));
|
||||
assert_eq!(tree.get_widget_bounds(2), Some(&BoundingBox::new(100, 0, 40, 320)));
|
||||
assert_eq!(tree.get_widget_bounds(3), Some(&BoundingBox::new(200, 0, 40, 320)));
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(1),
|
||||
Some(&BoundingBox::new(0, 0, 40, 320))
|
||||
);
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(2),
|
||||
Some(&BoundingBox::new(100, 0, 40, 320))
|
||||
);
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(3),
|
||||
Some(&BoundingBox::new(200, 0, 40, 320))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -282,8 +302,14 @@ fn justify_space_evenly_distributes_with_edges() {
|
||||
let tree = LayoutEngine::compute(&layout, screen());
|
||||
|
||||
// 160 / 3 = 53px per slot
|
||||
assert_eq!(tree.get_widget_bounds(1), Some(&BoundingBox::new(53, 0, 40, 320)));
|
||||
assert_eq!(tree.get_widget_bounds(2), Some(&BoundingBox::new(146, 0, 40, 320)));
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(1),
|
||||
Some(&BoundingBox::new(53, 0, 40, 320))
|
||||
);
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(2),
|
||||
Some(&BoundingBox::new(146, 0, 40, 320))
|
||||
);
|
||||
}
|
||||
|
||||
// --- AlignItems tests ---
|
||||
@@ -315,5 +341,8 @@ fn align_items_center_centers_on_cross_axis() {
|
||||
let tree = LayoutEngine::compute(&layout, screen());
|
||||
|
||||
// Stretch: child gets full cross-axis height
|
||||
assert_eq!(tree.get_widget_bounds(1), Some(&BoundingBox::new(0, 0, 40, 320)));
|
||||
assert_eq!(
|
||||
tree.get_widget_bounds(1),
|
||||
Some(&BoundingBox::new(0, 0, 40, 320))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,39 +7,73 @@ fn theme() -> ThemeConfig {
|
||||
#[test]
|
||||
fn plain_text_produces_single_span() {
|
||||
let spans = parse_markup("hello world", &theme());
|
||||
assert_eq!(spans, vec![
|
||||
TextSpan { text: "hello world".into(), color: theme().text },
|
||||
]);
|
||||
assert_eq!(
|
||||
spans,
|
||||
vec![TextSpan {
|
||||
text: "hello world".into(),
|
||||
color: theme().text
|
||||
},]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hex_color_span() {
|
||||
let spans = parse_markup("temp: {#FF0000}72°F{/}", &theme());
|
||||
assert_eq!(spans, vec![
|
||||
TextSpan { text: "temp: ".into(), color: theme().text },
|
||||
TextSpan { text: "72°F".into(), color: Color(0xFF, 0, 0) },
|
||||
]);
|
||||
assert_eq!(
|
||||
spans,
|
||||
vec![
|
||||
TextSpan {
|
||||
text: "temp: ".into(),
|
||||
color: theme().text
|
||||
},
|
||||
TextSpan {
|
||||
text: "72°F".into(),
|
||||
color: Color(0xFF, 0, 0)
|
||||
},
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn theme_color_spans() {
|
||||
let t = theme();
|
||||
let spans = parse_markup("{primary}hello{/} {accent}world{/}", &t);
|
||||
assert_eq!(spans, vec![
|
||||
TextSpan { text: "hello".into(), color: t.primary },
|
||||
TextSpan { text: " ".into(), color: t.text },
|
||||
TextSpan { text: "world".into(), color: t.accent },
|
||||
]);
|
||||
assert_eq!(
|
||||
spans,
|
||||
vec![
|
||||
TextSpan {
|
||||
text: "hello".into(),
|
||||
color: t.primary
|
||||
},
|
||||
TextSpan {
|
||||
text: " ".into(),
|
||||
color: t.text
|
||||
},
|
||||
TextSpan {
|
||||
text: "world".into(),
|
||||
color: t.accent
|
||||
},
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reset_returns_to_text_color() {
|
||||
let t = theme();
|
||||
let spans = parse_markup("{accent}hi{/}bye", &t);
|
||||
assert_eq!(spans, vec![
|
||||
TextSpan { text: "hi".into(), color: t.accent },
|
||||
TextSpan { text: "bye".into(), color: t.text },
|
||||
]);
|
||||
assert_eq!(
|
||||
spans,
|
||||
vec![
|
||||
TextSpan {
|
||||
text: "hi".into(),
|
||||
color: t.accent
|
||||
},
|
||||
TextSpan {
|
||||
text: "bye".into(),
|
||||
color: t.text
|
||||
},
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -52,16 +86,29 @@ fn empty_input_produces_no_spans() {
|
||||
fn adjacent_color_spans_no_text_between() {
|
||||
let t = theme();
|
||||
let spans = parse_markup("{primary}a{secondary}b{/}", &t);
|
||||
assert_eq!(spans, vec![
|
||||
TextSpan { text: "a".into(), color: t.primary },
|
||||
TextSpan { text: "b".into(), color: t.secondary },
|
||||
]);
|
||||
assert_eq!(
|
||||
spans,
|
||||
vec![
|
||||
TextSpan {
|
||||
text: "a".into(),
|
||||
color: t.primary
|
||||
},
|
||||
TextSpan {
|
||||
text: "b".into(),
|
||||
color: t.secondary
|
||||
},
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_tag_treated_as_literal() {
|
||||
let spans = parse_markup("{unknown}text", &theme());
|
||||
assert_eq!(spans, vec![
|
||||
TextSpan { text: "text".into(), color: theme().text },
|
||||
]);
|
||||
assert_eq!(
|
||||
spans,
|
||||
vec![TextSpan {
|
||||
text: "text".into(),
|
||||
color: theme().text
|
||||
},]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use client_domain::{
|
||||
BoundingBox, Color, DrawCommand, FontMetrics, FontSize, HAlign, RenderEngine,
|
||||
ThemeConfig, VAlign,
|
||||
BoundingBox, Color, DrawCommand, FontMetrics, FontSize, HAlign, RenderEngine, ThemeConfig,
|
||||
VAlign,
|
||||
};
|
||||
|
||||
fn metrics() -> FontMetrics {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use client_domain::{BoundingBox, LayoutEngine};
|
||||
use domain::{AlignItems, ContainerNode, Direction, JustifyContent, LayoutChild, LayoutNode, Sizing};
|
||||
use domain::{
|
||||
AlignItems, ContainerNode, Direction, JustifyContent, LayoutChild, LayoutNode, Sizing,
|
||||
};
|
||||
|
||||
fn screen() -> BoundingBox {
|
||||
BoundingBox::screen(240, 320)
|
||||
|
||||
Reference in New Issue
Block a user