ScrollArea
ui.widgets.mountScrollAreaCustom-drawn scrolling, scrollbars and programmatic positioning.
BEHAVIOR CONTRACT
Wheel / trackpad, clamping, momentum, scrollbar, scrollIntoView and pixel alignment share state.
RECORDED INTERACTION
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;
}The story's verbatim source from the Storybook (zenit 4c50245 2026-10-01). W is ui.widgets; col / row / label are small Storybook layout helpers.
ScrollAreaProps
ui.widgets.mountScrollAreafn mountScrollArea(props: ScrollAreaProps, scope: *Scope, cx: *Cx) !ScrollAreaResultField
Type
Default
Description
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.mountScrollAreaField
Type
Default
Description
container*Node—
—
content*Node—
—
state*ScrollState—
—