this repo has no description
13
fork

Configure Feed

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

vxfw: misc size checks for 0 width or height

+71 -32
+8
src/vxfw/RichText.zig
··· 32 32 } 33 33 34 34 pub fn draw(self: *const RichText, ctx: vxfw.DrawContext) Allocator.Error!vxfw.Surface { 35 + if (ctx.max.width != null and ctx.max.width.? == 0) { 36 + return .{ 37 + .size = ctx.min, 38 + .widget = self.widget(), 39 + .buffer = &.{}, 40 + .children = &.{}, 41 + }; 42 + } 35 43 var iter = try SoftwrapIterator.init(self.text, ctx); 36 44 const container_size = self.findContainerSize(&iter); 37 45
+48 -32
src/vxfw/SplitView.zig
··· 21 21 /// Used to calculate mouse events when our constraint is rhs 22 22 last_max_width: ?u16 = null, 23 23 24 - /// Statically allocated children 25 - children: [2]vxfw.SubSurface = undefined, 26 - 27 24 // State 28 25 pressed: bool = false, 29 26 mouse_set: bool = false, ··· 111 108 112 109 // The constrained side is equal to the width 113 110 const constrained_min: vxfw.Size = .{ .width = self.width, .height = max.height }; 114 - const constrained_max: vxfw.MaxSize = .{ .width = self.width, .height = max.height }; 111 + const constrained_max = vxfw.MaxSize.fromSize(constrained_min); 115 112 116 113 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 }; 114 + const unconstrained_max = vxfw.MaxSize.fromSize(unconstrained_min); 115 + 116 + var children = try std.ArrayList(vxfw.SubSurface).initCapacity(ctx.arena, 2); 118 117 119 118 switch (self.constrain) { 120 119 .lhs => { 121 - const lhs_ctx = ctx.withConstraints(constrained_min, constrained_max); 122 - const lhs_surface = try self.lhs.draw(lhs_ctx); 123 - 124 - self.children[0] = .{ 125 - .surface = lhs_surface, 126 - .origin = .{ .row = 0, .col = 0 }, 127 - }; 128 - const rhs_ctx = ctx.withConstraints(unconstrained_min, unconstrained_max); 129 - const rhs_surface = try self.rhs.draw(rhs_ctx); 130 - self.children[1] = .{ 131 - .surface = rhs_surface, 132 - .origin = .{ .row = 0, .col = self.width + 1 }, 133 - }; 134 - var surface = try vxfw.Surface.initWithChildren(ctx.arena, self.widget(), max, &self.children); 120 + if (constrained_max.width.? > 0 and constrained_max.height.? > 0) { 121 + const lhs_ctx = ctx.withConstraints(constrained_min, constrained_max); 122 + const lhs_surface = try self.lhs.draw(lhs_ctx); 123 + children.appendAssumeCapacity(.{ 124 + .surface = lhs_surface, 125 + .origin = .{ .row = 0, .col = 0 }, 126 + }); 127 + } 128 + if (unconstrained_max.width.? > 0 and unconstrained_max.height.? > 0) { 129 + const rhs_ctx = ctx.withConstraints(unconstrained_min, unconstrained_max); 130 + const rhs_surface = try self.rhs.draw(rhs_ctx); 131 + children.appendAssumeCapacity(.{ 132 + .surface = rhs_surface, 133 + .origin = .{ .row = 0, .col = self.width + 1 }, 134 + }); 135 + } 136 + var surface = try vxfw.Surface.initWithChildren( 137 + ctx.arena, 138 + self.widget(), 139 + max, 140 + children.items, 141 + ); 135 142 for (0..max.height) |row| { 136 143 surface.writeCell(self.width, @intCast(row), .{ 137 144 .char = .{ .grapheme = "│", .width = 1 }, ··· 141 148 return surface; 142 149 }, 143 150 .rhs => { 144 - const lhs_ctx = ctx.withConstraints(unconstrained_min, unconstrained_max); 145 - const lhs_surface = try self.lhs.draw(lhs_ctx); 146 - self.children[0] = .{ 147 - .surface = lhs_surface, 148 - .origin = .{ .row = 0, .col = 0 }, 149 - }; 150 - const rhs_ctx = ctx.withConstraints(constrained_min, constrained_max); 151 - const rhs_surface = try self.rhs.draw(rhs_ctx); 152 - self.children[1] = .{ 153 - .surface = rhs_surface, 154 - .origin = .{ .row = 0, .col = lhs_surface.size.width + 1 }, 155 - }; 156 - var surface = try vxfw.Surface.initWithChildren(ctx.arena, self.widget(), max, &self.children); 151 + if (unconstrained_max.width.? > 0 and unconstrained_max.height.? > 0) { 152 + const lhs_ctx = ctx.withConstraints(unconstrained_min, unconstrained_max); 153 + const lhs_surface = try self.lhs.draw(lhs_ctx); 154 + children.appendAssumeCapacity(.{ 155 + .surface = lhs_surface, 156 + .origin = .{ .row = 0, .col = 0 }, 157 + }); 158 + } 159 + if (constrained_max.width.? > 0 and constrained_max.height.? > 0) { 160 + const rhs_ctx = ctx.withConstraints(constrained_min, constrained_max); 161 + const rhs_surface = try self.rhs.draw(rhs_ctx); 162 + children.appendAssumeCapacity(.{ 163 + .surface = rhs_surface, 164 + .origin = .{ .row = 0, .col = unconstrained_max.width.? + 1 }, 165 + }); 166 + } 167 + var surface = try vxfw.Surface.initWithChildren( 168 + ctx.arena, 169 + self.widget(), 170 + max, 171 + children.items, 172 + ); 157 173 for (0..max.height) |row| { 158 174 surface.writeCell(max.width -| self.width -| 1, @intCast(row), .{ 159 175 .char = .{ .grapheme = "│", .width = 1 },
+8
src/vxfw/Text.zig
··· 27 27 } 28 28 29 29 pub fn draw(self: *const Text, ctx: vxfw.DrawContext) Allocator.Error!vxfw.Surface { 30 + if (ctx.max.width != null and ctx.max.width.? == 0) { 31 + return .{ 32 + .size = ctx.min, 33 + .widget = self.widget(), 34 + .buffer = &.{}, 35 + .children = &.{}, 36 + }; 37 + } 30 38 const container_size = self.findContainerSize(ctx); 31 39 32 40 // Create a surface of target width and max height. We'll trim the result after drawing
+7
src/vxfw/vxfw.zig
··· 214 214 .height = self.height.?, 215 215 }; 216 216 } 217 + 218 + pub fn fromSize(other: Size) MaxSize { 219 + return .{ 220 + .width = other.width, 221 + .height = other.height, 222 + }; 223 + } 217 224 }; 218 225 219 226 /// The Widget interface