-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: maintain window sizing for preview action * chore: enlarge stroke on full size preview * chore: reword option
- Loading branch information
Showing
10 changed files
with
105 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Cocoa | ||
|
||
extension CGPoint { | ||
func screen() -> NSScreen? { | ||
// Try direct containment first | ||
if let screen = NSScreen.screens.first(where: { $0.frame.contains(self) }) { | ||
return screen | ||
} | ||
|
||
// If that fails, try using the screen's visible frame | ||
if let screen = NSScreen.screens.first(where: { $0.visibleFrame.contains(self) }) { | ||
return screen | ||
} | ||
|
||
// If still no match, find the nearest screen by calculating distance to center | ||
return NSScreen.screens.min(by: { screen1, screen2 in | ||
let distance1 = self.distance(to: CGPoint(x: screen1.frame.midX, y: screen1.frame.midY)) | ||
let distance2 = self.distance(to: CGPoint(x: screen2.frame.midX, y: screen2.frame.midY)) | ||
return distance1 < distance2 | ||
}) ?? NSScreen.main | ||
} | ||
|
||
func distance(to point: CGPoint) -> CGFloat { | ||
let dx = x - point.x | ||
let dy = y - point.y | ||
return sqrt(dx * dx + dy * dy) | ||
} | ||
|
||
func displace(by point: CGPoint = .init(x: 0.0, y: 0.0)) -> CGPoint { | ||
CGPoint(x: x + point.x, | ||
y: y + point.y) | ||
} | ||
|
||
/// Caps the point to the unit space | ||
func capped() -> CGPoint { | ||
CGPoint(x: max(min(x, 1), 0), | ||
y: max(min(y, 1), 0)) | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Cocoa | ||
|
||
extension CGSize { | ||
static func + (lhs: CGSize, rhs: CGSize) -> CGSize { | ||
CGSize(width: lhs.width + rhs.width, height: lhs.height + rhs.height) | ||
} | ||
} | ||
|
||
extension CGSize { | ||
func scaleToFit(within maxSize: CGSize) -> CGSize { | ||
let widthRatio = maxSize.width / width | ||
let heightRatio = maxSize.height / height | ||
let scale = min(widthRatio, heightRatio) | ||
|
||
return CGSize( | ||
width: width * scale, | ||
height: height * scale | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters