v0.1.0-alpha
官网Home
components/divider
布局与大数据Layout · 45 / 64

Divider

ui.widgets.Divider

水平、垂直和带标签的内容分隔。Horizontal, vertical and labeled separators.

BEHAVIOR CONTRACT

方向、文字位置、颜色与间距来自主题 token。Direction, label position, color and spacing come from theme tokens.

RECORDED INTERACTION

录像展示 solid / dashed、OR label 和竖向分隔。Shows solid / dashed, an OR label and vertical dividers.

examples/storybook/stories.zig:523
// ── Divider ──
pub fn buildDivider(scope: *ui.Scope, cx: *ui.Cx) anyerror!*ui.Node {
    const a = cx.allocator;
    const c = try col(cx, 16);

    // ── 样式:solid / dashed / dotted ──
    try c.appendChild(a, try label(cx, "Styles (solid / dashed / dotted)"));
    inline for (.{ W.divider.DividerVariant.solid, .dashed, .dotted }) |variant| {
        try c.appendChild(a, try W.Divider(.{ .orientation = .horizontal, .variant = variant }).mount(scope, cx));
    }

    // ── 带 label,三种位置 ──
    try c.appendChild(a, try label(cx, "Labeled (left / center / right)"));
    try c.appendChild(a, try W.Divider(.{ .label_text = "LEFT", .label_position = .left }).mount(scope, cx));
    try c.appendChild(a, try W.Divider(.{ .label_text = "OR", .label_position = .center }).mount(scope, cx));
    try c.appendChild(a, try W.Divider(.{ .label_text = "RIGHT", .label_position = .right }).mount(scope, cx));

    // ── 垂直方向 ──
    try c.appendChild(a, try label(cx, "Vertical"));
    const vrow = try ui.box(cx, .{ .direction = .row, .gap = 12, .align_items = .center, .height = .{ .px = 32 } }, .{});
    try vrow.appendChild(a, try ui.text(cx, "Left", .{ .font_size = 13, .color = light.color.fg_primary }));
    try vrow.appendChild(a, try W.Divider(.{ .orientation = .vertical }).mount(scope, cx));
    try vrow.appendChild(a, try ui.text(cx, "Middle", .{ .font_size = 13, .color = light.color.fg_primary }));
    try vrow.appendChild(a, try W.Divider(.{ .orientation = .vertical }).mount(scope, cx));
    try vrow.appendChild(a, try ui.text(cx, "Right", .{ .font_size = 13, .color = light.color.fg_primary }));
    try c.appendChild(a, vrow);
    return c;
}
在 GitHub 查看源码View source on GitHubexamples/storybook/stories.zig:523

这是 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.

zenit · 双授权Dual-licensed开源项目可按 GPL-3.0-only 免费使用;闭源或商业产品需要商业授权。Free for open-source projects under GPL-3.0-only; closed-source or commercial products need a commercial license.可联系作者:Contact the author: zongyi.xzy#gmail.com(# 换成 @) (replace # with @)zenit 5f9add5+wip 2026-09-30