From 424cf7fd98b89ea35c130512c0398c9bd4dc289a Mon Sep 17 00:00:00 2001 From: aiongg Date: Sat, 14 Nov 2026 03:37:21 +0000 Subject: [PATCH] panels-w11: written by an agent --- crates/font-manager/README.md | 8 +- crates/font-manager/src/glyphs.rs | 20 ++- crates/font-manager/src/glyphs/stories.rs | 29 ++++ crates/font-store/src/lib.rs | 16 ++- crates/font-store/src/store.rs | 14 +- crates/imaging/src/ui/adjust/kinds.rs | 116 ++++++++------- crates/imaging/src/ui/adjust/mod.rs | 9 +- crates/imaging/src/ui/adjust/panel.rs | 132 ++++++++++++++++++ crates/imaging/src/ui/adjust/panel/stories.rs | 24 ++++ 9 files changed, 285 insertions(+), 83 deletions(-) create mode 100644 crates/imaging/src/ui/adjust/panel.rs create mode 100644 crates/imaging/src/ui/adjust/panel/stories.rs diff --git a/crates/font-manager/README.md b/crates/font-manager/README.md index 9b4b9c439..e77d6a981 100644 --- a/crates/font-manager/README.md +++ b/crates/font-manager/README.md @@ -10,12 +10,12 @@ Fonts tab; the standalone app | `filter` | always | Search over the index: family names ignoring case and accents, category, language (English name, autonym or id) and script | | `index` | always | The pinned built-in indexes (Google Fonts and Noto) compiled into [`craft-font-store`](../font-store/README.md) (`bundled`), each family's source (`source_label`: its name and whether it is curated), and the categories | | `installed` | always | The installed fonts [`craft-font-catalog`](../font-catalog/README.md) sees, grouped by family and source | -| `store` | always | `Installer`, what the interface needs from the font store: the download consent, install, remove, downloads for a preview, the indexes (`indexes`, `fetch_indexes`) and the sources the user added (`user_sources`, `add_user_source`, `remove_user_source`). `SuiteStore` is craft-font-store's store, `FakeStore` a stand-in for tests, `NoStore` one for when the store folder is unknown | +| `store` | always | `Installer`, what the interface needs from the font store: the download consent, install, remove, downloads for a preview, the indexes (`indexes`, `fetch_indexes`) and the sources the user added (`user_sources`, `add_user_source`, `remove_user_source`). `SuiteStore` is craft-font-store's store (native only), `FakeStore` a stand-in for tests, `NoStore` one for when the store folder is unknown | | `FontsPanel` | `ui` | The whole interface as one egui panel | -| `glyphs` | `ui` | `GlyphsPanel`: the character grid of a face with categories, zoom and Recently Used; the app supplies the glyphs through `GlyphSource`. Sizes are the `glyphs.*` tokens | +| `glyphs` | `ui` | `GlyphsPanel`: the character grid of a face with categories, zoom and Recently Used; the app supplies the glyphs through `GlyphSource`, which also reports when it is ready and when its faces change. Sizes are the `glyphs.*` tokens | | `missing` | `ui` | `document_fonts`, `missing_font_warnings` and `MissingFontsDialog`: which fonts a document names are not installed, and a replacement for each | | `axes` | `ui` | `read_axes`, `read_named_instances` and `AxisSliders`: a variable face's axes as sliders with a Style list of its named instances | -| `picker` | `ui` | `FontPicker`: the family field with its list (stars, recents, class and feature filters, similar fonts, previews) | +| `picker` | `ui` | `FontPicker`: the family field with its list (stars, recents, class and feature filters, similar fonts, previews, style rows, the served families and the banner) | The stories (`patterns/font-picker/*`, `patterns/glyphs-panel/panel`, `patterns/missing-fonts-dialog/dialog`, `composites/axis-sliders/sliders`) use the two faces egui ships. @@ -54,6 +54,8 @@ its strings and numbers are in `host.lang()` each frame (English without a Host, has no catalog for the language), its settings section is `fonts_panel`, and installs, removals and previews run through `host.jobs()`, one at a time in request order (without a Host, on craft-host's default job service: a thread per runner, inline on wasm32). +Native code (`SuiteStore` is not built for wasm32): + ```rust let catalog = Arc::clone(Catalog::global()); catalog.scan_in_background(); diff --git a/crates/font-manager/src/glyphs.rs b/crates/font-manager/src/glyphs.rs index 6b328d736..0a20f136f 100644 --- a/crates/font-manager/src/glyphs.rs +++ b/crates/font-manager/src/glyphs.rs @@ -1,6 +1,6 @@ //! [`GlyphsPanel`]: Photoshop's Glyphs panel. A family and style picker, a category list (Entire Font, Punctuation, //! Currency, ...), a grid of glyph cells drawn by the app's text engine, a zoom slider, and the recently used -//! glyphs in a row at the top. Double-click or Enter inserts the glyph into the text being edited. +//! glyphs in a row at the top. Double-click or Enter inserts the glyph where the app can insert. #[cfg(feature = "screen-testing")] mod stories; @@ -13,7 +13,7 @@ use craft_ui::contract::{ ActivateOn, Bind, CollectionEvent, Entry, NoValue, Outcome, Pad, Pattern, Props, Remember as _, SelectMode, Show as _, ShowCollection as _, ShowContainer as _, }; -use craft_ui::display::Text; +use craft_ui::display::{Shade, Spinner, Text}; use craft_ui::layout_components::{Row, Stack}; use craft_ui::list::ThumbAspect; use craft_ui::list::ThumbSize; @@ -26,6 +26,7 @@ use craft_ui::tile_grid::{CaptionPlace, ThumbnailSlider, Tile, TileGrid, TileZoo use egui::{ColorImage, Rect, Response, Ui}; use serde::{Deserialize, Serialize}; +use crate::panel::browse::SCAN_POLL_SECONDS; use crate::picker::{read_bind, write_bind}; craft_ui::words! { @@ -152,7 +153,7 @@ impl Section for GlyphsPanelSettings { pub struct GlyphsPanelOutput { /// The panel's response. pub response: Response, - /// A glyph to insert at the caret (double-click, Enter on the focused cell); only while text is edited. + /// A glyph to insert at the caret (double-click, Enter on the focused cell); only where the app can insert. pub insert: Option, /// The family or style changed in the panel's own pickers. pub font_changed: bool, @@ -262,7 +263,8 @@ impl craft_behavior::ItemSource for Chars<'_> {} /// Enter inserts. Hovering a cell shows its character and code point as a tooltip. /// - A cell is drawn from [`GlyphSource::glyph`] at the zoom size, cached per face and character. The grid shows /// only the current category; a cell the source returns no image for stays empty. -/// - Without text being edited the cells still show, Enter and double-click do nothing and the footer says so. +/// - Where the app cannot insert, the cells still show, Enter and double-click do nothing and the footer says so. +/// - While the source is not [ready](GlyphSource::ready) the panel shows a spinner and "Loading fonts…" only. /// - The font and style lists come from the app ([`families`](GlyphsPanel::families), /// [`styles`](GlyphsPanel::styles)); without a list the name is shown as text. #[must_use = "show the panel with `show`"] @@ -301,6 +303,16 @@ impl<'a> GlyphsPanel<'a> { let GlyphsPanel { label, source, mut family, mut style, mut settings, families, styles, can_insert } = self; let env = Env::of(ui); let words = env.words::(); + if !source.ready() { + let shown = Stack::new().label(label).show(ui, |ui, _| { + Row::new().show(ui, |ui, _| { + Spinner::new().label(words.loading.clone()).show(ui); + Text::new(words.loading.clone()).shade(Shade::Muted).show(ui); + }); + }); + craft_ui::runtime::frame::request_repaint_after(ui.ctx(), SCAN_POLL_SECONDS); + return GlyphsPanelOutput { response: shown.output, insert: None, font_changed: false }; + } let thumbs = Thumbnails::::in_context(ui.ctx(), "craft-font-manager-glyphs", ThumbnailOptions::new()); let pictures = GlyphPictures(source); let mut insert: Option = None; diff --git a/crates/font-manager/src/glyphs/stories.rs b/crates/font-manager/src/glyphs/stories.rs index dbf8a2622..de318f784 100644 --- a/crates/font-manager/src/glyphs/stories.rs +++ b/crates/font-manager/src/glyphs/stories.rs @@ -51,6 +51,35 @@ fn glyphs_panel_not_editing(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { show_panel(ui, data, false) } +/// The panel while the app is still reading its fonts: a spinner and the loading line, no grid. +#[story(GlyphsPanel<'static>, covers = [], drive = Drive::Never)] +fn glyphs_panel_loading(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let Demo { family, style, settings } = + data.value("loading", Demo { family: String::new(), style: String::new(), settings: GlyphsPanelSettings::default() }); + GlyphsPanel::new("Glyphs", &NotReady, Bind::bound(family), Bind::bound(style), Bind::bound(settings)).can_insert(true).show(ui).into() +} + +/// A source whose fonts are not read yet. +struct NotReady; + +impl GlyphSource for NotReady { + fn charmap(&self, _: &str, _: &str) -> Vec { + Vec::new() + } + + fn glyph(&self, _: &str, _: &str, _: char, _: u32) -> Option { + None + } + + fn in_category(&self, _: char, _: &str) -> bool { + false + } + + fn ready(&self) -> bool { + false + } +} + /// Glyphs of the shipped faces, drawn by skrifa's outlines. struct FaceGlyphs; diff --git a/crates/font-store/src/lib.rs b/crates/font-store/src/lib.rs index ac43dc098..b96ac2846 100644 --- a/crates/font-store/src/lib.rs +++ b/crates/font-store/src/lib.rs @@ -43,6 +43,20 @@ pub use pin::{IndexPin, PINNED_INDEX}; pub use sources::{SourceEntry, SourcesFile}; pub use verify::{VerifyError, is_font, sha256_hex, verify_font}; +/// A source the user added: an index file at an https URL, never curated. Plain data, so it builds on every target +/// for the interfaces that list the sources. +#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub struct UserSource { + /// The index file (format 1.x, JSON or gzipped JSON). + pub url: String, + /// When it was added, in seconds since 1970. + pub added_at: u64, + /// The sha256 of the file first fetched from it. A different file later shows as + /// [`FontSource::changed`]. + #[serde(default)] + pub last_sha256: Option, +} + #[cfg(not(target_arch = "wasm32"))] pub use http::{Cancel, Client, FetchError, Timeouts, USER_AGENT}; #[cfg(not(target_arch = "wasm32"))] @@ -51,7 +65,7 @@ pub use language_packs::{ MAX_PACK_INDEX_BYTES, MAX_PACK_UNPACKED_BYTES, PackEntry, PackIndex, PackIndexPin, language_pack_index_overridden, }; #[cfg(not(target_arch = "wasm32"))] -pub use store::{Caller, Error, FontStore, InstalledFamily, InstalledFile, Network, Problem, Progress, UserSource}; +pub use store::{Caller, Error, FontStore, InstalledFamily, InstalledFile, Network, Problem, Progress}; #[cfg(test)] mod tests; diff --git a/crates/font-store/src/store.rs b/crates/font-store/src/store.rs index ae62ab443..a6e98d2f8 100644 --- a/crates/font-store/src/store.rs +++ b/crates/font-store/src/store.rs @@ -23,6 +23,7 @@ use std::time::{Duration, SystemTime}; use craft_font_catalog::{Catalog, FontEnv, font_store_dir}; use serde::{Deserialize, Serialize}; +use crate::UserSource; use crate::http::{Cancel, Client, FetchError}; use crate::index::{Face, Family, FontFile, GOOGLE_FONTS, Index, IndexError, MAX_INDEX_BYTES, MAX_LICENSE_BYTES, SourceProblem, Unavailable}; use crate::pin::IndexPin; @@ -183,19 +184,6 @@ fn google_fonts() -> String { GOOGLE_FONTS.into() } -/// A source the user added: an index file at an https URL, never curated. -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] -pub struct UserSource { - /// The index file (format 1.x, JSON or gzipped JSON). - pub url: String, - /// When it was added, in seconds since 1970. - pub added_at: u64, - /// The sha256 of the file first fetched from it. A different file later shows as - /// [`crate::FontSource::changed`]. - #[serde(default)] - pub last_sha256: Option, -} - #[derive(Clone, Default, Serialize, Deserialize)] struct Settings { #[serde(default)] diff --git a/crates/imaging/src/ui/adjust/kinds.rs b/crates/imaging/src/ui/adjust/kinds.rs index ad535ad1d..2a5c443a4 100644 --- a/crates/imaging/src/ui/adjust/kinds.rs +++ b/crates/imaging/src/ui/adjust/kinds.rs @@ -1,9 +1,7 @@ -//! [`AdjustmentKind`] and the Adjustments panel: a grid of icon buttons, one per adjustment. +//! [`AdjustmentKind`]: the adjustments the Adjustments panel offers, with their command key, icon and title. use craft_behavior::IconId; -use craft_ui::contract::{NoValue, Outcome, Pattern}; use craft_ui::runtime::env::Label; -use egui::{Response, Ui}; use super::AdjustWords; @@ -66,69 +64,69 @@ impl AdjustmentKind { AdjustmentKind::ColorLookup, ]; - /// The kind's key (`"brightnessContrast"`). + /// The kind's key (`"brightnessContrast"`): the suffix of the app's `layer.newAdjustmentLayer.{key}` command. pub fn key(self) -> &'static str { - let _ = self; - todo!("pn.C44") + match self { + AdjustmentKind::BrightnessContrast => "brightnessContrast", + AdjustmentKind::Levels => "levels", + AdjustmentKind::Curves => "curves", + AdjustmentKind::Exposure => "exposure", + AdjustmentKind::Vibrance => "vibrance", + AdjustmentKind::HueSaturation => "hueSaturation", + AdjustmentKind::ColorBalance => "colorBalance", + AdjustmentKind::BlackWhite => "blackWhite", + AdjustmentKind::PhotoFilter => "photoFilter", + AdjustmentKind::ChannelMixer => "channelMixer", + AdjustmentKind::Invert => "invert", + AdjustmentKind::Posterize => "posterize", + AdjustmentKind::Threshold => "threshold", + AdjustmentKind::GradientMap => "gradientMap", + AdjustmentKind::SelectiveColor => "selectiveColor", + AdjustmentKind::ColorLookup => "colorLookup", + } } /// The kind's icon from the catalog. pub fn icon(self) -> IconId { - let _ = self; - todo!("pn.C44") + IconId::new(match self { + AdjustmentKind::BrightnessContrast => "sun", + AdjustmentKind::Levels => "gauge", + AdjustmentKind::Curves => "pen_tool", + AdjustmentKind::Exposure => "scan", + AdjustmentKind::Vibrance => "sparkles", + AdjustmentKind::HueSaturation => "droplet", + AdjustmentKind::ColorBalance => "blend", + AdjustmentKind::BlackWhite => "contrast", + AdjustmentKind::PhotoFilter => "target", + AdjustmentKind::ChannelMixer => "adjustments", + AdjustmentKind::Invert => "squares_subtract", + AdjustmentKind::Posterize => "layers", + AdjustmentKind::Threshold => "square", + AdjustmentKind::GradientMap => "palette", + AdjustmentKind::SelectiveColor => "swatch_book", + AdjustmentKind::ColorLookup => "grid", + }) } - /// The kind's title. + /// The kind's title, from `words`. pub fn label(self, words: &AdjustWords) -> Label { - let _ = (self, words); - todo!("pn.C44") - } -} - -/// What the Adjustments panel reports. -#[derive(Debug)] -#[non_exhaustive] -pub struct AdjustmentsPanelOutput { - /// The panel's response. - pub response: Response, - /// The kind the user picked this pass. - pub picked: Option, -} - -impl Outcome for AdjustmentsPanelOutput { - type Value = NoValue; - - fn response(&self) -> &Response { - &self.response - } -} - -/// A grid of icon buttons in one roving group; the app picks which kinds it offers (default all). -#[must_use = "show the panel with `show`"] -#[derive(Pattern)] -#[allow(dead_code)] // P3(panels-w11): pn.C44 -pub struct AdjustmentsPanel<'a> { - label: Label, - kinds: &'a [AdjustmentKind], -} - -impl<'a> AdjustmentsPanel<'a> { - /// A panel named `label` offering every kind. - pub fn new(label: impl Into