feat(draw): per-object data-* caption overlay on the drawing card (T-318)

DrawingCard stacks a caption layer over the SVG: each data-label /
data-description annotation renders a themed caption just below its
element, mapped to pixel space via a shared svgViewportFit (refactored out
of the painter so the overlay and the paint use identical viewBox-fit
math). Display-only (IgnorePointer). Widget-tested. data-lightbox is
captured in the model; the tap-to-zoom interaction is the last follow-on.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-28 22:35:12 +02:00
co-authored by Claude Opus 4.8
parent 78b0a7b8a4
commit 3e43746c17
3 changed files with 77 additions and 9 deletions
+46 -4
View File
@@ -2,9 +2,11 @@
///
/// Renders an [SvgDocument] — the substrate the SVG engine paints — inside a
/// framed region, with an optional clide-themed caption (label + description)
/// beneath it. The SVG is *content* (its own palette); the frame and caption
/// are clide *chrome* and use `SurfaceTokens`. Display-only per D-78 — no
/// interaction lives on the card.
/// beneath it, plus per-object overlay captions anchored to SVG elements that
/// carry `data-label` / `data-description` (mapped to pixel space via the same
/// viewBox fit the painter uses). The SVG is *content* (its own palette); the
/// frame and captions are clide *chrome* and use `SurfaceTokens`. Display-only
/// per D-78 — no interaction lives on the card.
///
/// Sizes the SVG to its intrinsic aspect ratio (viewBox / width-height) within
/// a height cap, filling the available width.
@@ -51,8 +53,24 @@ class DrawingCard extends StatelessWidget {
Widget _svgRegion(SurfaceTokens tokens) {
final view = SvgView(document: document, images: images);
final captioned = document.annotations.where((a) => _has(a.label) || _has(a.description)).toList();
final content = captioned.isEmpty
? view
: Stack(
fit: StackFit.expand,
children: [
view,
LayoutBuilder(
builder: (ctx, c) {
final size = Size(c.maxWidth, c.maxHeight);
final vp = svgViewportFit(size, document);
return Stack(children: [for (final a in captioned) _caption(a, vp, tokens)]);
},
),
],
);
final aspect = _aspect(document);
final sized = aspect != null ? AspectRatio(aspectRatio: aspect, child: view) : SizedBox(height: maxHeight, child: view);
final sized = aspect != null ? AspectRatio(aspectRatio: aspect, child: content) : SizedBox(height: maxHeight, child: content);
return DecoratedBox(
decoration: BoxDecoration(
color: tokens.panelBackground,
@@ -69,6 +87,30 @@ class DrawingCard extends StatelessWidget {
);
}
/// A per-object caption (data-label / data-description) positioned just below
/// the annotated element's pixel bbox. Display-only (IgnorePointer).
Widget _caption(SvgAnnotation a, SvgViewport vp, SurfaceTokens tokens) {
final tl = vp.toPixel(a.x, a.y);
final br = vp.toPixel(a.x + a.width, a.y + a.height);
final w = (br.dx - tl.dx).abs();
final h = (br.dy - tl.dy).abs();
return Positioned(
left: tl.dx,
top: tl.dy + h + 2,
width: w < 48 ? 48.0 : w,
child: IgnorePointer(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (_has(a.label)) ClideText(a.label!, fontSize: clideFontCaption, fontWeight: FontWeight.w600, color: tokens.globalForeground, maxLines: 2),
if (_has(a.description)) ClideText(a.description!, fontSize: clideFontCaption, color: tokens.globalTextMuted, maxLines: 3),
],
),
),
);
}
static double? _aspect(SvgDocument d) {
final w = d.viewBox?.width ?? d.width;
final h = d.viewBox?.height ?? d.height;