Files
vectorcraft/crates/ui-egui/src/theme.rs
T
BFlat e4347f0d6f Look: production's breathing room across VectorCraft (type size, menus, dialogs, Home, panels) and main's lib test fixes (#9292)
* Theme: type at the size production draws it. Production set Inter at 92% of its nominal size, so its 13-point body, 12.5-point labels and 11.5-point captions read at 12, 11.5 and 10.5 points; SIZES took the nominal sizes, which drew every text about 8% larger than production on the same rows. Body and strong body 12, labels 11.5, captions 10.5, line heights kept. Dialog buttons at least 72 points wide, as production's.

* Theme: menus and dialogs as production spaces them. 29-point menu rows (production's 24-point rows 5 points apart), dialogs 22 points inside their edge (production's dialog margin) and 28-point dialog buttons. Needs a craft-libs rev with size.row.menu, size.dialog.button_height and space.pad.dialog (fix/vc-look9-metrics): on an older rev SIZES does not parse. Land it after that rev move.

* Home: production's rhythm through the framework's page sizes: 9 from title to subtitle, 27 to New and Open, which stand 28 high with 16 points beside their labels and 14 apart, 33 between sections, 15 under a heading, the community links in 24-point rows 5 apart and in the link colour alone (LinkLook::Plain on Home only); Learn's skills a heading gap apart, each title muted over its tutorials, which stand as tall as New and Open, as production's secondary buttons did

* Swatches: thumbnails at production's sizes and the footer split as production

The thumbnail views give the browser zooms of 1/4, 1/3 and 2/3 on the large
thumbnail: 12, 16 and 32 point tiles, production's 11, 15.5 and 30. The
library panels' saved view follows the new zooms. Swatch Libraries, Show
Swatch Kinds and the edit action stand at the footer's start edge; New Color
Group, New Swatch and Delete at its end edge.

* Color Guide: the footer split as production

Limit to Library stands at the start edge; Edit or Apply Colors, Save
selected colors and Save color group at the end edge, in that order.

* Graphic Styles: 40-point tiles in Thumbnail View

Thumbnail View sets its own zoom, as the list views do, so its tiles are
production's 40 points and no longer keep a list view's zoom.

* Align panel: the reference app's groups and rules: the align and distribute buttons in groups a section gap apart, a rule between Align Objects and Distribute Objects, and Distribute Spacing and Align To on one line with a rule between them

* Transform panel: a rule over the shape properties and over the options, as the reference app had

* Info panel: the two columns of numbers are equal halves of the panel, as the reference app had them

* Layers panel: the footer's layer count is a text unit of the footer row in the text ink, as the reference app showed it

* Libraries panel: the no-library notice shows the library icon over its title, as the reference app did

* craft-libs: next 5442cfb97, with the page rhythm tokens, LinkLook, the menu row height and the dialog padding and button height the look commits set

* Docking test: the report names the panel that has the keys after a click in its search field. A press on a dock tab now leaves the keys where they were (craft-libs TabStrip::keeps_focus), so the tab click alone no longer focuses the panel; the search lookup is a harness helper both tests use

* craft-libs: next 6fcf61c81, a document window raised as Presentation Mode ends comes to the front

* Canvas drops: a canvas takes no drop where a floating panel's OS window lies over it

The canvas's drop catcher accepted art carried off its own canvas wherever
the pointer was over the canvas, including where a floating panel's OS window
lies over it. The main window's pass runs first, so the canvas took the drop
and resumed the move, and the panel under the pointer got nothing. Every
target of the catcher now refuses a point that panel_docking::os_window_at
reports covered, the same rule the Selection tools' carry uses.

It used to work by accident: the carry's covered test flickered every other
frame, the move dispatched a drag in those frames, and the changed revision
made the canvas refuse the carried art until the release.

* Safe Mode: the choice about a stopped plug-in opens on the host at once

The choice was put on the host's startup queue, which the host drains
only at the start of its next pass. On main the first frame happened to
run a second pass (layout memory asked for a rerun), so the choice was
open by the end of the launch frame; the framework now settles that
frame in one pass, and the choice stayed queued until the frame after,
where an agent's ui.dialog.* found no hosted dialog open. The choice is
only asked for on an empty host, so opening it directly is what the
queue would do one pass later.

* Image Trace sampler test: a step runs until the press lifecycle reported its events

run_ui stopped stepping once egui had seen every pointer event of the
step. The press lifecycle reports one phase a pass, so a pass that
brings a release and the next press (two clicks in one frame) reports
the press's Down one pass later and holds its release for the pass after
that, asking for a repaint. The step ended before that pass, and the
second click of review_597048_two_ordinary_clicks_in_one_frame_survive_
sampler_correction never reached the tool, so the group did not isolate.

It passed before by accident: with craft-libs a4b6d3b6ca every other
frame ran a second pass, and the held release landed in it. With
6fcf61c81 each of these frames runs one pass. The step now also counts
the phases owed and runs empty frames until the passes have caught up.

* Shapes add-on: the helper that maps a shape tool to its icon is icon_for_shape, so the icon test no longer reads its tool ids ("polygon", "no-such-tool") as icon ids

* Native panel window test: drop the art on the first graphic style's tile

The test dropped the art 60 x 120 points into the Graphic Styles window. Since
Thumbnail View's tiles are 40 points (df940cff4e) the tile row ends at 116
points, so that point lies in the empty room below the tiles, which takes no
drop, and the panel made no style. The test now finds the first style's tile
by its name in the window's access tree and drops the art there. The test
host keeps each window's named access nodes for that.
2026-11-25 23:23:47 +07:00

239 lines
9.0 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! The user's interface choices (brightness, accent, colour scheme) and how they select the root theme.
use craft::theme::{AppSizes, ModeChoice, Rgba, ThemeId};
use egui::{FontFamily, FontId};
use serde::{Deserialize, Serialize};
use std::sync::{Arc, LazyLock};
use vectorcraft_engine::Prefs;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub enum Brightness {
Dark,
#[default]
MediumDark,
MediumLight,
Light,
}
impl Brightness {
pub const ALL: [Brightness; 4] = [Brightness::Dark, Brightness::MediumDark, Brightness::MediumLight, Brightness::Light];
pub fn label(self) -> &'static str {
match self {
Brightness::Dark => "Dark",
Brightness::MediumDark => "Medium Dark",
Brightness::MediumLight => "Medium Light",
Brightness::Light => "Light",
}
}
pub fn id(self) -> &'static str {
match self {
Brightness::Dark => "dark",
Brightness::MediumDark => "mediumDark",
Brightness::MediumLight => "mediumLight",
Brightness::Light => "light",
}
}
pub fn parse(s: &str) -> Option<Self> {
Self::ALL.into_iter().find(|b| b.id().eq_ignore_ascii_case(s) || b.label().eq_ignore_ascii_case(s))
}
}
/// User Interface › Accent Color: the one colour for what is on, chosen or focused. Coral, the
/// default, is the app icon's.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum Accent {
#[default]
Coral,
Blue,
Violet,
Green,
Amber,
Pink,
}
impl Accent {
pub const ALL: [Accent; 6] = [Accent::Coral, Accent::Blue, Accent::Violet, Accent::Green, Accent::Amber, Accent::Pink];
pub fn id(self) -> &'static str {
match self {
Accent::Coral => "coral",
Accent::Blue => "blue",
Accent::Violet => "violet",
Accent::Green => "green",
Accent::Amber => "amber",
Accent::Pink => "pink",
}
}
pub fn parse(s: &str) -> Option<Self> {
Self::ALL.into_iter().find(|a| a.id().eq_ignore_ascii_case(s))
}
/// The accent's seed colour (`0xRRGGBB`) on dark panels and on light ones.
fn seed_hex(self, dark: bool) -> u32 {
match (self, dark) {
(Accent::Coral, true) => 0xf06a52,
(Accent::Coral, false) => 0xd9472f,
(Accent::Blue, true) => 0x5b96ff,
(Accent::Blue, false) => 0x2563eb,
(Accent::Violet, true) => 0xa98bff,
(Accent::Violet, false) => 0x7146dc,
(Accent::Green, true) => 0x3fcf8e,
(Accent::Green, false) => 0x16955a,
(Accent::Amber, true) => 0xf5b544,
(Accent::Amber, false) => 0xb06d06,
(Accent::Pink, true) => 0xf36aa3,
(Accent::Pink, false) => 0xcc3672,
}
}
}
/// User Interface › Color Scheme: Modern (the default: slate greys and the chosen accent) or
/// Classic (the neutral greys and blue accent of earlier versions). Both keep the same layout,
/// cards and corners; only the colours differ.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum Scheme {
#[default]
Modern,
Classic,
}
impl Scheme {
pub const ALL: [Scheme; 2] = [Scheme::Modern, Scheme::Classic];
pub fn id(self) -> &'static str {
match self {
Scheme::Modern => "modern",
Scheme::Classic => "classic",
}
}
pub fn parse(s: &str) -> Option<Self> {
Self::ALL.into_iter().find(|c| c.id().eq_ignore_ascii_case(s))
}
}
/// A built-in theme's id; the ids are constants, so the fallback never shows.
fn theme_id(id: &str) -> ThemeId {
ThemeId::parse(id).unwrap_or_else(|_| ThemeId::suite_default())
}
/// The root theme the saved interface preferences select: its id, its fixed mode (the four
/// brightness levels decide light or dark, never the system) and the accent seed. Classic keeps its
/// own blue and Modern's coral is in its theme files, so both return no seed there.
pub fn root_theme(prefs: &Prefs) -> (ThemeId, ModeChoice, Option<Rgba>) {
let brightness = Brightness::parse(&prefs.ui_brightness).unwrap_or_default();
let accent = Accent::parse(&prefs.ui_accent).unwrap_or_default();
let scheme = Scheme::parse(&prefs.ui_color_scheme).unwrap_or_default();
let dark = matches!(brightness, Brightness::Dark | Brightness::MediumDark);
let mode = if dark { ModeChoice::Dark } else { ModeChoice::Light };
match scheme {
Scheme::Classic => {
let id = match brightness {
Brightness::MediumDark => "craft.artcraft",
Brightness::MediumLight => "craft.pro-light-gray",
Brightness::Dark | Brightness::Light => "craft.pro",
};
(theme_id(id), mode, None)
}
Scheme::Modern => {
let id = match brightness {
Brightness::Dark | Brightness::Light => "craft.vectorcraft-modern",
Brightness::MediumDark | Brightness::MediumLight => "craft.vectorcraft-modern-medium",
};
let seed = (accent != Accent::Coral).then(|| {
let h = accent.seed_hex(dark);
Rgba::rgb((h >> 16) as u8, (h >> 8) as u8, h as u8)
});
(theme_id(id), mode, seed)
}
}
}
/// The app's sizes over the framework's size sets (`sizes.json`): push buttons have the app's 4-point corners
/// where the sets give pills, the Home title is 26-point under 60 points of page margin with a 36-point call to
/// action, Home keeps production's rhythm (its item spacing of 5 plus the room it added: 9 from title to subtitle, 27
/// to New and Open, 28-point New and Open with 16 points beside their labels and 14 between them, 33 between sections,
/// 15 under a heading, 24-point link rows 5 apart), and the compact set takes the reference app's metrics:
/// 26-point fields and spinners, 24-point push buttons, 10 points inside panels, 5 between rows, 16-point glyphs in
/// icon buttons, 5-point control corners, 8-point menus and 10-point windows, 33-point panel tabs, 310-point dock
/// columns with 14-point column bars and 38-point icon columns, 29-point menu rows, and dialogs 22 points inside their
/// edge with 28-point buttons at least 72 points wide.
/// Its type is the size the reference app draws: it set Inter at 92% of its nominal 13-point body, 12.5-point labels
/// and 11.5-point captions, so they read at 12, 11.5 and 10.5 points, on the rows those nominal sizes gave.
const SIZES: &[u8] = br#"{
"all": {
"radius.button": 4,
"typography.display.size": 26,
"typography.display.line_height": 32,
"size.page.margin": 60,
"size.page.action": 36,
"size.page.button": 28,
"size.page.button_side": 16,
"size.page.gap.title": 9,
"size.page.gap.lead": 27,
"size.page.gap.actions": 14,
"size.page.gap.section": 33,
"size.page.gap.heading": 15,
"size.page.gap.link": 5,
"size.page.link": 24
},
"compact": {
"size.control.md": 26,
"size.button": 24,
"size.icon.glyph_md": 16,
"size.rail.width": 38,
"size.dock.column": 310,
"size.bar.column": 14,
"size.panel_header": 33,
"size.bar.tab": 35,
"size.bar.tab_large": 44,
"space.pad.regular": 10,
"space.gap.row": 5,
"radius.control": 5,
"radius.surface": 8,
"radius.window": 10,
"size.dialog.button": 72,
"size.dialog.button_height": 28,
"size.row.menu": 29,
"space.pad.dialog": 22,
"typography.body.size": 12,
"typography.body.line_height": 17,
"typography.body_strong.size": 12,
"typography.body_strong.line_height": 17,
"typography.label.size": 11.5,
"typography.label.line_height": 17,
"typography.caption.size": 10.5,
"typography.caption.line_height": 15
}
}"#;
/// The app's sizes ([`SIZES`]) as one shared value: the token cache tells a change of sizes by its pointer, so a
/// new value each frame would resolve the tokens again each frame.
pub fn app_sizes() -> Arc<AppSizes> {
static SHARED: LazyLock<Arc<AppSizes>> = LazyLock::new(|| Arc::new(AppSizes::parse_or_default(SIZES)));
Arc::clone(&SHARED)
}
pub fn semibold(size: f32) -> FontId {
FontId::new(size, FontFamily::Name(craft::ui::fonts::SEMIBOLD.into()))
}
pub fn mono(size: f32) -> FontId {
FontId::monospace(size)
}
#[cfg(test)]
mod tests {
use super::*;
/// The saved strings are what Preferences and old settings files hold.
#[test]
fn brightness_roundtrip() {
for b in Brightness::ALL {
assert_eq!(Brightness::parse(b.id()), Some(b));
assert_eq!(Brightness::parse(b.label()), Some(b));
}
}
/// A size `app_sizes` cannot read is only logged and dropped, which brings the pill buttons back unnoticed.
#[test]
fn the_app_sizes_are_read_whole() {
assert!(AppSizes::parse(SIZES).is_ok_and(|sizes| !sizes.is_empty()));
}
}