Card
ui.widgets.Cardタイトル、本文、インタラクティブな面を一つの視覚単位にまとめます。
BEHAVIOR CONTRACT
default / outlined / elevated、selected、hoverable、interactive、padding の方針を明示的に区別します。
RECORDED INTERACTION
バリアントと各種インタラクション状態を示します。
// ── Card ──
pub fn buildCard(scope: *ui.Scope, cx: *ui.Cx) anyerror!*ui.Node {
const a = cx.allocator;
const c = try col(cx, 12);
// ── 变体 ──
try c.appendChild(a, try label(cx, "Variants (default / outlined / elevated)"));
try c.appendChild(a, try W.Card(.{ .title = "Default", .subtitle = "with subtitle", .variant = .default, .width = 320 }).mount(scope, cx));
try c.appendChild(a, try W.Card(.{ .title = "Outlined", .variant = .outlined, .width = 320 }).mount(scope, cx));
try c.appendChild(a, try W.Card(.{ .title = "Elevated", .variant = .elevated, .width = 320 }).mount(scope, cx));
// ── body ──
try c.appendChild(a, try label(cx, "With body"));
const res = try W.Card(.{ .title = "Card with body", .width = 320 }).mountBody(scope, cx);
try res.body.appendChild(a, try ui.text(cx, "Body content goes here.", .{ .font_size = 13, .color = light.color.fg_secondary }));
try c.appendChild(a, res.card);
// ── 交互态 ──
try c.appendChild(a, try label(cx, "States (selected / hoverable / interactive / no-pad)"));
try c.appendChild(a, try W.Card(.{ .title = "Selected", .selected = true, .width = 320 }).mount(scope, cx));
try c.appendChild(a, try W.Card(.{ .title = "Hoverable", .hoverable = true, .width = 320 }).mount(scope, cx));
try c.appendChild(a, try W.Card(.{ .title = "Interactive", .interactive = true, .width = 320 }).mount(scope, cx));
try c.appendChild(a, try W.Card(.{ .title = "No padding", .padded = false, .width = 320 }).mount(scope, cx));
return c;
}Storybook にあるこの story のコードそのままです(zenit 5f9add5+wip 2026-09-30)。W は ui.widgets のことで、col / row / label は Storybook 内の小さなレイアウトヘルパーです。
CardProps
ui.widgets.Cardfn Card(props: CardProps) CardBuilderフィールド
型
デフォルト値
説明
title?[]const u8null标题
subtitle?[]const u8null副标题
variantCardVariant.default.outlined.elevated.default变体
interactiveboolfalse可交互
hoverableboolfalse可悬停
selectedboolfalse选中状态
paddedbooltrue内边距
width?f32null宽度
height?f32null高度
on_click?core.HandlerRefnull点击回调
*Node
ui.widgets.Cardmount は *Node を直接返します。親ノードに append してください。