Fix zoom, but for realses

This commit is contained in:
Tamius Han 2021-11-02 20:52:01 +01:00
parent 03bd442783
commit f00d3b5aaf
2 changed files with 29 additions and 11 deletions

View File

@ -66,13 +66,13 @@
type="range" type="range"
step="any" step="any"
min="-1" min="-1"
max="4" max="3"
:value="zoom.x" :value="zoom.x"
@input="changeZoom($event.target.value)" @input="changeZoom($event.target.value)"
/> />
<div style="overflow: auto" class="flex flex-row"> <div style="overflow: auto" class="flex flex-row">
<div class="flex flex-grow medium-small x-pad-1em"> <div class="flex flex-grow medium-small x-pad-1em">
Zoom: {{(zoom.x * 100).toFixed()}}% Zoom: {{getZoomForDisplay('x')}}
</div> </div>
<div class="flex flex-nogrow flex-noshrink medium-small"> <div class="flex flex-nogrow flex-noshrink medium-small">
<a class="_zoom_reset x-pad-1em" @click="resetZoom()">reset</a> <a class="_zoom_reset x-pad-1em" @click="resetZoom()">reset</a>
@ -97,14 +97,14 @@
type="range" type="range"
step="any" step="any"
min="-1" min="-1"
max="4" max="3"
:value="zoom.y" :value="zoom.y"
@input="changeZoom($event.target.value, 'y')" @input="changeZoom($event.target.value, 'y')"
/> />
<div style="overflow: auto" class="flex flex-row"> <div style="overflow: auto" class="flex flex-row">
<div class="flex flex-grow medium-small x-pad-1em"> <div class="flex flex-grow medium-small x-pad-1em">
Zoom: {{(zoom.x * 100).toFixed()}}% x {{(zoom.y * 100).toFixed()}}% Zoom: {{getZoomForDisplay('x')}} x {{getZoomForDisplay('y')}}
</div> </div>
<div class="flex flex-nogrow flex-noshrink medium-small"> <div class="flex flex-nogrow flex-noshrink medium-small">
<a class="_zoom_reset x-pad-1em" @click="resetZoom()">reset</a> <a class="_zoom_reset x-pad-1em" @click="resetZoom()">reset</a>
@ -189,6 +189,14 @@ export default {
computed: { computed: {
}, },
methods: { methods: {
getZoomForDisplay(axis) {
// zoom is internally handled logarithmically, because we want to
// have x0.5, x1, x2, x4 ... magnifications spaced out at regular
// intervals. When displaying, we need to conver that back to non-
// logarithmic units.
return `${ (Math.pow(2, this.zoom[axis]) * 100).toFixed()}%`;
},
async openOptionsPage() { async openOptionsPage() {
BrowserDetect.runtime.openOptionsPage(); BrowserDetect.runtime.openOptionsPage();
}, },
@ -207,12 +215,23 @@ export default {
}, },
resetZoom() { resetZoom() {
this.zoom = 1; // we store zoom logarithmically on this component
this.eventBus.send('set-zoom', {zoom: 1}); this.zoom = {x: 0, y: 0};
// we do not use logarithmic zoom elsewhere
this.eventBus.send('set-zoom', {zoom: 1, axis: 'y'});
this.eventBus.send('set-zoom', {zoom: 1, axis: 'x'});
}, },
changeZoom(newZoom, axis) { changeZoom(newZoom, axis) {
newZoom = Math.pow(2, newZoom); // we store zoom logarithmically on this compnent
if (!axis) {
this.zoom.x = newZoom;
} else {
this.zoom[axis] = newZoom;
}
// we do not use logarithmic zoom elsewhere, therefore we need to convert
newZoom = Math.pow(2, newZoom);
this.eventBus.send('set-zoom', {zoom: newZoom, axis: axis, noAnnounce: true}); this.eventBus.send('set-zoom', {zoom: newZoom, axis: axis, noAnnounce: true});
}, },
} }

View File

@ -123,11 +123,10 @@ const ExtensionConfPatch = [
} }
} }
}, { }, {
forVersion: '6.0.0', forVersion: '6.0.0-alpha1',
updateFn: (userOptions: SettingsInterface, defaultOptions) => { updateFn: (userOptions: SettingsInterface, defaultOptions) => {
// migrate keyboard settings to the new format: // add new commands
userOptions.commands = defaultOptions.commands;
// userOptions.actions
} }
} }
]; ];