From f95de2283c3499920eb563d4acdf689f51645949 Mon Sep 17 00:00:00 2001 From: Robin Schreiber Date: Tue, 28 Jan 2025 19:36:34 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8:=20avoid=20overriding=20extent=20p?= =?UTF-8?q?rop=20during=20layout=20application?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously some layout applications, including text layout, would cause extent, height or width properies in style policies to no longer apply, although not warranted. --- lively.morphic/components/policy.js | 8 +++++++- lively.morphic/layout.js | 10 +++++----- lively.morphic/text/morph.js | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lively.morphic/components/policy.js b/lively.morphic/components/policy.js index 943ec26e3e..d775eaf861 100644 --- a/lively.morphic/components/policy.js +++ b/lively.morphic/components/policy.js @@ -454,7 +454,12 @@ export class StylePolicy { if (targetMorph._lastIndex && !obj.equals(targetMorph._lastIndex, currIndex)) { const limitExtent = bpStore.getLimitExtent(currIndex); const actualExtent = targetMorph.extent; - targetMorph.withMetaDo({ metaInteraction: true, reconcileChanges: false, doNotFit: true }, () => { + targetMorph.withMetaDo({ + metaInteraction: true, // do not record + reconcileChanges: false, + doNotFit: true, + doNotOverride: true + }, () => { const origLayoutableFlag = targetMorph.isLayoutable; targetMorph.isLayoutable = false; // avoid any resizing interference here targetMorph.extent = limitExtent; @@ -1574,6 +1579,7 @@ export class PolicyApplicator extends StylePolicy { */ onMorphChange (changedMorph, change) { if (change.meta?.metaInteraction || + change.meta?.doNotOverride || !this.targetMorph || this.isCurrentlyAnimated(changedMorph) ) return; diff --git a/lively.morphic/layout.js b/lively.morphic/layout.js index 6c5eda505f..86d619dcd6 100644 --- a/lively.morphic/layout.js +++ b/lively.morphic/layout.js @@ -834,10 +834,10 @@ export class TilingLayout extends Layout { aMorph._yogaNode = Yoga.Node.create(yogaConfig); if (aMorph.isText) { aMorph._yogaNode.setMeasureFunc((width, widthMode, height, heightMode) => { - if (aMorph.fixedWidth && widthMode !== 0) aMorph.width = width; - if (aMorph.fixedHeight && heightMode !== 0) aMorph.height = height; + if (aMorph.fixedWidth && widthMode !== 0) aMorph.withMetaDo({ doNotOverride: true }, () => aMorph.width = width); + if (aMorph.fixedHeight && heightMode !== 0) aMorph.withMetaDo({ doNotOverride: true }, () => aMorph.height = height); if (!aMorph.visible) return { width: aMorph.width, height: aMorph.height }; - if (!aMorph.fixedWidth || !aMorph.fixedHeight) aMorph.withMetaDo({ doNotFit: false }, () => aMorph.fit()); + if (!aMorph.fixedWidth || !aMorph.fixedHeight) aMorph.withMetaDo({ doNotFit: false, skipRerender: true }, () => aMorph.fitIfNeeded()); if (!aMorph.fixedWidth) width = aMorph.width; if (!aMorph.fixedHeight) height = aMorph.height; return { width, height }; @@ -934,10 +934,10 @@ export class TilingLayout extends Layout { if (this.container.submorphs.length > 0) { if (hugContentsVertically && container.height !== height) { - container.withMetaDo({ isLayoutAction: true, skipRender: true }, () => container.height = height); + container.withMetaDo({ isLayoutAction: true, skipRender: true, doNotOverride: true }, () => container.height = height); } if (hugContentsHorizontally && container.width !== width) { - container.withMetaDo({ isLayoutAction: true, skipRender: true }, () => container.width = width); + container.withMetaDo({ isLayoutAction: true, skipRender: true, doNotOverride: true }, () => container.width = width); } } } diff --git a/lively.morphic/text/morph.js b/lively.morphic/text/morph.js index 34288210c5..7b5c0dc3e2 100644 --- a/lively.morphic/text/morph.js +++ b/lively.morphic/text/morph.js @@ -2826,8 +2826,7 @@ export class Text extends Morph { } else if (this.env.renderer) { if (this.fixedHeight && this.fixedWidth) return; let textBoundsExtent = this.textBounds().extent(); - this.renderingState.needsFit = this.renderingState.needsRemeasure; - this.withMetaDo({ isLayoutAction: true, doNotFit: true }, () => { + this.withMetaDo({ isLayoutAction: true, doNotFit: true, doNotOverride: true }, () => { if (this.fixedWidth) textBoundsExtent = textBoundsExtent.withX(this.width); if (this.fixedHeight) textBoundsExtent = textBoundsExtent.withY(this.height); const newExt = textBoundsExtent.addXY( @@ -2836,6 +2835,7 @@ export class Text extends Morph { ); if (!this.extent.equals(newExt)) { this.extent = newExt; + this.renderingState.needsFit = this.renderingState.needsRemeasure; } }); } else {