╭──────────╮ │← previous│ ╰──────────╯ ╭ changed ──────╮ │src/ui/Home.zig│ ╰───────────────╯ ╭──────────────────────────────────────╮ │66 pub const View = struct { │ │67 box: wgt.Box(ui.Widget), │ │68 data: *const Self, │ │69 + session: *ui.Session, │ │70 │ │71 const header_index: usize = 0;│ │72 const stack_index: usize = 1; │ ╰──────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │73 │ │62 - pub fn init(allocator: std.mem.Allocator, data: *const Self) !View { │ │74 + pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { │ │75 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert });│ │76 errdefer box.deinit(); │ │77 │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │78 + // build the header first so we can grab the users-tab focus id and │ │79 + // hand it to login/logout │ │80 + var users_tab_id: usize = undefined; │ │81 { │ │67 - var header_view = try Header.View.init(allocator, &data.header); │ │82 + var header_view = try Header.View.init(allocator, &data.header, session); │ │83 errdefer header_view.deinit(); │ │84 + users_tab_id = header_view.tab_ids[0]; │ │85 try box.children.put(allocator, header_view.getFocus().id, .{ .widget = .{ .home_header = header_view }, .rect = null, .min_size = null });│ │86 } │ │87 │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ 99 var repos_view = try Repos.View.init(allocator, &data.repos); │ │100 errdefer repos_view.deinit(); │ │101 try stack.children.put(stack.allocator, repos_view.getFocus().id, .{ .home_repos = repos_view }); │ │102 + } │ │103 + │ │104 + { │ │105 + var auth_view = try Auth.View.init(allocator, &data.auth, session, users_tab_id); │ │106 + errdefer auth_view.deinit(); │ │107 + try stack.children.put(stack.allocator, auth_view.getFocus().id, .{ .home_auth = auth_view }); │ │108 } │ │109 │ │110 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null });│ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────╮ │113 var self = View{ │ │114 .box = box, │ │115 .data = data, │ │116 + .session = session, │ │117 }; │ │118 self.getFocus().child_id = box.children.keys()[header_index];│ │119 return self; │ ╰──────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────╮ │127 self.clearGrid(); │ │128 const header = &self.box.children.values()[header_index].widget.home_header;│ │129 const stack = &self.box.children.values()[stack_index].widget.stack; │ │130 + │ │131 + // each header tab maps 1:1 to a stack child by position │ │132 if (header.getSelectedIndex()) |index| { │ │133 stack.getFocus().child_id = stack.children.keys()[index]; │ │134 } │ ╰─────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────╮ │141 const child = &self.box.children.values()[current_index].widget;│ │142 var index = current_index; │ │143 │ │119 - // arrow up/down (and scroll wheel) move focus between the │ │120 - // header and the stack below it, matching radargit's GitUI. │ │144 const Direction = enum { up, down, none }; │ │145 const direction: Direction = switch (key) { │ │146 .arrow_up => .up, │ ╰─────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────╮ │163 const at_top = switch (selected_widget.*) { │ │164 .home_users => |*v| v.getSelectedIndex() == 0,│ │165 .home_repos => |*v| v.getSelectedIndex() == 0,│ │166 + .home_auth => |*v| v.getSelectedIndex() == 0, │ │167 else => false, │ │168 }; │ │169 if (at_top) { │ ╰───────────────────────────────────────────────────────────────────────────────────────────╯ ╭ changed ─────────────╮ │src/ui/Home/Header.zig│ ╰──────────────────────╯ ╭─────────────────────────────────────────────────╮ │ 8 const Grid = xitui.grid.Grid; │ │ 9 const Focus = xitui.focus.Focus; │ │10 │ │11 -const Self = @This(); │ │11 +pub const AuthTab = @import("./AuthTab.zig");│ │12 │ │13 -const Tab = enum { users, repos }; │ │13 +auth_tab: AuthTab, │ │14 + │ │15 +const Self = @This(); │ │16 │ │17 pub fn init() Self { │ │16 - return .{}; │ │18 + return .{ .auth_tab = AuthTab.init() }; │ │19 } │ │20 │ │21 pub const View = struct { │ ╰─────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │22 box: wgt.Box(ui.Widget), │ │23 data: *const Self, │ │24 + tab_ids: [3]usize, │ │25 │ │23 - pub fn init(allocator: std.mem.Allocator, data: *const Self) !View { │ │26 + const auth_tab_index: usize = 2; │ │27 + // the auth slot must fit either "login" or "logout" │ │28 + const auth_tab_min_width: usize = @as(usize, "logout".len) + 2; │ │29 + │ │30 + pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { │ │31 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz });│ │32 errdefer box.deinit(); │ │33 │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────╮ │next →│ ╰──────╯