Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐞 Padding fixes #473

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Loop/Utilities/PaddingModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
9 changes: 7 additions & 2 deletions Loop/Window Management/WindowAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 16 additions & 13 deletions Loop/Window Management/WindowEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
}
Loading