this repo has no description
13
fork

Configure Feed

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

vxfw: fix SizedBox constraints

Replaces: #189

+15 -14
+15 -14
src/vxfw/SizedBox.zig
··· 20 20 fn typeErasedDrawFn(ptr: *anyopaque, ctx: vxfw.DrawContext) Allocator.Error!vxfw.Surface { 21 21 const self: *const SizedBox = @ptrCast(@alignCast(ptr)); 22 22 const max: vxfw.MaxSize = .{ 23 - .width = if (ctx.max.width) |max_w| @min(max_w, self.size.width) else self.size.width, 24 - .height = if (ctx.max.height) |max_h| @min(max_h, self.size.height) else self.size.height, 23 + .width = if (ctx.max.width) |max_w| max_w else self.size.width, 24 + .height = if (ctx.max.height) |max_h| max_h else self.size.height, 25 25 }; 26 26 const min: vxfw.Size = .{ 27 - .width = @max(ctx.min.width, max.width.?), 28 - .height = @max(ctx.min.height, max.height.?), 27 + .width = @min(@max(ctx.min.width, self.size.width), max.width.?), 28 + .height = @min(@max(ctx.min.height, self.size.height), max.height.?), 29 29 }; 30 30 return self.child.draw(ctx.withConstraints(min, max)); 31 31 } ··· 79 79 }; 80 80 81 81 const box_widget = sized_box.widget(); 82 - _ = try box_widget.draw(draw_ctx); 82 + { 83 + const result = try box_widget.draw(draw_ctx); 84 + // The sized box is smaller than the constraints, so we should be the desired size 85 + try std.testing.expectEqual(sized_box.size, result.size); 86 + } 83 87 84 - // The sized box is smaller than the constraints, so we should be the desired size 85 - try std.testing.expectEqual(sized_box.size, test_widget.min); 86 - try std.testing.expectEqual(sized_box.size, test_widget.max.size()); 87 - 88 - draw_ctx.max.height = 8; 89 - _ = try box_widget.draw(draw_ctx); 90 - // The sized box is smaller than the constraints, so we should be that size 91 - try std.testing.expectEqual(@as(vxfw.Size, .{ .width = 10, .height = 8 }), test_widget.min); 92 - try std.testing.expectEqual(@as(vxfw.Size, .{ .width = 10, .height = 8 }), test_widget.max.size()); 88 + { 89 + draw_ctx.max.height = 8; 90 + const result = try box_widget.draw(draw_ctx); 91 + // The sized box is smaller than the constraints, so we should be that size 92 + try std.testing.expectEqual(@as(vxfw.Size, .{ .width = 10, .height = 8 }), result.size); 93 + } 93 94 94 95 draw_ctx.max.width = 8; 95 96 _ = try box_widget.draw(draw_ctx);