Skip to content

Commit

Permalink
Window out of bounds hook now also checks if size has changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Cruor committed Jul 19, 2024
1 parent 138ee01 commit f652c28
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/ui/widgets/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ function widgetUtils.preventOutOfBoundsMovement(window, padding)
return
end

local positionChanged = self.x ~= self._previousX or self.y ~= self._previousY
local sizeChanged = self.width ~= self._previousWidth or self.height ~= self._previousHeight

-- No need to run if position hasn't changed
if self.x ~= self._previousX or self.y ~= self._previousY then
if positionChanged or sizeChanged then
local usableWidth, usableHeight = widgetUtils.getUsableSize(padding)
local newX, newY = self.x, self.y

Expand All @@ -108,6 +111,9 @@ function widgetUtils.preventOutOfBoundsMovement(window, padding)

self._previousX = self.x
self._previousY = self.y
self._previousWidth = self.width
self._previousHeight = self.height

end
})
end
Expand All @@ -126,7 +132,9 @@ function widgetUtils.moveWindow(window, newX, newY, threshold, clamp, padding)

if math.abs(currentX - newX) > threshold or math.abs(currentY - newY) > threshold then
window.x = newX
window.realX = newX
window.y = newY
window.realY = newY

if window.parent then
window.parent:reflow()
Expand Down

0 comments on commit f652c28

Please sign in to comment.