Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make win.setAspectRatio() work on Windows / new Electron version #102

Open
hhaensel opened this issue Jan 21, 2022 · 0 comments
Open

make win.setAspectRatio() work on Windows / new Electron version #102

hhaensel opened this issue Jan 21, 2022 · 0 comments

Comments

@hhaensel
Copy link

A recent patch for Electron makes win.setAspectRatio() work on Windows. This would be very handy to have. The currently used version of Electron is already rather old. Would it be possible to update to the latest version?

Currently I use a js version for a similar task (keep a constant offset of 45 pixels for height with respect to width. I paste it here to document how events can be handled by the ElectronAPI.

using Electron, JSON

win = Window()

# initialise `oldSize` in the app
wsize = ElectronAPI.getSize(win)
run(win.app, "oldSize = $(JSON.json(wsize))")

ElectronAPI.on(win, "resize", JSONText("""function() { 
    win = electron.BrowserWindow.fromId($(win.id))
    newSize = win.getSize()

    if (Math.abs(oldSize[0] - newSize[0]) < 5) {
        height = newSize[1]
        width = height - 45
    } else if (Math.abs(oldSize[1] - newSize[1]) < 5) {
        width = newSize[0]
        height = width + 45
    }
    
    if (Math.abs(oldSize[0] - newSize[0]) < 3 & Math.abs(oldSize[1] - newSize[1]) < 3) {
        oldSize = newSize
        return
    }
    
    oldSize = [width, height]
    win.setSize(width, height)    
 }"""))

Resizing with the edge handles doesn't work properly, but side handles work well. I use it in the camera widget app in Stipple (it's listed under broken but works already quite well.)
To people not familiar with JSON: JSONText is necessary to have the function pasted as function and not as string.

@davidanthoff Perhaps we can paste a use case of event handling in the docs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant