look-rest-4: a theme's app layer can carry its own shape, which replaces the theme's for that app (parsed, checked, written, resolved); WordCraft's buttons are 4 pt rounded rectangles under ArtCraft, as WordCraft's were, not capsules; test

This commit is contained in:
Martin Ball
2026-11-19 14:47:44 +00:00
parent 171eea0cd1
commit b3e1c96a5b
7 changed files with 43 additions and 4 deletions
+4 -3
View File
@@ -456,9 +456,10 @@ impl Parser {
Some(hc) => p.at("high_contrast", |p| p.mode_pins(hc, variants, false)),
None => Some(ModePins::default()),
};
match (pins, high_contrast) {
(Some(pins), Some(high_contrast)) => {
out.insert(id, AppOverrides { pins, high_contrast });
let shape = p.shape(app);
match (pins, high_contrast, shape) {
(Some(pins), Some(high_contrast), Some(shape)) => {
out.insert(id, AppOverrides { pins, high_contrast, shape });
true
}
_ => false,
+3
View File
@@ -31,6 +31,9 @@ impl ThemeDef {
c.at(id.as_str(), |c| {
c.mode_pins(&app.pins, self.variants);
c.at("high_contrast", |c| c.mode_pins(&app.high_contrast, self.variants));
if let Some(shape) = &app.shape {
c.at("shape", |c| c.shape(shape));
}
});
}
});
+7
View File
@@ -136,6 +136,13 @@ fn update_shape(shape: &mut Map<String, Value>, s: &ShapeSeed) {
fn update_app(app: &mut Map<String, Value>, o: &AppOverrides) {
mode_maps(app, &o.pins);
section(app, "high_contrast", |hc| mode_maps(hc, &o.high_contrast));
// An app without its own shape writes none: the theme's applies.
match &o.shape {
None => {
app.remove("shape");
}
Some(shape) => with_object(app, "shape", |s| update_shape(s, shape)),
}
}
/// Writes each mode's seed overrides as `seeds` inside its pin map, after `mode_maps`.
+21
View File
@@ -95,6 +95,27 @@ fn round_trip_keeps_values_and_unknown_keys() {
assert_eq!(format::write(&again).unwrap(), text, "writing is stable");
}
/// An app's own `shape` replaces the theme's for that app only (WordCraft's rounded-rectangle buttons under
/// ArtCraft's capsules), and it is written back.
#[test]
fn an_apps_own_shape_replaces_the_themes_for_that_app() {
let mut v = full();
v["apps"]["photocraft"]["shape"] = json!({ "button_radius": 4 });
let file = parse_value(&v).unwrap();
let id = AppId::parse("photocraft").unwrap();
assert_eq!(file.theme.apps.get(&id).and_then(|app| app.shape).and_then(|shape| shape.button_radius), Some(4.0));
let appearance = super::semantic_tests::app(Mode::Light, Contrast::Standard);
let own = crate::resolve(&file.theme, appearance, Some(&id)).tokens.shape.radius.button;
let theirs = crate::resolve(&file.theme, appearance, None).tokens.shape.radius.button;
assert_eq!(own, 4.0, "the app's buttons take its own radius");
assert_ne!(theirs, 4.0, "other apps keep the theme's");
let written: Value = serde_json::from_str(&format::write(&file).unwrap()).unwrap();
assert_eq!(written.pointer("/apps/photocraft/shape/button_radius"), Some(&json!(4.0)));
let mut bad = full();
bad["apps"]["photocraft"]["shape"] = json!({ "button_radius": -1 });
assert!(!errors(&bad).is_empty(), "an app's shape is checked as a theme's");
}
/// A theme file with the given light-mode pins.
fn with_light(pins: Value) -> Value {
let mut v = full();
+2 -1
View File
@@ -180,7 +180,8 @@ fn resolve_concrete(theme: &ThemeDef, appearance: Appearance, app: Option<&AppId
let mut preset = set.base;
sizes.apply_base(appearance.size, &mut preset);
let seed = theme.shape;
// An app's own shape replaces the theme's for that app.
let seed = app.and_then(|id| theme.apps.get(id)).and_then(|own| own.shape).or(theme.shape);
let radius = seed.and_then(|s| s.radius).unwrap_or(preset.radius);
let radius = seed.and_then(|s| s.radius_offset).map_or(radius, |o| o.apply(radius));
let radius = RadiusSet { button: seed.and_then(|s| s.button_radius).unwrap_or(radius.button), ..radius };
+3
View File
@@ -43,6 +43,9 @@ pub struct AppOverrides {
pub pins: ModePins,
/// Fixed colours per mode used only with [`Contrast::High`].
pub high_contrast: ModePins,
/// The app's own shape, in place of the theme's `shape` for that app (an app whose buttons are rounded
/// rectangles under a theme of capsules). `None` keeps the theme's.
pub shape: Option<ShapeSeed>,
}
impl ThemeDef {
+3
View File
@@ -62,6 +62,9 @@
},
"apps": {
"wordcraft": {
"shape": {
"button_radius": 4
},
"light": {
"accent.soft": "#dde3f8",
"accent.solid": "#3b5bdb",