Skip to content

Commit c54ea2c

Browse files
committed
use grid layout in 300-buttons example
1 parent 750c48b commit c54ea2c

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

examples/300-buttons.zig

+13-8
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,23 @@ pub fn main() !void {
1313
const NUM_BUTTONS = 300;
1414

1515
// This is only used for additional performance
16-
var labelArena = std.heap.ArenaAllocator.init(capy.internal.scratch_allocator);
17-
defer labelArena.deinit();
18-
const labelAllocator = labelArena.child_allocator;
19-
20-
var row = try capy.row(.{ .wrapping = true }, .{});
16+
var label_arena = std.heap.ArenaAllocator.init(capy.internal.scratch_allocator);
17+
defer label_arena.deinit();
18+
const label_allocator = label_arena.child_allocator;
19+
20+
const grid = try capy.grid(.{
21+
.template_columns = &([_]capy.GridLayoutConfig.LengthUnit{.{ .fraction = 1 }} ** 5),
22+
// .template_rows = &.{ .{ .pixels = 150 }, .{ .pixels = 300 } },
23+
.column_spacing = 5,
24+
.row_spacing = 10,
25+
}, .{});
2126
var i: usize = 0;
2227
while (i < NUM_BUTTONS) : (i += 1) {
23-
const buttonLabel = try std.fmt.allocPrintZ(labelAllocator, "Button #{d}", .{i});
24-
try row.add(capy.button(.{ .label = buttonLabel }));
28+
const button_label = try std.fmt.allocPrintZ(label_allocator, "Button #{d}", .{i + 1});
29+
try grid.add(capy.button(.{ .label = button_label }));
2530
}
2631

27-
try window.set(row);
32+
try window.set(capy.alignment(.{}, grid));
2833
window.setPreferredSize(800, 600);
2934
window.show();
3035

0 commit comments

Comments
 (0)