Skip to content

Commit

Permalink
Using utils.getBestScale instead
Browse files Browse the repository at this point in the history
Does the same as the now deprecated widgetUtils.getBestImageScale
  • Loading branch information
Cruor committed Oct 30, 2023
1 parent 5a31af5 commit 9ba63e4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 24 deletions.
24 changes: 1 addition & 23 deletions src/ui/widgets/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -193,26 +193,4 @@ function widgetUtils.centerWindow(window, parent)
widgetUtils.moveWindow(window, x, y, 0, 0, 0)
end

function widgetUtils.getBestImageScale(width, height, maxWidth, maxHeight, maxScale, preMultiplied)
local scaleX = maxScale or 1
local scaleY = maxScale or 1

if maxScale and not preMultiplied then
width *= scaleX
height *= scaleY
end

while width >= maxWidth do
width /= 2
scaleX /= 2
end

while height >= maxHeight do
height /= 2
scaleY /= 2
end

return math.min(scaleX, scaleY)
end

return widgetUtils
return widgetUtils
2 changes: 1 addition & 1 deletion src/ui/windows/stylegrounds_window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function stylegroundWindow.getStylegroundPreview(interactionData)
imageElement:layout()

local imageWidth, imageHeight = imageElement.width / imageElement.scaleX, imageElement.height / imageElement.scaleY
local bestScale = widgetUtils.getBestImageScale(imageWidth, imageHeight, PREVIEW_MAX_WIDTH, PREVIEW_MAX_HEIGHT)
local bestScale = utils.getBestScale(imageWidth, imageHeight, PREVIEW_MAX_WIDTH, PREVIEW_MAX_HEIGHT)

imageElement.scaleX = bestScale
imageElement.scaleY = bestScale
Expand Down

0 comments on commit 9ba63e4

Please sign in to comment.