Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
design_gallery.hpp
Go to the documentation of this file.
1#pragma once
2
3// pulp::design — design-system gallery: card model + review-artifact emitters.
4//
5// A "gallery card" is any example/kit source file that opts in with a first-line
6// magic comment. There is no registry to keep in sync — the tag lives in the
7// file, so a card is discovered by a grep of the source tree and survives a
8// move or rename:
9//
10// // @dsCard group=knobs viewport=120x120
11// // @startingPoint
12//
13// `pulp design gallery` walks a root, parses these tags, renders each card at
14// its declared viewport (via the screenshot tool, Skia backend), and emits one
15// review artifact per pass — a deterministic JSON manifest plus a self-contained
16// HTML grid grouped by `group`. That standing artifact replaces hunting loose
17// PNGs after an import/design pass, and doubles as a visual-regression inventory.
18//
19// This translation unit is deliberately pure: it parses the card model and
20// serializes the manifest/HTML, but does no filesystem or render work. The CLI
21// owns the walk, the render shell-out, and the content-hash cache; it hands the
22// emitters a `png_rel` callback so this layer never learns about paths on disk.
23// Kept separate for the same reason design_fidelity_ledger.cpp is separate from
24// the checks: the pure model stays trivially testable and free of GPU/IO.
25
26#include <functional>
27#include <optional>
28#include <string>
29#include <string_view>
30#include <vector>
31
32namespace pulp::design {
33
35inline constexpr std::string_view kGalleryFormatVersion = "2026.07-design-gallery-v1";
36
38inline constexpr std::string_view kGalleryUngrouped = "ungrouped";
39
42 std::string file;
43 std::string group;
44 int width = 0;
45 int height = 0;
46 bool starting_point = false;
47 std::string content_hash;
48};
49
56std::optional<GalleryCard> parse_gallery_card(std::string_view file_head,
57 std::string_view path);
58
63std::string gallery_content_hash(std::string_view bytes);
64
66void sort_cards(std::vector<GalleryCard>& cards);
67
73 const std::vector<GalleryCard>& cards,
74 const std::function<std::string(const GalleryCard&)>& png_rel);
75
81std::string gallery_html(
82 const std::vector<GalleryCard>& cards,
83 const std::function<std::string(const GalleryCard&)>& png_rel);
84
85} // namespace pulp::design
Definition design_adherence.hpp:32
std::optional< GalleryCard > parse_gallery_card(std::string_view file_head, std::string_view path)
Parse the leading magic comments of one source file.
constexpr std::string_view kGalleryFormatVersion
Format id stamped into the manifest JSON; bump on a non-additive shape change.
Definition design_gallery.hpp:35
std::string gallery_content_hash(std::string_view bytes)
Deterministic 64-bit FNV-1a hash (lowercase hex) of a card's source bytes.
void sort_cards(std::vector< GalleryCard > &cards)
Stable order: by group, then by file. The gallery diffs cleanly across passes.
std::string gallery_html(const std::vector< GalleryCard > &cards, const std::function< std::string(const GalleryCard &)> &png_rel)
Self-contained HTML review page: one section per group, each card shown at its declared viewport with...
std::string gallery_manifest_json(const std::vector< GalleryCard > &cards, const std::function< std::string(const GalleryCard &)> &png_rel)
Deterministic JSON manifest: format_version, a total, and one entry per group (sorted,...
constexpr std::string_view kGalleryUngrouped
The group a card falls into when its tag omits group=.
Definition design_gallery.hpp:38
One tagged card discovered by its leading @dsCard magic comment.
Definition design_gallery.hpp:41
int width
viewport width in points (from viewport=WxH)
Definition design_gallery.hpp:44
std::string group
group=<name>; empty tag value -> kGalleryUngrouped
Definition design_gallery.hpp:43
std::string file
path as discovered (relative to the scan root)
Definition design_gallery.hpp:42
bool starting_point
@startingPoint present -> a pulp create --from seed
Definition design_gallery.hpp:46
std::string content_hash
gallery_content_hash() of the source bytes; caller-filled
Definition design_gallery.hpp:47
int height
viewport height in points
Definition design_gallery.hpp:45