Skip to content

Commit bbdeb32

Browse files
committed
fix layouting
1 parent 0b32562 commit bbdeb32

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

examples/border-layout.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const capy = @import("capy");
33
pub usingnamespace capy.cross_platform;
44

55
pub fn main() !void {
6-
try capy.backend.init();
6+
try capy.init();
77

88
var window = try capy.Window.init();
99
try window.set(capy.column(.{}, .{

src/components/Alignment.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ pub const Alignment = struct {
9494
const preferred_size = self.child.get().getPreferredSize(available);
9595
const final_size = Size.intersect(preferred_size, available);
9696

97-
const x: u32 = @intFromFloat(alignX * available.width - final_size.width);
98-
const y: u32 = @intFromFloat(alignY * available.height - final_size.height);
97+
const x: u32 = @intFromFloat(alignX * @max(0, available.width - final_size.width));
98+
const y: u32 = @intFromFloat(alignY * @max(0, available.height - final_size.height));
9999

100100
peer.move(widget_peer, x, y);
101101
peer.resize(widget_peer, @intFromFloat(final_size.width), @intFromFloat(final_size.height));

src/containers.zig

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub fn ColumnLayout(peer: Callbacks, widgets: []*Widget) void {
4848
const config = peer.getLayoutConfig(ColumnRowConfig);
4949
const spacing: f32 = @floatFromInt(config.spacing);
5050

51-
const totalAvailableHeight = peer.getSize(peer.userdata).height - @as(f32, @floatFromInt((widgets.len -| 1) * config.spacing));
51+
const totalAvailableHeight: f32 = @max(0, peer.getSize(peer.userdata).height - @as(f32, @floatFromInt((widgets.len -| 1) * config.spacing)));
5252

5353
var childHeight = if (expandedCount == 0) 0 else totalAvailableHeight / @as(f32, @floatFromInt(expandedCount));
5454
for (widgets) |widget| {
@@ -81,7 +81,7 @@ pub fn ColumnLayout(peer: Callbacks, widgets: []*Widget) void {
8181

8282
const available = Size{
8383
.width = peer.getSize(peer.userdata).width,
84-
.height = if (widget.container_expanded) childHeight else peer.getSize(peer.userdata).height - childY,
84+
.height = if (widget.container_expanded) childHeight else @max(0, peer.getSize(peer.userdata).height - childY),
8585
};
8686
const preferred = widget.getPreferredSize(available);
8787
const size = blk: {
@@ -124,7 +124,7 @@ pub fn RowLayout(peer: Callbacks, widgets: []*Widget) void {
124124
const config = peer.getLayoutConfig(ColumnRowConfig);
125125
const spacing: f32 = @floatFromInt(config.spacing);
126126

127-
const totalAvailableWidth = peer.getSize(peer.userdata).width - @as(f32, @floatFromInt((widgets.len -| 1) * config.spacing));
127+
const totalAvailableWidth: f32 = @max(0, peer.getSize(peer.userdata).width - @as(f32, @floatFromInt((widgets.len -| 1) * config.spacing)));
128128

129129
var childWidth = if (expandedCount == 0) 0 else totalAvailableWidth / @as(f32, @floatFromInt(expandedCount));
130130
for (widgets) |widget| {
@@ -156,7 +156,7 @@ pub fn RowLayout(peer: Callbacks, widgets: []*Widget) void {
156156
}
157157

158158
const available = Size{
159-
.width = if (widget.container_expanded) childWidth else peer.getSize(peer.userdata).width - childX,
159+
.width = if (widget.container_expanded) childWidth else @max(0, peer.getSize(peer.userdata).width - childX),
160160
.height = peer.getSize(peer.userdata).height,
161161
};
162162
const preferred = widget.getPreferredSize(available);

0 commit comments

Comments
 (0)