diff --git a/Loop/Utilities/PaddingModel.swift b/Loop/Utilities/PaddingModel.swift index a825d1e2..d160e919 100644 --- a/Loop/Utilities/PaddingModel.swift +++ b/Loop/Utilities/PaddingModel.swift @@ -32,15 +32,15 @@ struct PaddingModel: Codable, Defaults.Serializable, Hashable { configureScreenPadding: false ) - var totalVerticalPadding: CGFloat { - totalTopPadding + bottom - } - - var totalHorizontalPadding: CGFloat { - right + left - } - var allEqual: Bool { window == top && window == bottom && window == right && window == left } + + func apply(on initial: CGRect) -> CGRect { + initial + .padding(.leading, left) + .padding(.trailing, right) + .padding(.bottom, bottom) + .padding(.top, totalTopPadding) + } } diff --git a/Loop/Window Management/WindowAction.swift b/Loop/Window Management/WindowAction.swift index fcee2b32..570bc7b8 100644 --- a/Loop/Window Management/WindowAction.swift +++ b/Loop/Window Management/WindowAction.swift @@ -326,8 +326,13 @@ struct WindowAction: Codable, Identifiable, Hashable, Equatable, Defaults.Serial var result = frameToResizeFrom let totalBounds: Edge.Set = [.top, .bottom, .leading, .trailing] let step = Defaults[.sizeIncrement] * ((direction == .larger || direction.willGrow) ? -1 : 1) - let minWidth = Defaults[.padding].totalHorizontalPadding + Defaults[.previewPadding] + 100 - let minHeight = Defaults[.padding].totalVerticalPadding + Defaults[.previewPadding] + 100 + + let padding = Defaults[.padding] + let previewPadding = Defaults[.previewPadding] + let totalHorizontalPadding = padding.left + padding.right + let totalVerticalPadding = padding.totalTopPadding + padding.bottom + let minWidth = totalHorizontalPadding + previewPadding + 100 + let minHeight = totalVerticalPadding + previewPadding + 100 if LoopManager.sidesToAdjust == nil { let edgesTouchingBounds = frameToResizeFrom.getEdgesTouchingBounds(bounds) diff --git a/Loop/Window Management/WindowEngine.swift b/Loop/Window Management/WindowEngine.swift index 5dcef5e1..da7eaabf 100644 --- a/Loop/Window Management/WindowEngine.swift +++ b/Loop/Window Management/WindowEngine.swift @@ -84,7 +84,13 @@ enum WindowEngine { return } - let bounds = action.direction.willMove ? .zero : screen.safeScreenFrame + let screenFrame = action.direction.willMove ? .zero : screen.safeScreenFrame + + let bounds = if Defaults[.enablePadding] { + Defaults[.padding].apply(on: screenFrame) + } else { + screenFrame + } window.setFrame( targetFrame, @@ -186,25 +192,22 @@ enum WindowEngine { return } - let windowFrame = window.frame + var windowFrame = window.frame + // If the window is fully shown on the screen - if windowFrame.maxX <= bounds.maxX, windowFrame.maxY <= bounds.maxY { + if windowFrame.maxX <= bounds.maxX, + windowFrame.maxY <= bounds.maxY { return } - // If not, then Loop will auto re-adjust the window size to be fully shown on the screen - var fixedWindowFrame = windowFrame - - if fixedWindowFrame.maxX > bounds.maxX { - let rightPadding = Defaults[.enablePadding] ? Defaults[.padding].right : 0 - fixedWindowFrame.origin.x = bounds.maxX - fixedWindowFrame.width - rightPadding + if windowFrame.maxX > bounds.maxX { + windowFrame.origin.x = bounds.maxX - windowFrame.width } - if fixedWindowFrame.maxY > bounds.maxY { - let bottomPadding = Defaults[.enablePadding] ? Defaults[.padding].bottom : 0 - fixedWindowFrame.origin.y = bounds.maxY - fixedWindowFrame.height - bottomPadding + if windowFrame.maxY > bounds.maxY { + windowFrame.origin.y = bounds.maxY - windowFrame.height } - window.setPosition(fixedWindowFrame.origin) + window.setPosition(windowFrame.origin) } }