Skip to content

Commit

Permalink
Match text scale to zoom percent from the editor
Browse files Browse the repository at this point in the history
  • Loading branch information
thsparks committed Oct 18, 2023
1 parent c7f0bdc commit 30b0a2c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions pxteditor/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace pxt.editor {
zoomIn(): void;
zoomOut(): void;
resize(): void;
getMaxScale(): number;
setScale(scale: number): void;
onScaleChanged: (oldScale: number, newScale: number) => void;
}
Expand Down
13 changes: 6 additions & 7 deletions webapp/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ export class ProjectView
private pendingImport: pxt.Util.DeferredPromise<void>;

private initialEditorScale: number;
private tutorialFontIncrement = 0.25;
private tutorialInitialFontSize = 1.125; // rem
private tutorialMaxFontSize = 2; // rem

private highContrastSubscriber: data.DataSubscriber = {
subscriptions: [],
Expand Down Expand Up @@ -1550,12 +1550,11 @@ export class ProjectView
// Do not shrink the text beyond its initial size.
this.setState({tutorialFontSize: this.tutorialInitialFontSize});
} else {
const change = newScale > oldScale ? this.tutorialFontIncrement : -this.tutorialFontIncrement;
if (!this.state.tutorialFontSize) {
this.setState({ tutorialFontSize: this.tutorialInitialFontSize + change });
} else {
this.setState({ tutorialFontSize: this.state.tutorialFontSize + change });
}
// Increase font size to match the editor's % zoom.
const maxEditorScale = this.editor.getMaxScale();
const zoomAmt = (newScale - this.initialEditorScale) / (maxEditorScale - this.initialEditorScale);
const newTutorialFontSize = this.tutorialInitialFontSize + (this.tutorialMaxFontSize - this.tutorialInitialFontSize) * zoomAmt;
this.setState({ tutorialFontSize: newTutorialFontSize });
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions webapp/src/blocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,11 @@ export class Editor extends toolboxeditor.ToolboxEditor {
this.editor.zoomCenter(-0.8);
}

getMaxScale() {
if (!this.editor) return undefined;
return this.editor.options.zoomOptions.maxScale;
}

setScale(scale: number) {
if (!this.editor) return;
if (scale != this.editor.scale) {
Expand Down
5 changes: 5 additions & 0 deletions webapp/src/monaco.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,11 @@ export class Editor extends toolboxeditor.ToolboxEditor {
}
}

getMaxScale() {
if (!this.editor) return undefined;
return MAX_EDITOR_FONT_SIZE;
}

private loadReference() {
Util.assert(this.editor != undefined); // Guarded

Expand Down
1 change: 1 addition & 0 deletions webapp/src/srceditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export class Editor implements pxt.editor.IEditor {

zoomIn() { }
zoomOut() { }
getMaxScale() { return 1; }
setScale(scale: number) { }

closeFlyout() { }
Expand Down

0 comments on commit 30b0a2c

Please sign in to comment.