Skip to content

Commit

Permalink
use grid layout in 300-buttons example
Browse files Browse the repository at this point in the history
  • Loading branch information
zenith391 committed Jan 1, 2025
1 parent 750c48b commit c54ea2c
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions examples/300-buttons.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,23 @@ pub fn main() !void {
const NUM_BUTTONS = 300;

// This is only used for additional performance
var labelArena = std.heap.ArenaAllocator.init(capy.internal.scratch_allocator);
defer labelArena.deinit();
const labelAllocator = labelArena.child_allocator;

var row = try capy.row(.{ .wrapping = true }, .{});
var label_arena = std.heap.ArenaAllocator.init(capy.internal.scratch_allocator);
defer label_arena.deinit();
const label_allocator = label_arena.child_allocator;

const grid = try capy.grid(.{
.template_columns = &([_]capy.GridLayoutConfig.LengthUnit{.{ .fraction = 1 }} ** 5),
// .template_rows = &.{ .{ .pixels = 150 }, .{ .pixels = 300 } },
.column_spacing = 5,
.row_spacing = 10,
}, .{});
var i: usize = 0;
while (i < NUM_BUTTONS) : (i += 1) {
const buttonLabel = try std.fmt.allocPrintZ(labelAllocator, "Button #{d}", .{i});
try row.add(capy.button(.{ .label = buttonLabel }));
const button_label = try std.fmt.allocPrintZ(label_allocator, "Button #{d}", .{i + 1});
try grid.add(capy.button(.{ .label = button_label }));
}

try window.set(row);
try window.set(capy.alignment(.{}, grid));
window.setPreferredSize(800, 600);
window.show();

Expand Down

0 comments on commit c54ea2c

Please sign in to comment.