Skip to content

Commit b0c72cd

Browse files
committed
Better resize event propagation. Should there be code to catch loops?
1 parent 88b6892 commit b0c72cd

File tree

3 files changed

+16
-30
lines changed

3 files changed

+16
-30
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.12.1",
3+
.version = "0.12.2",
44
.fingerprint = 0xe8a81a8d0aa558d5,
55
.minimum_zig_version = "0.15.2",
66
.dependencies = .{

src/engine.zig

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -673,13 +673,20 @@ pub fn Display(comptime T: type) type {
673673
pub fn relayout(display: *Self) void {
674674
if (display.need_relayout == false) return;
675675

676+
trace("relayout", .{});
677+
676678
display.need_relayout = false;
677679

678680
const resized = display.root.type.panel.layout(display, &display.root);
679681
if (resized) {
680682
if (display.on_resized.call(display, &display.root)) {
681683
_ = display.root.type.panel.layout(display, &display.root);
682684
}
685+
const child_resized = display.propagate_resize_event(&display.root);
686+
if (child_resized) {
687+
display.need_relayout = true;
688+
display.relayout();
689+
}
683690
}
684691
}
685692

@@ -1538,14 +1545,16 @@ pub fn Display(comptime T: type) type {
15381545
}
15391546

15401547
/// Trigger `on_resized` events on each node in the tree.
1541-
fn propagate_resize_event(self: *Self, parent: *Entity(T)) bool {
1548+
fn propagate_resize_event(self: *Self, entity: *Entity(T)) bool {
15421549
var updated = false;
1543-
if (parent.visible == .visible)
1544-
updated = parent.on_resized.call(self, parent);
1550+
if (entity.visible == .visible)
1551+
updated = entity.on_resized.call(self, entity);
15451552

1546-
if (parent.type == .panel) {
1547-
for (parent.type.panel.children.items) |entity| {
1548-
updated = self.propagate_resize_event(entity) or updated;
1553+
if (entity.type == .panel) {
1554+
for (entity.type.panel.children.items) |child| {
1555+
if (child.visible == .visible) {
1556+
updated = self.propagate_resize_event(child) or updated;
1557+
}
15491558
}
15501559
}
15511560

src/panel.zig

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -262,26 +262,10 @@ pub fn Panel(comptime T: type) type {
262262
if (entity.maximum.width > 0 and new_width > entity.maximum.width) {
263263
new_width = entity.maximum.width;
264264
}
265-
if (entity.type == .label) {
266-
debug("dolayout label {s} width={d} new_width={d} inner_width={d}", .{
267-
entity.type.label.translated,
268-
entity.rect.width,
269-
new_width,
270-
entity.inner_width(),
271-
});
272-
}
273265
if (entity.rect.width != new_width) {
274266
entity.rect.width = new_width;
275267
child_resized = true;
276268
}
277-
if (entity.type == .label) {
278-
debug("`-layout label {s} width={d} new_width={d} inner_width={d}", .{
279-
entity.type.label.translated,
280-
entity.rect.width,
281-
new_width,
282-
entity.inner_width(),
283-
});
284-
}
285269
},
286270
.shrinks => {
287271
// Shrink to the smallest the children will allow.
@@ -337,13 +321,6 @@ pub fn Panel(comptime T: type) type {
337321
for (self.children.items) |entity| {
338322
if (entity.visible == .hidden) continue;
339323
if (entity.type == .label) {
340-
debug("relayout label {s} width={d} inner_width={d} align={t} grows={t}", .{
341-
entity.type.label.translated,
342-
entity.rect.width,
343-
entity.inner_width(),
344-
entity.child_align.x,
345-
entity.layout.x,
346-
});
347324
const content_size = entity.layout_label(display.scale, available_width);
348325
entity.rect.width = switch (entity.layout.x) {
349326
.grows => available_width + entity.pad.left + entity.pad.right,

0 commit comments

Comments
 (0)