How can I keep the window width and height aspect ratio in electron?
For example, a square shape that can be resized by the user.
Advertisement
Answer
There’s a win.setAspectRatio
API for the BrowserWindow
.
Note that it’s currently only available on macOS on the latest stable (Electron 8.2.1), but should be available on Linux as of Electron 9.
PR #18306 attempts to add support for Windows, but hasn’t been accepted yet.
EDIT: This has been added to Electron 11 via PR #26941.