╭ changed ────────╮ │src/ui/widget.zig│ ╰─────────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ 99 } │ │100 } │ │101 }; │ │102 + │ │103 +pub const back_button_width = 3; │ │104 +const back_button_height = 3; │ │105 +const back_kind = "back"; │ │106 + │ │107 +pub fn addBackButton(allocator: std.mem.Allocator, box: *wgt.Box(Widget), session: *ui.Session) !void { │ │108 + if (!session.is_terminal) return; │ │109 + var back = try wgt.TextBox.init(allocator, "←", .{ .border_style = .hidden, .wrap_kind = .none }); │ │110 + errdefer back.deinit(allocator); │ │111 + back.getFocus().kind = .{ .custom = back_kind }; │ │112 + try box.children.put(allocator, back.getFocus().id, .{ │ │113 + .widget = .{ .text_box = back }, │ │114 + .rect = null, │ │115 + .min_size = .{ .width = back_button_width, .height = back_button_height }, │ │116 + .max_size = .{ .width = back_button_width, .height = back_button_height }, │ │117 + .hidden = session.back != .available, │ │118 + }); │ │119 +} │ │120 + │ │121 +pub fn setBackButtonVisible(box: *wgt.Box(Widget), visible: bool) void { │ │122 + for (box.children.values()) |*child| { │ │123 + if (isBackButton(child.widget.getFocus())) { │ │124 + child.hidden = !visible; │ │125 + continue; │ │126 + } │ │127 + switch (child.widget) { │ │128 + .box => |*nested| setBackButtonVisible(nested, visible), │ │129 + else => {}, │ │130 + } │ │131 + } │ │132 +} │ │133 │ │134 +pub fn isBackButton(focus: *Focus) bool { │ │135 + return switch (focus.kind) { │ │136 + .custom => |kind| std.mem.eql(u8, kind, back_kind), │ │137 + else => false, │ │138 + }; │ │139 +} │ │140 + │ │141 // move the focused row in `box` by `delta`, clamped to the ends, scrolling │ │142 // `scroll` to keep it visible. │ │143 pub fn moveRowFocus(box: *wgt.Box(Widget), scroll: *wgt.Scroll(Widget), root_focus: *Focus, delta: isize) void {│ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯