this repo has no description
13
fork

Configure Feed

Select the types of activity you want to include in your feed.

vxfw(SplitView): fix calcs for rhs constraints

+48 -21
+48 -21
src/vxfw/SplitView.zig
··· 18 18 /// Target width to draw at 19 19 width: u16, 20 20 21 + /// Used to calculate mouse events when our constraint is rhs 22 + last_max_width: ?u16 = null, 23 + 21 24 /// Statically allocated children 22 25 children: [2]vxfw.SubSurface = undefined, 23 26 ··· 46 49 const mouse = event.mouse; 47 50 48 51 const separator_col: u16 = switch (self.constrain) { 49 - .lhs => self.width + 1, 50 - .rhs => self.width -| 1, 52 + .lhs => self.width, 53 + .rhs => if (self.last_max_width) |max| 54 + max -| self.width -| 1 55 + else { 56 + ctx.redraw = true; 57 + return; 58 + }, 51 59 }; 52 60 53 61 // If we are on the separator, we always set the mouse shape ··· 74 82 // If pressed, we always keep the mouse shape and we update the width 75 83 if (self.pressed) { 76 84 try ctx.setMouseShape(.@"ew-resize"); 77 - self.width = @max(self.min_width, mouse.col -| 1); 78 - if (self.max_width) |max| { 79 - self.width = @min(self.width, max); 85 + switch (self.constrain) { 86 + .lhs => { 87 + self.width = @max(self.min_width, mouse.col); 88 + if (self.max_width) |max| { 89 + self.width = @min(self.width, max); 90 + } 91 + }, 92 + .rhs => { 93 + const last_max = self.last_max_width orelse return; 94 + self.width = @min(last_max -| self.min_width, last_max -| mouse.col -| 1); 95 + if (self.max_width) |max| { 96 + self.width = @max(self.width, max); 97 + } 98 + }, 80 99 } 81 100 ctx.consume_event = true; 82 101 } ··· 88 107 const max = ctx.max.size(); 89 108 // Constrain width to the max 90 109 self.width = @min(self.width, max.width); 110 + self.last_max_width = max.width; 91 111 92 112 // The constrained side is equal to the width 93 113 const constrained_min: vxfw.Size = .{ .width = self.width, .height = max.height }; 94 114 const constrained_max: vxfw.MaxSize = .{ .width = self.width, .height = max.height }; 95 115 96 - const unconstrained_min: vxfw.Size = .{ .width = max.width - self.width - 2, .height = max.height }; 97 - const unconstrained_max: vxfw.MaxSize = .{ .width = max.width - self.width - 2, .height = max.height }; 116 + const unconstrained_min: vxfw.Size = .{ .width = max.width -| self.width -| 1, .height = max.height }; 117 + const unconstrained_max: vxfw.MaxSize = .{ .width = max.width -| self.width -| 1, .height = max.height }; 98 118 99 119 switch (self.constrain) { 100 120 .lhs => { ··· 109 129 const rhs_surface = try self.rhs.draw(rhs_ctx); 110 130 self.children[1] = .{ 111 131 .surface = rhs_surface, 112 - .origin = .{ .row = 0, .col = self.width + 2 }, 132 + .origin = .{ .row = 0, .col = self.width + 1 }, 113 133 }; 134 + var surface = try vxfw.Surface.initWithChildren(ctx.arena, self.widget(), max, &self.children); 135 + for (0..max.height) |row| { 136 + surface.writeCell(self.width, @intCast(row), .{ 137 + .char = .{ .grapheme = "│", .width = 1 }, 138 + .style = self.style, 139 + }); 140 + } 141 + return surface; 114 142 }, 115 143 .rhs => { 116 144 const lhs_ctx = ctx.withConstraints(unconstrained_min, unconstrained_max); ··· 123 151 const rhs_surface = try self.rhs.draw(rhs_ctx); 124 152 self.children[1] = .{ 125 153 .surface = rhs_surface, 126 - .origin = .{ .row = 0, .col = self.width + 2 }, 154 + .origin = .{ .row = 0, .col = lhs_surface.size.width + 2 }, 127 155 }; 156 + var surface = try vxfw.Surface.initWithChildren(ctx.arena, self.widget(), max, &self.children); 157 + for (0..max.height) |row| { 158 + surface.writeCell(max.width -| self.width -| 1, @intCast(row), .{ 159 + .char = .{ .grapheme = "│", .width = 1 }, 160 + .style = self.style, 161 + }); 162 + } 163 + return surface; 128 164 }, 129 165 } 130 - 131 - var surface = try vxfw.Surface.initWithChildren(ctx.arena, self.widget(), max, &self.children); 132 - for (0..max.height) |row| { 133 - surface.writeCell(self.width + 1, @intCast(row), .{ 134 - .char = .{ .grapheme = "│", .width = 1 }, 135 - .style = self.style, 136 - }); 137 - } 138 - return surface; 139 166 } 140 167 141 168 test SplitView { ··· 175 202 176 203 // Send the widget a mouse press on the separator 177 204 var mouse: vaxis.Mouse = .{ 178 - // The separator is width + 1 179 - .col = split_view.width + 1, 205 + // The separator is at width 206 + .col = split_view.width, 180 207 .row = 0, 181 208 .type = .press, 182 209 .button = .left, ··· 198 225 try split_widget.handleEvent(&ctx, .{ .mouse = mouse }); 199 226 try std.testing.expect(ctx.redraw); 200 227 try std.testing.expect(split_view.pressed); 201 - try std.testing.expectEqual(mouse.col - 1, split_view.width); 228 + try std.testing.expectEqual(mouse.col, split_view.width); 202 229 } 203 230 204 231 test "refAllDecls" {