Theme: shape.wells, the shape of a colour well that stands on its own; SwatchPair draws round wells where the theme says so (Adwaita, Breeze, Soft)

This commit is contained in:
aiongg
2026-11-13 19:26:50 +00:00
parent 80fa53719e
commit b27d5d4eb5
15 changed files with 75 additions and 21 deletions
+13 -6
View File
@@ -1,7 +1,7 @@
//! [`SwatchPair`]: two overlapping colour wells, foreground over background or fill over stroke.
use craft_behavior::{EditEvents, Flow, HitLevel, HitPriority, Metrics, Mixed, NavShape, PartKey, PressPhase, Roving, Sense};
use craft_theme::Srgba;
use craft_theme::{Srgba, WellShape};
use craft_ui::buttons::IconButton;
use craft_ui::choice::{ChoiceWords, Swatch, SwatchMetrics, SwatchStyle};
use craft_ui::contract::{
@@ -100,7 +100,7 @@ pub struct SwatchPairStyle {
well: f32,
/// The offset of the secondary well from the primary one on both axes: `size.icon.sm`.
step: f32,
/// The corners of a well: the swatch's.
/// The corners of a well: the swatch's, or half the side where the theme's wells are round (`shape.wells`).
radius: CornerRadius,
/// The gap in the panel's colour round the front well: `space.gap.tight`.
gap: f32,
@@ -286,12 +286,17 @@ impl Component for SwatchPair<'_> {
fn style(cx: &StyleCx<'_>, _: SwatchPairStyleKey) -> SwatchPairStyle {
let colors = &cx.tokens.color;
let well = cx.tokens.size.icon.lg;
let radius = match cx.tokens.shape.wells {
WellShape::Round => UiTokens::corner(well / 2.0),
_ => SwatchMetrics::of(cx).radius,
};
SwatchPairStyle {
metrics: Metrics::new(),
focus: cx.focus_look(),
well: cx.tokens.size.icon.lg,
well,
step: cx.tokens.size.icon.sm,
radius: SwatchMetrics::of(cx).radius,
radius,
gap: cx.tokens.space.gap.tight,
buttons: cx.control().icon,
edge: cx.color(colors.line.control_edge),
@@ -495,8 +500,10 @@ fn paint_ring(draw: &Draw<'_>, at: Rect, color: Srgba, style: &SwatchPairStyle)
draw.stroke(&PaintShape::Rect(at, style.radius), StrokeWidth::Thin, contrast);
draw.stroke(&outline(at, style), StrokeWidth::Thin, style.edge);
let hole = at.shrink(band);
draw.stroke(&PaintShape::Rect(hole.expand(2.0 * line), CornerRadius::ZERO), StrokeWidth::Thin, contrast);
draw.stroke(&PaintShape::Rect(hole.expand(line), CornerRadius::ZERO), StrokeWidth::Thin, style.edge);
// The hole's corners are concentric with the well's: square for a square well, round for a round one.
let corner = |grow: f32| UiTokens::corner((f32::from(style.radius.nw) - band + grow).max(0.0));
draw.stroke(&PaintShape::Rect(hole.expand(2.0 * line), corner(2.0 * line)), StrokeWidth::Thin, contrast);
draw.stroke(&PaintShape::Rect(hole.expand(line), corner(line)), StrokeWidth::Thin, style.edge);
}
/// The outline just outside the well `at`, concentric with its corners.
+3 -2
View File
@@ -9,7 +9,7 @@ use crate::{
BarSizes, ColorToken, ControlSizes, DialogSizes, DockColumnSizes, Easing, Edge, Elevation, ElevationTokens, FloatSizes, FontSlot, Gaps,
HandleSizes, HitSizes, IconSizes, Insets, KnobShape, LengthSizes, Motion, MotionTokens, NoticeSizes, Pads, PaneSizes, PlotSizes, RadiusSet,
RailSizes, RampSizes, Rgba, RowSizes, RowStyle, RulerSizes, RulerTickSizes, ShapeTokens, SizeTokens, SpaceTokens, StorySizes, StrokeTokens,
ThumbSamples, ThumbSizes, Tokens, TypeStyle, TypeTokens, WindowSizes,
ThumbSamples, ThumbSizes, Tokens, TypeStyle, TypeTokens, WellShape, WindowSizes,
};
/// The text of every token, one `key = value` line each, in a fixed order.
@@ -66,7 +66,7 @@ fn edge(e: Edge) -> String {
}
fn shape_lines(out: &mut Lines, shape: &ShapeTokens) {
let ShapeTokens { radius, edge: e, rows, knob } = shape;
let ShapeTokens { radius, edge: e, rows, knob, wells } = shape;
let RadiusSet { sm, control, surface, window, panel, button, pill } = radius;
for (k, v) in [("sm", sm), ("control", control), ("surface", surface), ("window", window), ("panel", panel), ("button", button), ("pill", pill)] {
out.line(&format!("shape.radius.{k}"), len(*v));
@@ -74,6 +74,7 @@ fn shape_lines(out: &mut Lines, shape: &ShapeTokens) {
out.line("shape.edge", edge(*e));
out.line("shape.rows", if *rows == RowStyle::Divided { "divided" } else { "rounded" });
out.line("shape.knob", if *knob == KnobShape::Round { "round" } else { "tab" });
out.line("shape.wells", if *wells == WellShape::Square { "square" } else { "round" });
}
fn stroke_lines(out: &mut Lines, stroke: &StrokeTokens) {
+2
View File
@@ -40,6 +40,8 @@ const LENGTH: &str = "a length: a number of 0 or more, or \"full\"";
const OFFSET: &str = "a number";
const ROWS: &str = "\"divided\" or \"rounded\"";
const KNOB: &str = "\"round\" or \"tab\"";
/// What `shape.wells` takes.
const WELLS: &str = "\"square\" or \"round\"";
const EDGE: &str = "\"flat\" or {\"bevel\": {\"width\": n}} with n above 0";
/// A parsed theme file: the theme and the JSON it came from, so that [`fn@write`] keeps unknown keys.
+12 -2
View File
@@ -4,13 +4,13 @@ use std::collections::BTreeMap;
use serde_json::{Map, Value};
use super::{EDGE, ErrorKind, FormatError, FormatErrors, KNOB, LENGTH, MAX_THEME_BYTES, OFFSET, ROWS, SCHEMA, SCHEMA_VERSION, ThemeFile};
use super::{EDGE, ErrorKind, FormatError, FormatErrors, KNOB, LENGTH, MAX_THEME_BYTES, OFFSET, ROWS, SCHEMA, SCHEMA_VERSION, ThemeFile, WELLS};
use crate::color::Rgba;
use crate::scale::Radius;
use crate::theme::{
AppOverrides, ContrastIntent, EdgeSeed, ModePins, ModeSeeds, Pins, RadiusOffset, SeedOverrides, Seeds, ShapeSeed, ThemeDef, Variants,
};
use crate::tokens::{ColorToken, KnobShape, RadiusSet, RowStyle, Status};
use crate::tokens::{ColorToken, KnobShape, RadiusSet, RowStyle, Status, WellShape};
use crate::{AppId, ThemeId};
/// Parses and validates a theme file. Unknown keys are allowed anywhere except in colour maps, and
@@ -249,6 +249,15 @@ impl Parser {
None
}
});
let wells = p.at("wells", |p| match shape.get("wells") {
None | Some(Value::Null) => Some(None),
Some(Value::String(s)) if s == "square" => Some(Some(WellShape::Square)),
Some(Value::String(s)) if s == "round" => Some(Some(WellShape::Round)),
Some(_) => {
p.fail(ErrorKind::BadValue { expected: WELLS });
None
}
});
Some(Some(ShapeSeed {
radius: radius?,
radius_offset: radius_offset?,
@@ -256,6 +265,7 @@ impl Parser {
edge: edge?,
rows: rows?,
knob: knob?,
wells: wells?,
}))
})
}
+9 -1
View File
@@ -5,7 +5,7 @@ use serde_json::{Map, Number, Value};
use super::{FormatErrors, SCHEMA, SCHEMA_VERSION, ThemeFile};
use crate::scale::Radius;
use crate::theme::{AppOverrides, ContrastIntent, EdgeSeed, ModePins, ModeSeeds, Pins, ShapeSeed, ThemeDef, Variants};
use crate::tokens::{KnobShape, RowStyle};
use crate::tokens::{KnobShape, RowStyle, WellShape};
/// Top-level keys in the order a file lists them; other keys follow, sorted.
const TOP_ORDER: [&str; 13] =
@@ -131,6 +131,14 @@ fn update_shape(shape: &mut Map<String, Value>, s: &ShapeSeed) {
shape.insert("knob".to_owned(), Value::String(if k == KnobShape::Round { "round" } else { "tab" }.to_owned()));
}
}
match s.wells {
None => {
shape.remove("wells");
}
Some(w) => {
shape.insert("wells".to_owned(), Value::String(if w == WellShape::Square { "square" } else { "round" }.to_owned()));
}
}
}
fn update_app(app: &mut Map<String, Value>, o: &AppOverrides) {
+3 -1
View File
@@ -21,7 +21,7 @@ fn full() -> Value {
},
"shape": {
"radius": { "control": 3, "surface": 4, "window": 6, "panel": 0, "button": "full", "x_radius": 1 },
"edge": { "bevel": { "width": 1 } }, "knob": "tab", "x_shape": true
"edge": { "bevel": { "width": 1 } }, "knob": "tab", "wells": "round", "x_shape": true
},
"light": { "surface.panel": "#F0F0F0", "accent.solid": "#1062C4" },
"dark": { "surface.panel": "#535353" },
@@ -60,6 +60,7 @@ fn round_trip_keeps_values_and_unknown_keys() {
assert_eq!(shape.radius.unwrap().button, 999.0);
assert_eq!(shape.edge, Some(EdgeSeed::Bevel { width: 1.0 }));
assert_eq!(shape.knob, Some(KnobShape::Tab));
assert_eq!(shape.wells, Some(WellShape::Round));
assert_eq!(t.pins.light.get(T::SurfacePanel), Some(hex("#f0f0f0")));
assert_eq!(t.high_contrast.light.get(T::TextNormal), Some(hex("#000000")));
let photo = &t.apps[&AppId::parse("photocraft").unwrap()];
@@ -82,6 +83,7 @@ fn round_trip_keeps_values_and_unknown_keys() {
("/apps/x_app_entry", &orig["apps"]["x_app_entry"]),
("/version", &json!(3)),
("/shape/knob", &json!("tab")),
("/shape/wells", &json!("round")),
("/shape/radius/button", &json!("full")),
("/dark/surface.panel", &json!("#535353")),
] {
+1 -1
View File
@@ -96,7 +96,7 @@ pub use tokens::{
ElevationTokens, FloatSizes, FontSlot, Gaps, HandleSizes, HitSizes, IconSizes, Insets, KnobShape, LengthSizes, LineColors, Motion, MotionTokens,
NoticeSizes, OverlayColors, Pads, PaneSizes, PlotSizes, RadiusSet, RailSizes, RampSizes, RowSizes, RowStyle, RulerSizes, RulerTickSizes,
ShapeTokens, SizeTokens, SpaceTokens, StateColors, Status, StatusColors, StatusKind, StorySizes, StrokeTokens, SurfaceColors, TextColors,
ThumbSamples, ThumbSizes, Tokens, TypeRole, TypeStyle, TypeTokens, WindowSizes,
ThumbSamples, ThumbSizes, Tokens, TypeRole, TypeStyle, TypeTokens, WellShape, WindowSizes,
};
pub use values::ColorSource;
pub use variant::{CustomVariant, Emphasis, RadiusStep, Variant, VariantLook};
+7 -2
View File
@@ -200,8 +200,13 @@ fn resolve_concrete(theme: &ThemeDef, appearance: Appearance, app: Option<&AppId
let motion_ms = |millis: u32, easing: Easing| Motion { millis: if appearance.reduced_motion { 0 } else { millis }, easing };
let radius = RadiusSet { sm: (radius.control / 2.0).round(), ..radius };
let shape =
ShapeTokens { radius, edge, rows: seed.and_then(|s| s.rows).unwrap_or(preset.rows), knob: seed.and_then(|s| s.knob).unwrap_or_default() };
let shape = ShapeTokens {
radius,
edge,
rows: seed.and_then(|s| s.rows).unwrap_or(preset.rows),
knob: seed.and_then(|s| s.knob).unwrap_or_default(),
wells: seed.and_then(|s| s.wells).unwrap_or_default(),
};
let text_factor = sizes.text_steps.factor(appearance.text_size);
let typography = preset.typography.scaled(text_factor, values::TYPE_ROUNDING);
+3 -1
View File
@@ -4,7 +4,7 @@ use std::collections::BTreeMap;
use super::color::Rgba;
use super::ramp::Mode;
use super::tokens::{ColorToken, ColorTokens, Edge, KnobShape, RadiusSet, RowStyle, Status};
use super::tokens::{ColorToken, ColorTokens, Edge, KnobShape, RadiusSet, RowStyle, Status, WellShape};
use crate::{AppId, ThemeId};
/// A theme: seeds to derive from, values that override the derivation, and an optional shape.
@@ -190,6 +190,8 @@ pub struct ShapeSeed {
pub rows: Option<RowStyle>,
/// The knob shape; round when unset.
pub knob: Option<KnobShape>,
/// The shape of colour wells that stand on their own; square when unset.
pub wells: Option<WellShape>,
}
/// Per-tier additions to the corner radii, in logical pixels.
+13 -1
View File
@@ -72,7 +72,17 @@ pub enum KnobShape {
Tab,
}
/// Corner radii, edge style, row style and knob shape.
/// The shape of a colour well that stands on its own: the wells of a foreground and background pair.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum WellShape {
/// A square with the small corner radius.
#[default]
Square,
/// A circle.
Round,
}
/// Corner radii, edge style, row style, knob shape and well shape.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct ShapeTokens {
/// Corner radii.
@@ -83,6 +93,8 @@ pub struct ShapeTokens {
pub rows: RowStyle,
/// How the thumbs of value tracks are drawn.
pub knob: KnobShape,
/// How colour wells that stand on their own are drawn.
pub wells: WellShape,
}
/// Gaps between neighbouring elements, in logical pixels.
+2 -1
View File
@@ -25,7 +25,8 @@
"surface": 9.0,
"window": 12.0
},
"rows": "rounded"
"rows": "rounded",
"wells": "round"
},
"light": {
"accent.border": "#3584e482",
+2 -1
View File
@@ -25,7 +25,8 @@
"surface": 5.0,
"window": 5.0
},
"rows": "rounded"
"rows": "rounded",
"wells": "round"
},
"light": {
"accent.border": "#3aace8aa",
+2 -1
View File
@@ -23,7 +23,8 @@
"surface": 2.0,
"window": 2.0
},
"rows": "rounded"
"rows": "rounded",
"wells": "round"
},
"light": {
"accent.border": "#6e80d8aa",
+2
View File
@@ -970,6 +970,8 @@ A theme with its own shape replaces the radii or adds an offset to control, surf
`shape.knob` is the shape of a value track's thumb (Slider, RangeSlider): `round`, the control's glyph across, or `tab`, an upright tab the control's icon side tall. Classic sets `tab`.
`shape.wells` is the shape of a colour well that stands on its own (SwatchPair's foreground and background): `square`, with the small radius, or `round`, a circle. Adwaita, Breeze and Soft set `round`.
### Size roles
| Role | Components |
+1 -1
View File
@@ -56,7 +56,7 @@ the app's pins (`apps.<id>`), then the theme's high-contrast pins, then the app'
| `variants` | no | `"both"` (default), `"light"` or `"dark"` |
| `contrast_intent` | no | `"standard"` (default) or `"low"`: the theme is meant to be soft, and pickers label it "Low contrast" |
| `seeds` | yes | `neutral`, `accent` and `status.good/warn/bad/info`, all required |
| `shape` | no | `null`, or `{ "radius": { control, popup, window, panel, button, pill? }, "radius_offset": { control?, popup?, window? }, "edge": "flat" or {"bevel": {"width": 1}}, "rows": "divided" or "rounded", "knob": "round" or "tab" }`; `knob` is the shape of a value track's thumb (default `"round"`; Classic's `"tab"` is an upright tab); a radius is a number or `"full"`; `radius` needs the first five keys when present and fixes the radii at every Size; `radius_offset` (numbers, negative allowed, missing keys 0) is added to the control, popup and window radii in force, so the theme keeps its own shape at every Size (Soft: control +1, popup +2, window +2, which makes 7/10/14 at Comfortable and 4/6/8 at Compact); a "full" radius and `panel`, `button` and `pill` are not offset, and a sum below 0 is 0; `pill` (switch, slider, progress and badge shapes, clamped to half the part's height) defaults to `"full"`, and Classic sets it to 0 |
| `shape` | no | `null`, or `{ "radius": { control, popup, window, panel, button, pill? }, "radius_offset": { control?, popup?, window? }, "edge": "flat" or {"bevel": {"width": 1}}, "rows": "divided" or "rounded", "knob": "round" or "tab", "wells": "square" or "round" }`; `knob` is the shape of a value track's thumb (default `"round"`; Classic's `"tab"` is an upright tab); `wells` is the shape of a colour well that stands on its own, SwatchPair's (default `"square"`; Adwaita, Breeze and Soft are `"round"`); a radius is a number or `"full"`; `radius` needs the first five keys when present and fixes the radii at every Size; `radius_offset` (numbers, negative allowed, missing keys 0) is added to the control, popup and window radii in force, so the theme keeps its own shape at every Size (Soft: control +1, popup +2, window +2, which makes 7/10/14 at Comfortable and 4/6/8 at Compact); a "full" radius and `panel`, `button` and `pill` are not offset, and a sum below 0 is 0; `pill` (switch, slider, progress and badge shapes, clamped to half the part's height) defaults to `"full"`, and Classic sets it to 0 |
| `light`, `dark` | no | colour pins: dotted token path to `#RRGGBB`, `#RRGGBBAA` or a reference `"{token.path}"` (see References); surfaces (`surface.*` except `surface.scrim`) must be opaque. A `seeds` key holds that mode's seed overrides: `neutral`, `accent` and `status.good/warn/bad/info`, each optional; a field it names replaces the theme's `seeds` value in that mode and the rest fall through |
| `high_contrast` | no | `{ "light": {...}, "dark": {...} }`, pins used only in high contrast; no `seeds` key (it is an error there and in `apps`) |
| `apps` | no | per-app `{ light, dark, high_contrast }`, applied over the theme's values for that app; its `high_contrast` pins apply after the theme's |