Skip to content

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

Open
@hhaensel

Description

@hhaensel

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions