Skip to content

Commit 91376f5

Browse files
committed
Adds UI zoom to application menu [#1359]
1 parent fb6a654 commit 91376f5

File tree

1 file changed

+69
-2
lines changed

1 file changed

+69
-2
lines changed

src/main/electron.js

+69-2
Original file line numberDiff line numberDiff line change
@@ -973,13 +973,76 @@ app.whenReady().then(() =>
973973
})
974974
}
975975
};
976-
976+
977+
var zoomSteps = [0.25, 0.33, 0.5, 0.67, 0.75, 0.8, 0.9, 1,
978+
1.1, 1.25, 1.5, 1.75, 2, 2.5, 3, 4, 5];
979+
980+
// Zooms to the next zoom step
981+
function zoomInFn()
982+
{
983+
var zoomFactor = win.webContents.zoomFactor;
984+
var newZoomFactor = zoomSteps[zoomSteps.length - 1];
985+
986+
for (var i = 0; i < zoomSteps.length; i++)
987+
{
988+
if (zoomSteps[i] - zoomFactor > 0.01)
989+
{
990+
newZoomFactor = zoomSteps[i];
991+
break;
992+
}
993+
}
994+
995+
win.webContents.zoomFactor = newZoomFactor;
996+
};
997+
998+
// Zooms to the previous zoom step
999+
function zoomOutFn()
1000+
{
1001+
var zoomFactor = win.webContents.zoomFactor;
1002+
var newZoomFactor = zoomSteps[0];
1003+
1004+
for (var i = zoomSteps.length - 1; i >= 0; i--)
1005+
{
1006+
if (zoomSteps[i] - zoomFactor < -0.01)
1007+
{
1008+
newZoomFactor = zoomSteps[i];
1009+
break;
1010+
}
1011+
}
1012+
1013+
win.webContents.zoomFactor = newZoomFactor;
1014+
};
1015+
1016+
// Resets the zoom factor
1017+
function resetZoomFn()
1018+
{
1019+
win.webContents.zoomFactor = 1;
1020+
};
1021+
9771022
let checkForUpdates = {
9781023
label: 'Check for updates',
9791024
click: checkForUpdatesFn
9801025
}
9811026

1027+
let zoomIn = {
1028+
label: 'Zoom In',
1029+
click: zoomInFn
1030+
};
1031+
1032+
let zoomOut = {
1033+
label: 'Zoom Out',
1034+
click: zoomOutFn
1035+
};
1036+
1037+
let resetZoom = {
1038+
label: 'Actual Size',
1039+
click: resetZoomFn
1040+
};
1041+
9821042
ipcMain.on('checkForUpdates', checkForUpdatesFn);
1043+
ipcMain.on('zoomIn', zoomInFn);
1044+
ipcMain.on('zoomOut', zoomOutFn);
1045+
ipcMain.on('resetZoom', resetZoomFn);
9831046

9841047
if (isMac)
9851048
{
@@ -995,11 +1058,15 @@ app.whenReady().then(() =>
9951058
click() { shell.openExternal('https://github.com/jgraph/drawio-desktop/issues'); }
9961059
},
9971060
checkForUpdates,
1061+
{ type: 'separator' },
1062+
resetZoom,
1063+
zoomIn,
1064+
zoomOut,
9981065
{ type: 'separator' },
9991066
{ role: 'hide' },
10001067
{ role: 'hideothers' },
10011068
{ role: 'unhide' },
1002-
{ type: 'separator' },
1069+
{ type: 'separator' },
10031070
{ role: 'quit' }
10041071
]
10051072
}, {

0 commit comments

Comments
 (0)