ScrollArea
ui.widgets.mountScrollArea自绘滚动、滚动条与程序化定位。Custom-drawn scrolling, scrollbars and programmatic positioning.
BEHAVIOR CONTRACT
wheel / trackpad、clamp、momentum、scrollbar、scrollIntoView 和像素对齐共享 state。Wheel / trackpad, clamping, momentum, scrollbar, scrollIntoView and pixel alignment share state.
RECORDED INTERACTION
Harness 在内容区域滚动并记录 thumb 位移。The harness scrolls the content and records the thumb moving.
// ── ScrollArea ──
pub fn buildScrollArea(scope: *ui.Scope, cx: *ui.Cx) anyerror!*ui.Node {
const a = cx.allocator;
const sa = try W.mountScrollArea(.{ .width = 320, .height = 320, .direction = .vertical }, scope, cx);
var i: usize = 0;
while (i < 40) : (i += 1) {
var buf: [32]u8 = undefined;
const txt = try std.fmt.bufPrint(&buf, "Scrollable line {d}", .{i});
try sa.content.appendChild(a, try ui.text(cx, txt, .{ .font_size = 13, .color = light.color.fg_primary }));
}
return sa.container;
}这是 Storybook 中该 story 的原样代码(zenit 5f9add5+wip 2026-09-30)。其中 W 即 ui.widgets,col / row / label 是 Storybook 内的布局小工具。The story's verbatim source from the Storybook (zenit 5f9add5+wip 2026-09-30). W is ui.widgets; col / row / label are small Storybook layout helpers.