Keep gallery registrations in owned catalogs

This commit is contained in:
FredApps
2026-11-19 17:02:11 +01:00
parent 6e36fda086
commit 2e307a79bc
6 changed files with 16 additions and 13 deletions
+2
View File
@@ -135,6 +135,8 @@ const NO_GLOBAL_STATE_PREFIXES: &[&str] = &[
/// a `static` or `thread_local!` item or [`FS`] for `std::fs`. Each group names the settled fact or environment key that
/// covers it, or the later task of craft-libs#2336 that removes the state. A new item in these files is flagged.
const NO_GLOBAL_STATE: &[(&str, &str)] = &[
// Compile-time registry discovery reads the defining crate's source, never a view input.
("crates/ui-macros/src/registry.rs", FS),
// The trait's home crate: it implements `MemoProps` by hand for std and framework value types.
("crates/ui-contract/src/contract/memo.rs", "MemoProps"),
// Settled fact: constant font bytes, decompressed once from compile-time input and immutable after init.
+1
View File
@@ -178,6 +178,7 @@ impl Story {
/// A story registered by `#[story]`, linked to its type by the type's registered name.
#[doc(hidden)]
#[derive(Clone, Copy)]
#[non_exhaustive]
pub struct StoryRegistration {
/// The package that declares the story.
+4 -4
View File
@@ -61,14 +61,14 @@ pub struct CardStory<'a> {
/// The index of the story in the catalog: the key of its state.
pub index: usize,
/// The story.
pub story: &'static StoryRegistration,
pub story: StoryRegistration,
/// The story's caption.
pub caption: &'a str,
}
impl<'a> CardStory<'a> {
/// The story at catalog index `index`, under `caption`.
pub fn new(index: usize, story: &'static StoryRegistration, caption: &'a str) -> Self {
pub fn new(index: usize, story: StoryRegistration, caption: &'a str) -> Self {
CardStory { index, story, caption }
}
}
@@ -241,7 +241,7 @@ pub struct StoryBody {
/// The id scope of the story: unique among the stories of a pass.
pub key: String,
/// The story.
pub story: &'static StoryRegistration,
pub story: StoryRegistration,
/// The surface the story sits on.
pub surface: Surface,
/// The most a story that fills takes.
@@ -268,7 +268,7 @@ pub struct BodyShown {
impl StoryBody {
/// The body of `story` on `surface`, in the window's look, with ungated wheel takers.
pub fn new(key: impl Into<String>, story: &'static StoryRegistration, surface: Surface, room: f32, panel_pad: Pad) -> Self {
pub fn new(key: impl Into<String>, story: StoryRegistration, surface: Surface, room: f32, panel_pad: Pad) -> Self {
StoryBody { key: key.into(), story, surface, room, look: Look::default(), gated: false, panel_pad, caption: None, inspect: None }
}
+1 -1
View File
@@ -36,7 +36,7 @@ pub struct SpecStory {
/// The index of the story in the catalog.
pub index: usize,
/// The story's registration.
pub story: &'static StoryRegistration,
pub story: StoryRegistration,
/// The story's caption.
pub caption: String,
}
+2 -3
View File
@@ -72,9 +72,8 @@ pub fn register_all(registry: &mut craft_ui::testing::Registry) {
}
/// The registry of the viewer and the crates whose stories it shows.
pub fn registry() -> &'static craft_ui::testing::Registry {
static REGISTRY: std::sync::OnceLock<craft_ui::testing::Registry> = std::sync::OnceLock::new();
REGISTRY.get_or_init(|| craft_ui::testing::Registry::of(&[register_all]))
pub fn registry() -> craft_ui::testing::Registry {
craft_ui::testing::Registry::of(&[register_all])
}
/// How many registrations each selected crate contributes, and how many stories there are in all.
+6 -5
View File
@@ -10,7 +10,7 @@ use std::sync::OnceLock;
#[non_exhaustive]
pub struct Entry {
/// The registration.
pub registration: &'static StoryRegistration,
pub registration: StoryRegistration,
/// The registered name of the type the story shows.
pub type_name: &'static str,
}
@@ -109,7 +109,8 @@ pub fn fold_filter(filter: &str) -> String {
pub(crate) fn linked_catalog() -> &'static contract::Catalog {
static CATALOG: OnceLock<contract::Catalog> = OnceLock::new();
CATALOG.get_or_init(|| {
let registrations: Vec<_> = crate::registry().registrations().iter().collect();
let registry = crate::registry();
let registrations: Vec<_> = registry.registrations().iter().collect();
contract::catalog(&registrations)
})
}
@@ -121,7 +122,7 @@ pub fn display_name(type_name: &str) -> String {
/// Every story linked into the viewer, ordered by type then story name.
pub fn entries() -> Vec<Entry> {
crate::registry().stories().iter().map(|registration| Entry { registration, type_name: (registration.type_name)() }).collect()
crate::registry().stories().iter().map(|registration| Entry { registration: *registration, type_name: (registration.type_name)() }).collect()
}
/// What a registration says about a type: where it is declared and what it is for.
@@ -133,7 +134,7 @@ pub struct Declared {
/// The first sentence of the type's doc comment.
pub purpose: &'static str,
/// The component probe; `None` for a pattern.
pub probe: Option<&'static Probe>,
pub probe: Option<Probe>,
}
/// The registration of each registered component and pattern type, by the type's registered name.
@@ -142,7 +143,7 @@ pub fn declared() -> HashMap<&'static str, Declared> {
for registration in crate::registry().registrations() {
match registration {
Registration::Component(probe) => {
out.insert(probe.type_name(), Declared { module: probe.module, purpose: probe.purpose, probe: Some(probe) });
out.insert(probe.type_name(), Declared { module: probe.module, purpose: probe.purpose, probe: Some(*probe) });
}
Registration::Pattern(probe) => {
out.insert(probe.type_name(), Declared { module: probe.module, purpose: probe.purpose, probe: None });