Skip to content

Commit daccd14

Browse files
author
Jay
committed
Support panel .centre align
1 parent 0e29329 commit daccd14

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.{
22
.name = .engine,
3-
.version = "0.7.8",
3+
.version = "0.7.9",
44
.fingerprint = 0xe8a81a8d0aa558d5,
55
.minimum_zig_version = "0.15.2",
66
.dependencies = .{

src/engine.zig

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3302,22 +3302,29 @@ pub const Display = struct {
33023302
}
33033303

33043304
inline fn place_children_centred(_: *Display, parent: *Element) void {
3305+
const parent_width = parent.rect.width - parent.pad.left - parent.pad.right;
3306+
const parent_height = parent.rect.height - parent.pad.top - parent.pad.bottom;
3307+
33053308
// First pass just does a layout assuming top/left positioning.
33063309
for (parent.type.panel.children.items) |child| {
33073310
if (child.layout.position == .float) continue;
33083311
if (child.visible == .hidden) continue;
33093312
if (child.type == .expander) continue;
33103313

3311-
child.rect.x = parent.rect.width / 2 - child.rect.width / 2;
3312-
child.rect.y = parent.rect.height / 2 - child.rect.height / 2;
3314+
child.rect.x = parent.rect.x + parent.pad.left + (parent_width / 2 - child.rect.width / 2);
3315+
child.rect.y = parent.rect.y + parent.pad.top + (parent_height / 2 - child.rect.height / 2);
33133316
if (dev_build or dev_mode) {
3314-
err("relayout centre {s} puts child {s} size={d}x{d} at={d}x{d}", .{
3317+
err("in parent {s} ({d}x{d} {d}x{d}) centre {s} at={d}x{d} size={d}x{d}", .{
33153318
parent.name,
3319+
parent.rect.x,
3320+
parent.rect.y,
3321+
parent.rect.width,
3322+
parent.rect.height,
33163323
child.name,
3317-
child.rect.width,
3318-
child.rect.height,
33193324
child.rect.x,
33203325
child.rect.y,
3326+
child.rect.width,
3327+
child.rect.height,
33213328
});
33223329
}
33233330
}

0 commit comments

Comments
 (0)