Constrain window to aspect ratio
|
|
client var/tmp/lastWindowWidth = list() var/tmp/lastWindowHeight = list()
verb/forceAspect(window="default" as text|null, aspect=4/3 as num|null) var size = winget(src, window, "size") delimiter = findtext(size, "x") width = text2num(copytext(size, 1, delimiter)) height = text2num(copytext(size, delimiter+1, 0))
heightForWidth = round(width/aspect) widthForHeight = round(height*aspect)
var changeWidth = (!lastWindowWidth[window] ? 0 \ : width - lastWindowWidth[window]) changeHeight = (!lastWindowHeight[window] ? 0 \ : height - lastWindowHeight[window])
grow = ((abs(changeWidth) > abs(changeHeight)) ? changeWidth : changeHeight) >= 0
if((grow && widthForHeight>width) || (!grow && widthForHeight<width)) width = widthForHeight else height = heightForWidth
lastWindowWidth[window] = width lastWindowHeight[window] = height
winset(src, window, "size='[width]x[height]'")
|
|