Skip to main content

teksilo_theme_macos/
lib.rs

1// SPDX-License-Identifier: MPL-2.0
2// SPDX-FileCopyrightText: 2026 FernTech
3
4//! macOS (Aqua / Dark Aqua) theme preset for Teksilo.
5//!
6//! A full macOS theme: the AppKit semantic-colour palette, the two
7//! measured radii, the published San Francisco type ramp with its signed
8//! tracking, Core Animation's default duration and curve, and Tier-3
9//! chrome for the widgets whose AppKit counterpart is structurally its own
10//! thing.
11//!
12//! ```ignore
13//! use teksilo_theme_macos as macos;
14//!
15//! TeksiloAppBuilder::new()
16//!     .theme(macos::light())
17//!     .initial_window(WindowConfig::new().title("macOS demo"))
18//!     .run();
19//! ```
20//!
21//! ## What makes it read as macOS
22//!
23//! - **The focus ring is the accent.** Not a neutral high-contrast outline
24//!   (Fluent) and not a thickened border (Material 3) — the user's own
25//!   accent colour, as a soft halo hugging the control's outline. See
26//!   [`shape`] for how the halo is built so it still clears WCAG 1.4.11.
27//! - **Controls are physical objects.** A push button, a popup button, a
28//!   switch knob and a slider knob all share one bezel: a faint top-to-
29//!   bottom gradient, a hairline, and a shadow that separates it from the
30//!   surface underneath. Big Sur flattened Aqua's gloss but kept all
31//!   three, and it is what stops a macOS control reading as a coloured
32//!   rectangle.
33//! - **Selection is a capsule, and its label turns white.** A selected
34//!   list row is an accent-filled rounded capsule inset from the row's
35//!   edges, with `alternateSelectedControlTextColor` on top. Menus do the
36//!   same. This is the most recognisable single element of a macOS list.
37//! - **Signed tracking.** Small text is loosened, larger text tightened,
38//!   crossing zero at 12 pt — the only Teksilo preset that tracks
39//!   non-uniformly, and a published Apple table rather than a guess.
40//! - **Denser than Fluent.** A 22 dp control height against Windows 11's
41//!   32, and a 13 pt body against 14. macOS fits more in the same window.
42//! - **Symmetric motion.** `ease-in-ease-out` rather than Fluent's
43//!   decelerate-only curve: things start gently and stop gently.
44//!
45//! ## Accent colour
46//!
47//! `controlAccentColor` is whatever the user picked in System Settings.
48//! [`light`] and [`dark`] resolve it against the out-of-box `systemBlue`;
49//! [`light_with_accent`] / [`dark_with_accent`] rebuild the whole theme
50//! around a different seed, and [`SystemAccent`] carries the eight
51//! swatches macOS itself offers:
52//!
53//! ```ignore
54//! use teksilo_theme_macos::{self as macos, SystemAccent};
55//! let theme = macos::light_with_accent(SystemAccent::Purple.light());
56//! ```
57//!
58//! Note that `linkColor` deliberately does **not** follow: AppKit keeps
59//! links a fixed blue whatever accent is chosen, and so does this preset.
60//!
61//! ## Known limitations
62//!
63//! - **The OS accent is not read.** Teksilo's platform layer returns only
64//!   the light/dark preference on macOS — `query_os_theme_colors` fills in
65//!   the colour scheme and nothing else — so there is no live
66//!   `NSColor.controlAccentColor` to bind to. The preset ships the stock
67//!   blue and an app that wants the user's real accent passes it to
68//!   [`light_with_accent`] itself. Wiring the AppKit read is a
69//!   platform-layer change, not a theme one.
70//! - **Vibrancy is its opaque fallback.** Sidebars, menus, popovers and
71//!   title bars are `NSVisualEffectView` materials that sample and blur
72//!   what is *behind the window*; Teksilo's wgpu surface exposes no
73//!   compositor-side blur, so every such surface uses the opaque colour
74//!   the material falls back to — which is what macOS itself shows with
75//!   "Reduce transparency" on, not an invention. (Teksilo's `Blur`
76//!   primitive can blur content *within* a window, so a popover over the
77//!   app's own content is expressible; sampling the desktop wallpaper is
78//!   not.)
79//! - **The table selection band is a wash, not a capsule.** `ListView` and
80//!   `TreeView` rows get the authentic solid-accent capsule with a white
81//!   label, because [`styles::standard_item`] owns both halves.
82//!   `TableView` / `TreeTableView` / `GridView` paint the shared
83//!   `surface_selected` token behind *app-supplied* cell widgets whose
84//!   text this preset cannot retint, so that token is the accent as a wash
85//!   the primary label still clears 4.5:1 on. Fluent makes the same split
86//!   for the same reason.
87//! - **Several literals are snapshots.** Apple's own standing disclaimer
88//!   is that published colour values "will fluctuate from release to
89//!   release"; control heights, corner radii, focus-ring geometry and
90//!   every animation duration but one are not published at all. Each value
91//!   in this crate is tagged `[HIG]`, `[measured]` or `[derived]` at its
92//!   definition, and the handful that deviate from Apple's own numbers to
93//!   meet WCAG are called out with the measurement that forced the change.
94//! - **Window activation is two-state, AppKit's is three.** Teksilo
95//!   models a window as active or not; AppKit distinguishes Main, Key and
96//!   Inactive (a document window stays Main while its sheet is Key). The
97//!   accent desaturation this preset inherits fires on the Teksilo
98//!   boundary, which matches AppKit for every case except that one.
99//! - **Widget chrome is chosen at build time.** Switching between macOS
100//!   and another preset at runtime re-tints instantly but keeps the shapes
101//!   the tree was built with — a property of the styling system, not of
102//!   this preset.
103
104mod color;
105pub mod motion;
106pub mod palette;
107pub mod shape;
108pub mod styles;
109pub mod typography;
110
111pub use palette::{MacOsAccentRamp, MacOsBezel, MacOsPalette, SystemAccent};
112
113use std::rc::Rc;
114
115use teksilo_core::presets::intui;
116use teksilo_core::styles::{Theme, ThemeAppearance};
117use teksilo_tokens::{Color, InputTokens, TargetDensity};
118
119/// macOS **Aqua** (light), on the stock `systemBlue` accent.
120pub fn light() -> Theme {
121    build(ThemeAppearance::Light, MacOsPalette::light())
122}
123
124/// macOS **Dark Aqua**, on the stock `systemBlue` accent.
125pub fn dark() -> Theme {
126    build(ThemeAppearance::Dark, MacOsPalette::dark())
127}
128
129/// Aqua rebuilt around `accent` — the substitution macOS performs when the
130/// user picks an accent colour in System Settings.
131///
132/// ```ignore
133/// use teksilo_theme_macos::{self as macos, SystemAccent};
134/// let theme = macos::light_with_accent(SystemAccent::Green.light());
135/// ```
136pub fn light_with_accent(accent: Color) -> Theme {
137    build(
138        ThemeAppearance::Light,
139        MacOsPalette::light_with_accent(light_ramp_for(accent)),
140    )
141}
142
143/// Dark Aqua rebuilt around `accent`.
144pub fn dark_with_accent(accent: Color) -> Theme {
145    build(
146        ThemeAppearance::Dark,
147        MacOsPalette::dark_with_accent(dark_ramp_for(accent)),
148    )
149}
150
151/// The measured ramp when the seed *is* the stock accent, the derivation
152/// otherwise — so `light_with_accent(SystemAccent::Blue.light())` and
153/// [`light`] agree exactly.
154fn light_ramp_for(accent: Color) -> MacOsAccentRamp {
155    let default = MacOsAccentRamp::system_blue_light();
156    if accent == default.base {
157        default
158    } else {
159        MacOsAccentRamp::light_from_base(accent)
160    }
161}
162
163fn dark_ramp_for(accent: Color) -> MacOsAccentRamp {
164    let default = MacOsAccentRamp::system_blue_dark();
165    if accent == default.base {
166        default
167    } else {
168        MacOsAccentRamp::dark_from_base(accent)
169    }
170}
171
172fn build(appearance: ThemeAppearance, palette: MacOsPalette) -> Theme {
173    let light = appearance == ThemeAppearance::Light;
174    // Starting from the IntUI baseline keeps every token macOS has no
175    // opinion about (the chart palette, the find-match highlight) at a
176    // sensible value instead of at zero.
177    let mut theme = if light {
178        intui::light().with_id("macos.light")
179    } else {
180        intui::dark().with_id("macos.dark")
181    };
182
183    theme.colors = if light {
184        color::macos_light_colors(&palette)
185    } else {
186        color::macos_dark_colors(&palette)
187    };
188    theme.shape = if light {
189        shape::macos_light_shape()
190    } else {
191        shape::macos_dark_shape()
192    };
193    theme.typography = typography::macos_typography();
194    theme.motion = motion::macos_motion();
195    theme.extensions.insert(palette);
196
197    install_styles(&mut theme);
198    theme
199        .extensions
200        .insert(teksilo_core::styles::DensityProjection(reproject));
201    theme
202}
203
204/// Re-derive a macOS theme for another density.
205///
206/// Registered as the theme's [`DensityProjection`](teksilo_core::styles::DensityProjection), so
207/// `WidgetTree::set_input_density` (and `Theme::with_density`) rebuild the
208/// Tier-3 slots this preset installs instead of carrying their Compact
209/// dimensions across. Colours, id, the [`MacOsPalette`] extension and any slot
210/// the app installed itself ride across untouched.
211///
212/// `[unpublished]` — Apple states no touch ladder at all (macOS has no
213/// touchscreen), so this uses the generic [`InputTokens::for_density`] ladder.
214/// The `[measured]` 22 dp control height stays at Apple's number in the paint
215/// at every density; what rises is the minimum *hit box* around it.
216fn reproject(base: &Theme, density: TargetDensity) -> Theme {
217    let mut theme = base.clone();
218    theme.input = InputTokens::for_density(density);
219    install_styles(&mut theme);
220    theme
221}
222
223/// Install the macOS Tier-3 chrome. Every style resolves its colours from
224/// the live theme at paint time, so one install serves both appearances —
225/// and a custom-accent theme too.
226fn install_styles(theme: &mut Theme) {
227    // Every metric below comes from `theme.input`, so `reproject` can re-run
228    // this alone to move the whole preset to another density.
229    let tokens = theme.input;
230    let slots = &mut theme.style_slots;
231
232    // Structurally macOS — see `styles`.
233    slots.button = Some(Rc::new(styles::button::MacOsButtonStyle));
234    slots.toggle = Some(Rc::new(styles::toggle::MacOsToggleStyle));
235    slots.checkbox = Some(Rc::new(styles::checkbox::MacOsCheckboxStyle));
236    slots.radio = Some(Rc::new(styles::radio::MacOsRadioStyle));
237    slots.text_input = Some(Rc::new(styles::text_input::MacOsTextInputStyle));
238    slots.slider = Some(Rc::new(styles::slider::MacOsSliderStyle));
239    slots.menu_item = Some(Rc::new(styles::menu_item::MacOsMenuItemStyle::for_tokens(
240        &tokens,
241    )));
242    slots.standard_item = Some(Rc::new(styles::standard_item::MacOsStandardItemStyle));
243
244    // macOS metrics over the shipped composition.
245    slots.card = Some(Rc::new(styles::metrics::MacOsCardStyle));
246    slots.panel = Some(Rc::new(styles::metrics::macos_panel_style_for(&tokens)));
247    slots.popover = Some(Rc::new(styles::metrics::macos_popover_style_for(&tokens)));
248    slots.tooltip = Some(Rc::new(styles::metrics::macos_tooltip_style_for(&tokens)));
249    slots.dialog = Some(Rc::new(styles::metrics::macos_dialog_style_for(&tokens)));
250    slots.snackbar = Some(Rc::new(styles::metrics::macos_snackbar_style_for(&tokens)));
251    slots.toast = Some(Rc::new(styles::metrics::macos_toast_style_for(&tokens)));
252    slots.banner = Some(Rc::new(styles::metrics::macos_banner_style_for(&tokens)));
253    slots.combo_box = Some(Rc::new(styles::metrics::macos_combo_box_style_for(&tokens)));
254    slots.icon_button = Some(Rc::new(styles::metrics::macos_icon_button_style_for(
255        &tokens,
256    )));
257    slots.link = Some(Rc::new(styles::metrics::macos_link_style_for(&tokens)));
258    slots.segmented_control = Some(Rc::new(styles::metrics::macos_segmented_control_style_for(
259        &tokens,
260    )));
261    slots.badge = Some(Rc::new(styles::metrics::macos_badge_style_for(&tokens)));
262    slots.progress_bar = Some(Rc::new(styles::metrics::macos_progress_bar_style_for(
263        &tokens,
264    )));
265    slots.scroll_bar = Some(Rc::new(styles::metrics::macos_scroll_bar_style_for(
266        &tokens,
267    )));
268    slots.tab = Some(Rc::new(styles::metrics::macos_tab_style_for(&tokens)));
269    slots.table = Some(Rc::new(styles::metrics::macos_table_style_for(&tokens)));
270    slots.calendar = Some(Rc::new(styles::metrics::macos_calendar_style_for(&tokens)));
271    slots.search_field = Some(Rc::new(styles::metrics::macos_search_field_style_for(
272        &tokens,
273    )));
274    slots.avatar = Some(Rc::new(styles::metrics::macos_avatar_style_for(&tokens)));
275}
276
277#[cfg(test)]
278mod tests {
279    use super::*;
280    use crate::palette::hex;
281    use std::collections::BTreeSet;
282    use teksilo_core::styles::ComponentStyleSlots;
283
284    #[test]
285    fn light_reports_light_appearance() {
286        assert_eq!(light().appearance, ThemeAppearance::Light);
287        assert!(!light().is_dark());
288    }
289
290    #[test]
291    fn dark_reports_dark_appearance() {
292        assert_eq!(dark().appearance, ThemeAppearance::Dark);
293        assert!(dark().is_dark());
294    }
295
296    #[test]
297    fn ids_are_namespaced() {
298        assert_eq!(light().id.as_str(), "macos.light");
299        assert_eq!(dark().id.as_str(), "macos.dark");
300        // The widget-catalog persists and restores themes by this id, so
301        // a rename here silently breaks restore-on-launch.
302        assert_eq!(light_with_accent(Color::WHITE).id.as_str(), "macos.light");
303        assert_eq!(dark_with_accent(Color::WHITE).id.as_str(), "macos.dark");
304    }
305
306    #[test]
307    fn surfaces_are_the_appkit_window_backgrounds() {
308        assert_eq!(light().colors.surface_main, hex("#ECECEC"));
309        assert_eq!(dark().colors.surface_main, hex("#323232"));
310        assert_ne!(light().colors.surface_main, dark().colors.surface_main);
311    }
312
313    #[test]
314    fn the_accent_is_the_selection_shade_not_the_raw_control_accent() {
315        // The distinction the whole `MacOsAccentRamp` exists for.
316        assert_eq!(light().colors.accent, hex("#0063E1"));
317        assert_eq!(dark().colors.accent, hex("#0058D0"));
318        assert_eq!(light().colors.focus_ring, SystemAccent::Blue.light());
319        assert_eq!(dark().colors.focus_ring, SystemAccent::Blue.dark());
320        assert_eq!(light().colors.text_on_accent, Color::WHITE);
321        assert_eq!(dark().colors.text_on_accent, Color::WHITE);
322    }
323
324    /// The single clearest way this preset differs from Fluent.
325    #[test]
326    fn the_focus_indicator_is_the_accent_unlike_fluent() {
327        for t in [light(), dark()] {
328            assert_eq!(t.colors.focus_ring, t.colors.border_focused);
329            // Fluent asserts the opposite: that its ring is *not* the
330            // accent. macOS asserts that it comes from the same family.
331            assert_eq!(
332                t.colors.focus_ring,
333                t.extension::<MacOsPalette>().unwrap().accent_ramp.base
334            );
335        }
336    }
337
338    #[test]
339    fn geometry_is_the_two_measured_radii() {
340        for t in [light(), dark()] {
341            assert_eq!(t.shape.radius_control, 6.0);
342            assert_eq!(t.shape.radius_popup, 10.0);
343            assert_eq!(t.shape.focus_ring_offset, 0.0);
344        }
345    }
346
347    #[test]
348    fn body_is_the_published_macos_ramp_with_signed_tracking() {
349        let t = light();
350        assert!((t.typography.body.size - 13.0).abs() < 0.01);
351        assert!(t.typography.body.letter_spacing < 0.0);
352        assert_eq!(t.typography.small.letter_spacing, 0.0);
353        assert!(t.typography.tiny.letter_spacing > 0.0);
354    }
355
356    #[test]
357    fn motion_uses_the_core_animation_default() {
358        use std::time::Duration;
359        for t in [light(), dark()] {
360            assert_eq!(t.motion.duration_normal, Duration::from_millis(250));
361        }
362    }
363
364    #[test]
365    fn palette_extension_present_and_appearance_matched() {
366        let l = light().extension::<MacOsPalette>().copied().unwrap();
367        let d = dark().extension::<MacOsPalette>().copied().unwrap();
368        // The extension carries tokens `ColorTokens` has no slot for.
369        assert_eq!(l.window_background, hex("#ECECEC"));
370        assert_eq!(d.window_background, hex("#323232"));
371        assert!(l.bezel.inner_light.a() == 0.0);
372        assert!(d.bezel.inner_light.a() > 0.0);
373    }
374
375    /// The slots macOS deliberately leaves to the widget's default
376    /// `Recipe*Style`, each with the reason it is inherited rather than filled.
377    const MACOS_UNFILLED: &[(&str, &str)] = &[
378        (
379            "split_button",
380            "no AppKit split-button bezel is transcribed; the recipe frame paints from the theme surface and border roles",
381        ),
382        (
383            "splitter",
384            "the recipe's thin resting divider in the theme border role already reads as a split-view divider",
385        ),
386        (
387            "radio_tile",
388            "AppKit has no selectable card; the recipe surface reads the preset's surface and accent roles",
389        ),
390        (
391            "chart",
392            "AppKit has no chart chrome; the teksilo-charts default reads the series colours and the theme border role",
393        ),
394        (
395            "color_picker",
396            "NSColorPanel is a system panel with no in-window chrome to transcribe; the recipe reads the theme roles",
397        ),
398        (
399            "spin_box",
400            "no NSStepper chrome is transcribed; the recipe frames the widget's field and step buttons in theme roles",
401        ),
402        (
403            "date_edit",
404            "the recipe is a passthrough around the TextInput, which the text_input slot already styles",
405        ),
406        (
407            "rich_text_editor",
408            "the recipe frames the viewport in theme border and surface roles; the text is document content",
409        ),
410        (
411            "list_container",
412            "the recipe is only the drag-insertion line, drawn in the accent role this preset maps",
413        ),
414        (
415            "drop_zone",
416            "AppKit has no drop-zone control; the recipe tints its region from the theme roles",
417        ),
418        (
419            "drop_target",
420            "AppKit has no drop-target control; the recipe border reads the theme roles and its hints are cards, which the card slot styles",
421        ),
422        (
423            "grid_view",
424            "the recipe's focus ring, marquee and insertion bar use the focused and accent roles this preset maps",
425        ),
426        (
427            "web_view",
428            "the page paints itself; the recipe only tints the overlay shown over it, from theme roles",
429        ),
430        (
431            "text_selection",
432            "touch chrome on a platform without touch; its geometry is teksilo_core::text_touch's, shared with hit testing",
433        ),
434    ];
435
436    /// Whether the installed slots and [`MACOS_UNFILLED`] are exactly
437    /// [`ComponentStyleSlots::NAMES`], with no slot in both: a slot added to the
438    /// framework must be either filled by this preset or listed with a reason.
439    #[test]
440    fn installed_and_unfilled_slots_partition_the_roster() {
441        let unfilled: BTreeSet<&str> = MACOS_UNFILLED.iter().map(|(name, _)| *name).collect();
442        assert_eq!(
443            unfilled.len(),
444            MACOS_UNFILLED.len(),
445            "a slot is listed twice"
446        );
447        for (name, reason) in MACOS_UNFILLED {
448            assert!(
449                !reason.trim().is_empty(),
450                "{name} is listed without a reason"
451            );
452        }
453        let names: BTreeSet<&str> = ComponentStyleSlots::NAMES.iter().copied().collect();
454        for t in [light(), dark(), light().with_density(TargetDensity::Touch)] {
455            let installed: BTreeSet<&str> = t.style_slots.installed().into_iter().collect();
456            let both: Vec<_> = installed.intersection(&unfilled).collect();
457            assert!(
458                both.is_empty(),
459                "installed yet listed as unfilled: {both:?}"
460            );
461            let covered: BTreeSet<&str> = installed.union(&unfilled).copied().collect();
462            let missing: Vec<_> = names.difference(&covered).collect();
463            let unknown: Vec<_> = covered.difference(&names).collect();
464            assert!(
465                missing.is_empty() && unknown.is_empty(),
466                "neither installed nor listed: {missing:?}; not a slot: {unknown:?}"
467            );
468        }
469    }
470
471    #[test]
472    fn custom_accent_rebuilds_the_whole_accent_family() {
473        let seed = SystemAccent::Purple.light();
474        let t = light_with_accent(seed);
475        let base = light();
476        assert_ne!(t.colors.accent, base.colors.accent);
477        assert_ne!(t.colors.focus_ring, base.colors.focus_ring);
478        assert_ne!(
479            t.colors.selection_bg_active,
480            base.colors.selection_bg_active
481        );
482        // Neutral tokens are untouched — only the accent family moves…
483        assert_eq!(t.colors.surface_main, base.colors.surface_main);
484        assert_eq!(t.colors.text_primary, base.colors.text_primary);
485        // …and `linkColor` is not part of it, on macOS.
486        assert_eq!(t.colors.text_link, base.colors.text_link);
487        // …and the extension follows, so widget chrome sees it too.
488        let p = t.extension::<MacOsPalette>().copied().unwrap();
489        assert_eq!(p.accent_ramp.base, seed);
490    }
491
492    #[test]
493    fn passing_the_default_accent_reproduces_the_measured_ramp() {
494        assert_eq!(
495            light_with_accent(SystemAccent::Blue.light()).colors.accent,
496            light().colors.accent
497        );
498        assert_eq!(
499            dark_with_accent(SystemAccent::Blue.dark()).colors.accent,
500            dark().colors.accent
501        );
502    }
503
504    #[test]
505    fn every_system_accent_builds_a_usable_theme() {
506        for accent in SystemAccent::ALL {
507            for t in [
508                light_with_accent(accent.light()),
509                dark_with_accent(accent.dark()),
510            ] {
511                let c = &t.colors;
512                assert!(
513                    crate::palette::over(c.text_on_accent, c.accent).contrast_ratio(c.accent)
514                        >= 4.5,
515                    "{accent:?}: an accent-filled label is unreadable"
516                );
517                // …and the chrome is installed whichever accent was used.
518                assert!(t.style_slots.button.is_some());
519            }
520        }
521    }
522
523    #[test]
524    fn the_theme_survives_the_window_inactive_projection() {
525        // The paint walker swaps this palette in on focus loss — the
526        // convention macOS itself originated. A preset that left `accent`
527        // unmapped would produce a no-op here.
528        for t in [light(), dark()] {
529            let inactive = t.for_inactive_window();
530            assert_ne!(inactive.colors.accent, t.colors.accent);
531            assert_ne!(inactive.colors.focus_ring, t.colors.focus_ring);
532            assert_eq!(inactive.colors.surface_main, t.colors.surface_main);
533        }
534    }
535    /// A density switch must re-derive the Tier-3 slots this preset installs —
536    /// see the Fluent twin of this test, and `Theme::with_density`.
537    ///
538    /// `[unpublished]` — macOS has no touch ladder of its own, so the preset
539    /// uses the generic one. What moves is the *row*; the `[measured]` 22 dp
540    /// control height stays at Apple's number in the paint.
541    #[test]
542    fn a_density_switch_re_derives_the_installed_slots() {
543        let base = light();
544        let before = base
545            .style_slots
546            .standard_item
547            .clone()
548            .expect("slot installed");
549
550        let touch = base.with_density(TargetDensity::Touch);
551        let after = touch
552            .style_slots
553            .standard_item
554            .clone()
555            .expect("slot survives");
556
557        assert_eq!(touch.input.density, TargetDensity::Touch);
558        assert!(
559            !Rc::ptr_eq(&before, &after),
560            "the projection must rebuild the preset's own slots, not carry them across"
561        );
562
563        let compact = styles::standard_item::macos_standard_item_recipe_for(
564            &InputTokens::for_density(TargetDensity::Compact),
565        );
566        let touched = styles::standard_item::macos_standard_item_recipe_for(
567            &InputTokens::for_density(TargetDensity::Touch),
568        );
569        assert_eq!(
570            compact.min_height_single_line, 24.0,
571            "`NSTableView.rowHeight` on macOS 11+"
572        );
573        assert_eq!(touched.min_height_single_line, 44.0, "the Touch target");
574
575        assert_eq!(touch.id, base.id);
576        assert_eq!(touch.colors, base.colors);
577        assert!(touch.extension::<MacOsPalette>().is_some());
578    }
579
580    /// The menu slot is rebuilt for the density too, so the metrics
581    /// `MenuItem` and `MenuSeparator` read follow it, and switching back to
582    /// Compact gives the Compact metrics again.
583    #[test]
584    fn a_density_switch_reprojects_the_menu_metrics() {
585        use teksilo_core::styles::MenuItemStyle;
586
587        let base = light();
588        let metrics = |t: &Theme| {
589            t.style_slots
590                .menu_item
591                .as_ref()
592                .expect("slot installed")
593                .metrics()
594        };
595        for density in [
596            TargetDensity::Compact,
597            TargetDensity::Comfortable,
598            TargetDensity::Touch,
599        ] {
600            let t = base.with_density(density);
601            assert_eq!(
602                metrics(&t),
603                styles::menu_item::MacOsMenuItemStyle::for_tokens(&InputTokens::for_density(
604                    density
605                ))
606                .metrics(),
607                "{density:?}",
608            );
609        }
610        let touch = metrics(&base.with_density(TargetDensity::Touch));
611        let compact = metrics(&base);
612        assert!(touch.separator_height > compact.separator_height);
613        assert!(touch.trailing_column_width > compact.trailing_column_width);
614        // AppKit's 22 dp row is the preset's decision at every density.
615        assert_eq!(touch.item_height, compact.item_height);
616        let back = base
617            .with_density(TargetDensity::Touch)
618            .with_density(TargetDensity::Compact);
619        assert_eq!(metrics(&back), compact);
620    }
621}