Skip to content

Commit

Permalink
Decouple sequence extents from preview
Browse files Browse the repository at this point in the history
  • Loading branch information
SilvanVerhoeven committed Jun 14, 2021
1 parent a6fb5cb commit f1e3bbb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
32 changes: 21 additions & 11 deletions editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,16 +304,7 @@ export class InteractivesEditor extends QinoqMorph {
}

onInteractiveZoomed () {
const previewExtent = this.ui.preview.extent;

// only show scrollbars if they are necessary
if (this.interactive.extent.x >= previewExtent.x) {
this.ui.preview.clipMode = 'scroll';
}
if (this.interactive.extent.y >= previewExtent.y) {
this.ui.preview.clipMode = 'scroll';
}
if (!(this.interactive.extent.x > previewExtent.x) && !(this.interactive.extent.y > previewExtent.y)) this.ui.preview.clipMode = 'hidden';
this.ui.preview.updateScrollbarVisibility();
}

// call this to propagate changes to the scrollPosition to the actual interactive
Expand Down Expand Up @@ -1040,7 +1031,12 @@ class Preview extends QinoqMorph {
defaultValue: 'preview'
},
extent: {
defaultValue: pt(CONSTANTS.PREVIEW_WIDTH, CONSTANTS.SUBWINDOW_HEIGHT)
defaultValue: pt(CONSTANTS.PREVIEW_WIDTH, CONSTANTS.SUBWINDOW_HEIGHT),
after: ['_editor', 'ui'],
set (extent) {
this.setProperty('extent', extent);
if (!this._deserializing) this.updateScrollbarVisibility();
}
},
borderColor: {
defaultValue: COLOR_SCHEME.ON_BACKGROUND_DARKER_VARIANT
Expand Down Expand Up @@ -1157,6 +1153,20 @@ class Preview extends QinoqMorph {
removeAnimationPreview () {
this.animationPreview = null;
}

updateScrollbarVisibility () {
if (!this.interactive) return;

// only show scrollbars if they are necessary
if (this.interactive.width >= this.width ||
this.interactive.height >= this.height) {
this.clipMode = 'scroll';
}
if (!(this.interactive.width > this.width) &&
!(this.interactive.height > this.height)) {
this.clipMode = 'hidden';
}
}
}

class PositionAnimationPreview extends Canvas {
Expand Down
7 changes: 5 additions & 2 deletions interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class Interactive extends DeserializationAwareMorph {
}
this.setProperty('extent', extent);
if (!this._deserializing) {
this.updateSequenceExtents();
this.scaleText(previousHeight);
}
}
Expand Down Expand Up @@ -99,6 +100,10 @@ export class Interactive extends DeserializationAwareMorph {
};
}

updateSequenceExtents () {
this.sequences.forEach(sequence => sequence.extent = this.extent);
}

applyAspectRatio (extent, calculateAspectRatio = false) {
let aspectRatio;
aspectRatio = calculateAspectRatio ? this.width / this.height : this.fixedAspectRatio;
Expand Down Expand Up @@ -277,12 +282,10 @@ export class Interactive extends DeserializationAwareMorph {
sequence.interactive = this;
this.updateInteractiveLength();
signal(this, 'onSequenceAddition', sequence);
connect(this, 'extent', sequence, 'extent');
}

removeSequence (sequence) {
disconnectAll(sequence);
disconnect(this, 'extent', sequence, 'extent');
arr.remove(this.sequences, sequence);
sequence.remove();
signal(this, 'onSequenceRemoval', sequence);
Expand Down

0 comments on commit f1e3bbb

Please sign in to comment.