Skip to content

Commit

Permalink
🎨: avoid overriding extent prop during layout application
Browse files Browse the repository at this point in the history
Previously some layout applications, including text layout, would cause extent, height or width properies in style policies to no longer apply, although not warranted.
  • Loading branch information
merryman authored and linusha committed Feb 5, 2025
1 parent 65809a6 commit f95de22
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
8 changes: 7 additions & 1 deletion lively.morphic/components/policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions lively.morphic/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lively.morphic/text/morph.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -2836,6 +2835,7 @@ export class Text extends Morph {
);
if (!this.extent.equals(newExt)) {
this.extent = newExt;
this.renderingState.needsFit = this.renderingState.needsRemeasure;
}
});
} else {
Expand Down

0 comments on commit f95de22

Please sign in to comment.