╭ changed ────────╮ │src/ui/widget.zig│ ╰─────────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │348 var text_box = try wgt.TextBox.init(allocator, empty_label, .{ .border = null, .wrap_kind = .none }); │ │349 errdefer text_box.deinit(allocator); │ │350 return Center.init(allocator, .{ .text_box = text_box }); │ │351 +} │ │352 + │ │353 +pub const ConfirmationButton = struct { │ │354 + label: []const u8, │ │355 + bottom_label: []const u8 = "", │ │356 + action: []const u8 = "submit", │ │357 +}; │ │358 + │ │359 +// "are you sure?" over the buttons, in a form posting to `action` │ │360 +pub fn initConfirmationForm(allocator: std.mem.Allocator, action: []const u8, buttons: []const ConfirmationButton) !Center { │ │361 + var box = try wgt.Box(Widget).init(allocator, .{ .border = null, .round_corners = true, .direction = .vert }); │ │362 + errdefer box.deinit(allocator); │ │363 + box.getFocus().kind = .{ .custom = action }; │ │364 + │ │365 + var prompt = try wgt.Text.init(allocator, "are you sure?"); │ │366 + errdefer prompt.deinit(allocator); │ │367 + try box.children.put(allocator, prompt.getFocus().id, .{ .widget = .{ .text = prompt }, .rect = null, .min_size = null }); │ │368 + │ │369 + for (buttons, 0..) |options, index| { │ │370 + var button = try wgt.TextBox.init(allocator, options.label, .{ .border = .single, .round_corners = true, .wrap_kind = .none, .bottom_label = .{ .text = options.bottom_label } });│ │371 + errdefer button.deinit(allocator); │ │372 + button.getFocus().mode = .all; │ │373 + button.getFocus().kind = .{ .custom = options.action }; │ │374 + try box.children.put(allocator, button.getFocus().id, .{ .widget = .{ .text_box = button }, .rect = null, .min_size = null }); │ │375 + if (index == 0) box.getFocus().child_id = button.getFocus().id; │ │376 + } │ │377 + │ │378 + return Center.init(allocator, .{ .box = box }); │ │379 } │ │380 │ │381 pub const FlowBox = struct { │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯