components/scrollarea
布局与大数据 · 50 / 64

ScrollArea

ui.widgets.mountScrollArea

自绘滚动、滚动条与程序化定位。

BEHAVIOR CONTRACT

wheel / trackpad、clamp、momentum、scrollbar、scrollIntoView 和像素对齐共享 state。

RECORDED INTERACTION

Harness 在内容区域滚动并记录 thumb 位移。

examples/storybook/stories.zig:2986
// ── 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;
}
在 GitHub 查看源码examples/storybook/stories.zig:2986

这是 Storybook 中该 story 的原样代码(zenit 5f9add5+wip 2026-09-30)。其中 W 即 ui.widgets,col / row / label 是 Storybook 内的布局小工具。

zenit · 双授权开源项目可按 GPL-3.0-only 免费使用;闭源或商业产品需要商业授权。可联系作者:zongyi.xzy#gmail.com(# 换成 @)zenit 5f9add5+wip 2026-09-30