RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
Allow multiple Files sidebar sections to expand
Mel5ac17ed359b8
diff --git a/src/files/app.zig b/src/files/app.zigindex 2af0c65..cae9d78 100644--- a/src/files/app.zig+++ b/src/files/app.zig@@ -122,11 +122,8 @@ pub const App = struct {show_hidden: bool = false,list_view: bool = false,non_git_list_view: ?bool = null,- /// The sidebar accordion selection. Git's branch-list expansion remains- /// independent in `git_expanded`.- sidebar_section: app_model.SidebarSection = .places,- /// Set only after an explicit section choice; later activity may respect it.- sidebar_section_selected: bool = false,+ /// Each sidebar section expands independently. Places is open by default.+ sidebar_expanded: [4]bool = .{ true, false, false, false },git_expanded: bool = true,/// The "Git View" checkbox: off shows a repository like any other folder.git_view: bool = true,diff --git a/src/files/app_model.zig b/src/files/app_model.zigindex 534c9c7..85a537c 100644--- a/src/files/app_model.zig+++ b/src/files/app_model.zig@@ -122,20 +122,19 @@ pub const SidebarLayout = struct {cards: [4]SidebarCardGeometry,- /// Positions visible cards in section order. Hidden cards consume no- /// space; only the selected section receives its body height.+ /// Positions visible cards in section order. Every expanded card+ /// receives its body height independently.pub fn init(top: i32,body_heights: [4]i32,visible: [4]bool,- expanded_section: SidebarSection,+ expanded_sections: [4]bool,) SidebarLayout {var result: SidebarLayout = .{ .cards = undefined };var y = top;for (0..4) |i| {- const section: SidebarSection = @enumFromInt(i);- const expanded = visible[i] and section == expanded_section;+ const expanded = visible[i] and expanded_sections[i];const card: SidebarCardGeometry = .{.y = y,.header_height = header_height,diff --git a/src/files/app_pointer.zig b/src/files/app_pointer.zigindex 91d2ffb..1b06082 100644--- a/src/files/app_pointer.zig+++ b/src/files/app_pointer.zig@@ -507,8 +507,8 @@ pub fn handleButton(self: *App, button: u32, pressed: bool) void {}if (button == 0x110) {if (self.sidebarHeaderAt(x, y)) |section| {- self.sidebar_section = section;- self.sidebar_section_selected = true;+ const index = @intFromEnum(section);+ self.sidebar_expanded[index] = !self.sidebar_expanded[index];self.clampSidebarScroll();self.invalidate();return;diff --git a/src/files/app_sidebar_paint.zig b/src/files/app_sidebar_paint.zigindex 348f084..e59b293 100644--- a/src/files/app_sidebar_paint.zig+++ b/src/files/app_sidebar_paint.zig@@ -119,8 +119,8 @@ fn drawSidebarRowProximity();}-/// The shared accordion geometry. Body sizes come from the existing section-/// implementations; only the selected visible card receives its body.+/// The shared accordion geometry. Every expanded visible card receives+/// its body, with all cards stacked in section order.pub fn sidebarLayout(self: *App) app_model.SidebarLayout {const top = self.contentTop() - self.sidebar_scroll;const pin_bottom = self.pinRowY(self.pins.items.items.len);@@ -138,7 +138,7 @@ pub fn sidebarLayout(self: *App) app_model.SidebarLayout {top,.{ places_body, disks_body, git_body, transfers_body },.{ true, true, self.repository() != null, self.torrentSidebarHeight() > 0 },- self.sidebar_section,+ self.sidebar_expanded,);}diff --git a/src/files/app_sidebar_tests.zig b/src/files/app_sidebar_tests.zigindex 6117453..2451fbe 100644--- a/src/files/app_sidebar_tests.zig+++ b/src/files/app_sidebar_tests.zig@@ -19,43 +19,45 @@ test "sidebar accordion defaults to Places without changing Git branch expansionvar app = try testApp();defer app.deinit();- try std.testing.expectEqual(app_model.SidebarSection.places, app.sidebar_section);- try std.testing.expect(!app.sidebar_section_selected);+ try std.testing.expect(app.sidebar_expanded[0]);+ try std.testing.expect(!app.sidebar_expanded[1]);+ try std.testing.expect(!app.sidebar_expanded[2]);+ try std.testing.expect(!app.sidebar_expanded[3]);try std.testing.expect(app.git_expanded);}-test "sidebar layout uses shared headers and only expanded visible body" {+test "sidebar layout stacks every independently expanded visible body" {const body_heights = [_]i32{ 80, 40, 64, 120 };const visible = [_]bool{ true, true, false, true };- const places_expanded = app_model.SidebarLayout.init(+ const places_and_disks_expanded = app_model.SidebarLayout.init(100,body_heights,visible,- .places,+ .{ true, true, true, false },);- const places = places_expanded.cards[@intFromEnum(app_model.SidebarSection.places)];- const disks = places_expanded.cards[@intFromEnum(app_model.SidebarSection.disks)];- const git = places_expanded.cards[@intFromEnum(app_model.SidebarSection.git)];- const transfers = places_expanded.cards[@intFromEnum(app_model.SidebarSection.transfers)];+ const places = places_and_disks_expanded.cards[@intFromEnum(app_model.SidebarSection.places)];+ const disks = places_and_disks_expanded.cards[@intFromEnum(app_model.SidebarSection.disks)];+ const git = places_and_disks_expanded.cards[@intFromEnum(app_model.SidebarSection.git)];+ const transfers = places_and_disks_expanded.cards[@intFromEnum(app_model.SidebarSection.transfers)];try std.testing.expectEqual(@as(i32, 100), places.y);try std.testing.expectEqual(@as(i32, 112), places.height());try std.testing.expectEqual(@as(i32, 220), disks.y);- try std.testing.expectEqual(@as(i32, 32), disks.height());+ try std.testing.expectEqual(@as(i32, 72), disks.height());try std.testing.expect(!git.visible);- try std.testing.expectEqual(@as(i32, 260), transfers.y);+ try std.testing.expectEqual(@as(i32, 300), transfers.y);try std.testing.expectEqual(@as(i32, 32), transfers.height());- const transfers_expanded = app_model.SidebarLayout.init(+ const only_transfers_expanded = app_model.SidebarLayout.init(100,body_heights,visible,- .transfers,+ .{ false, false, false, true },);- const collapsed_places = transfers_expanded.cards[@intFromEnum(app_model.SidebarSection.places)];- const collapsed_disks = transfers_expanded.cards[@intFromEnum(app_model.SidebarSection.disks)];- const expanded_transfers = transfers_expanded.cards[@intFromEnum(app_model.SidebarSection.transfers)];+ const collapsed_places = only_transfers_expanded.cards[@intFromEnum(app_model.SidebarSection.places)];+ const collapsed_disks = only_transfers_expanded.cards[@intFromEnum(app_model.SidebarSection.disks)];+ const expanded_transfers = only_transfers_expanded.cards[@intFromEnum(app_model.SidebarSection.transfers)];try std.testing.expectEqual(@as(i32, 32), collapsed_places.height());try std.testing.expectEqual(@as(i32, 140), collapsed_disks.y);@@ -63,14 +65,14 @@ test "sidebar layout uses shared headers and only expanded visible body" {try std.testing.expectEqual(@as(i32, 152), expanded_transfers.height());}-test "sidebar header clicks select sections without collapsing the active card" {+test "sidebar header clicks independently toggle sections" {var app = try testApp();defer app.deinit();app.w = 800;app.h = 1000;- try std.testing.expectEqual(app_model.SidebarSection.places, app.sidebar_section);- try std.testing.expect(!app.sidebar_section_selected);+ try std.testing.expect(app.sidebar_expanded[0]);+ try std.testing.expect(!app.sidebar_expanded[1]);const layout = app.sidebarLayout();const disks = layout.cards[@intFromEnum(app_model.SidebarSection.disks)];@@ -82,18 +84,19 @@ test "sidebar header clicks select sections without collapsing the active card"app.handleMotion(x, y);app.handleButton(0x110, true);- try std.testing.expectEqual(app_model.SidebarSection.disks, app.sidebar_section);- try std.testing.expect(app.sidebar_section_selected);+ try std.testing.expect(app.sidebar_expanded[0]);+ try std.testing.expect(app.sidebar_expanded[1]);+ try std.testing.expect(app.sidebarLayout().cards[@intFromEnum(app_model.SidebarSection.places)].expanded);try std.testing.expect(app.sidebarLayout().cards[@intFromEnum(app_model.SidebarSection.disks)].expanded);- // Recompute its position after Places collapses. Clicking the active- // header is idempotent, not a collapse toggle.+ // Clicking Disks again collapses only Disks; Places stays open.const selected_disks = app.sidebarLayout().cards[@intFromEnum(app_model.SidebarSection.disks)];const selected_y: f64 = @floatFromInt(selected_disks.y + @divTrunc(selected_disks.header_height, 2));app.handleMotion(x, selected_y);app.handleButton(0x110, true);- try std.testing.expectEqual(app_model.SidebarSection.disks, app.sidebar_section);- try std.testing.expect(app.sidebarLayout().cards[@intFromEnum(app_model.SidebarSection.disks)].expanded);+ try std.testing.expect(app.sidebar_expanded[0]);+ try std.testing.expect(!app.sidebar_expanded[1]);+ try std.testing.expect(app.sidebarLayout().cards[@intFromEnum(app_model.SidebarSection.places)].expanded);const body_y: f64 = @floatFromInt(selected_disks.y + selected_disks.header_height + 1);try std.testing.expectEqual(@as(?app_model.SidebarSection, null), app.sidebarHeaderAt(x, body_y));@@ -112,11 +115,10 @@ test "sidebar body geometry rejects hidden areas and translates legacy section ctry std.testing.expectEqual(@as(?f64, @floatFromInt(places_source_top)), app.sidebarBodyY(.places, 70, @floatFromInt(places.y + places.header_height)));try std.testing.expectEqual(@as(?f64, null), app.sidebarBodyY(.places, 70, @as(f64, @floatFromInt(places.y + places.header_height + places.body_height))));- // The compact Disks header is not an interactive body while Places owns- // the accordion, even if a stale legacy device row would overlap it.+ // A collapsed Disks body is not interactive while Places remains open.try std.testing.expectEqual(@as(?f64, null), app.sidebarBodyY(.disks, 70, places_y));- app.sidebar_section = .disks;+ app.sidebar_expanded[@intFromEnum(app_model.SidebarSection.disks)] = true;const disks = app.sidebarLayout().cards[@intFromEnum(app_model.SidebarSection.disks)];const disks_y = @as(f64, @floatFromInt(disks.y + disks.header_height)) + 5;const disks_source_top = app.pinRowY(app.pins.items.items.len) + 24;@@ -375,8 +377,8 @@ test "Sidebar separates Disks from Places; only mounted volumes eject" {const step = app.placeStep();try std.testing.expectEqual(last_place_y + 44 + step, app.placeY(mounted));try std.testing.expectEqual(app.placeY(mounted) + step, app.placeY(unmounted));- // Places is expanded by default; the collapsed Disks card keeps its- // compact height when volumes are added.+ // Places is expanded by default; collapsed Disks keeps its compact+ // height when volumes are added.try std.testing.expectEqual(extent, app.sidebarExtent());const collapsed_disks = app.sidebarLayout().cards[@intFromEnum(app_model.SidebarSection.disks)];@@ -384,7 +386,7 @@ test "Sidebar separates Disks from Places; only mounted volumes eject" {try std.testing.expectEqual(@as(?usize, null), app.placeAt(70, collapsed_body_y));try std.testing.expectEqual(@as(?usize, null), app.pinSlotAt(70, collapsed_body_y));- app.sidebar_section = .disks;+ app.sidebar_expanded[@intFromEnum(app_model.SidebarSection.disks)] = true;const disks = app.sidebarLayout().cards[@intFromEnum(app_model.SidebarSection.disks)];const screen_body_top = disks.y + disks.header_height;const source_body_top = app.pinRowY(app.pins.items.items.len) + 24;diff --git a/src/files/app_views_tests.zig b/src/files/app_views_tests.zigindex a9c65dc..f57432c 100644--- a/src/files/app_views_tests.zig+++ b/src/files/app_views_tests.zig@@ -64,7 +64,7 @@ test "Git layout has two columns, scrollable sidebar and display-only deleted roapp.changed_only = true;app.search.text.clearRetainingCapacity();// Git's body follows its shared accordion header geometry.- app.sidebar_section = .git;+ app.sidebar_expanded[@intFromEnum(@import("app_model.zig").SidebarSection.git)] = true;const git_geometry = app.sidebarLayout().cards[@intFromEnum(@import("app_model.zig").SidebarSection.git)];try std.testing.expect(git_geometry.visible and git_geometry.expanded);try std.testing.expectEqual(