Skip to content

Commit f95de22

Browse files
merrymanlinusha
authored andcommitted
🎨: avoid overriding extent prop during layout application
Previously some layout applications, including text layout, would cause extent, height or width properies in style policies to no longer apply, although not warranted.
1 parent 65809a6 commit f95de22

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

lively.morphic/components/policy.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,12 @@ export class StylePolicy {
454454
if (targetMorph._lastIndex && !obj.equals(targetMorph._lastIndex, currIndex)) {
455455
const limitExtent = bpStore.getLimitExtent(currIndex);
456456
const actualExtent = targetMorph.extent;
457-
targetMorph.withMetaDo({ metaInteraction: true, reconcileChanges: false, doNotFit: true }, () => {
457+
targetMorph.withMetaDo({
458+
metaInteraction: true, // do not record
459+
reconcileChanges: false,
460+
doNotFit: true,
461+
doNotOverride: true
462+
}, () => {
458463
const origLayoutableFlag = targetMorph.isLayoutable;
459464
targetMorph.isLayoutable = false; // avoid any resizing interference here
460465
targetMorph.extent = limitExtent;
@@ -1574,6 +1579,7 @@ export class PolicyApplicator extends StylePolicy {
15741579
*/
15751580
onMorphChange (changedMorph, change) {
15761581
if (change.meta?.metaInteraction ||
1582+
change.meta?.doNotOverride ||
15771583
!this.targetMorph ||
15781584
this.isCurrentlyAnimated(changedMorph)
15791585
) return;

lively.morphic/layout.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -834,10 +834,10 @@ export class TilingLayout extends Layout {
834834
aMorph._yogaNode = Yoga.Node.create(yogaConfig);
835835
if (aMorph.isText) {
836836
aMorph._yogaNode.setMeasureFunc((width, widthMode, height, heightMode) => {
837-
if (aMorph.fixedWidth && widthMode !== 0) aMorph.width = width;
838-
if (aMorph.fixedHeight && heightMode !== 0) aMorph.height = height;
837+
if (aMorph.fixedWidth && widthMode !== 0) aMorph.withMetaDo({ doNotOverride: true }, () => aMorph.width = width);
838+
if (aMorph.fixedHeight && heightMode !== 0) aMorph.withMetaDo({ doNotOverride: true }, () => aMorph.height = height);
839839
if (!aMorph.visible) return { width: aMorph.width, height: aMorph.height };
840-
if (!aMorph.fixedWidth || !aMorph.fixedHeight) aMorph.withMetaDo({ doNotFit: false }, () => aMorph.fit());
840+
if (!aMorph.fixedWidth || !aMorph.fixedHeight) aMorph.withMetaDo({ doNotFit: false, skipRerender: true }, () => aMorph.fitIfNeeded());
841841
if (!aMorph.fixedWidth) width = aMorph.width;
842842
if (!aMorph.fixedHeight) height = aMorph.height;
843843
return { width, height };
@@ -934,10 +934,10 @@ export class TilingLayout extends Layout {
934934

935935
if (this.container.submorphs.length > 0) {
936936
if (hugContentsVertically && container.height !== height) {
937-
container.withMetaDo({ isLayoutAction: true, skipRender: true }, () => container.height = height);
937+
container.withMetaDo({ isLayoutAction: true, skipRender: true, doNotOverride: true }, () => container.height = height);
938938
}
939939
if (hugContentsHorizontally && container.width !== width) {
940-
container.withMetaDo({ isLayoutAction: true, skipRender: true }, () => container.width = width);
940+
container.withMetaDo({ isLayoutAction: true, skipRender: true, doNotOverride: true }, () => container.width = width);
941941
}
942942
}
943943
}

lively.morphic/text/morph.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2826,8 +2826,7 @@ export class Text extends Morph {
28262826
} else if (this.env.renderer) {
28272827
if (this.fixedHeight && this.fixedWidth) return;
28282828
let textBoundsExtent = this.textBounds().extent();
2829-
this.renderingState.needsFit = this.renderingState.needsRemeasure;
2830-
this.withMetaDo({ isLayoutAction: true, doNotFit: true }, () => {
2829+
this.withMetaDo({ isLayoutAction: true, doNotFit: true, doNotOverride: true }, () => {
28312830
if (this.fixedWidth) textBoundsExtent = textBoundsExtent.withX(this.width);
28322831
if (this.fixedHeight) textBoundsExtent = textBoundsExtent.withY(this.height);
28332832
const newExt = textBoundsExtent.addXY(
@@ -2836,6 +2835,7 @@ export class Text extends Morph {
28362835
);
28372836
if (!this.extent.equals(newExt)) {
28382837
this.extent = newExt;
2838+
this.renderingState.needsFit = this.renderingState.needsRemeasure;
28392839
}
28402840
});
28412841
} else {

0 commit comments

Comments
 (0)