ScrollArea
ui.widgets.mountScrollArea自绘滚动、滚动条与程序化定位。
BEHAVIOR CONTRACT
wheel / trackpad、clamp、momentum、scrollbar、scrollIntoView 和像素对齐共享 state。
RECORDED INTERACTION
Harness 在内容区域滚动并记录 thumb 位移。
// ── 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 内的布局小工具。
ScrollAreaProps
ui.widgets.mountScrollAreafn mountScrollArea(props: ScrollAreaProps, scope: *Scope, cx: *Cx) !ScrollAreaResult字段
类型
默认值
说明
width?f32null—
height?f32null—
directionScrollDirection.vertical.horizontal.both.vertical—
content_height?f32null—
content_width?f32null—
scroll_speedf321滚动速度乘数(macOS scrollingDelta 已是像素值,默认 1.0)
paddingPaddingPadding.ZERO—
backgroundColorColor.TRANSPARENT—
state_id?u64null自定义状态 ID(用于跨实例复用或区分滚动状态)
rubber_band_ybooltrue垂直方向是否启用 rubber band(果冻回弹)效果
rubber_band_xbooltrue水平方向是否启用 rubber band(果冻回弹)效果
ScrollAreaResult
ui.widgets.mountScrollArea字段
类型
默认值
说明
container*Node—
—
content*Node—
—
state*ScrollState—
—