mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-28 23:54:32 +00:00
Added positioning mocks
This commit is contained in:
parent
ea2706ad96
commit
0a6b4a576b
5 changed files with 310 additions and 7 deletions
|
|
@ -1,6 +1,8 @@
|
|||
import AppKit
|
||||
import SwiftUI
|
||||
import SkyLightWindow
|
||||
import Defaults
|
||||
import QuartzCore
|
||||
|
||||
@MainActor
|
||||
final class LockScreenWeatherPanelManager {
|
||||
|
|
@ -9,6 +11,8 @@ final class LockScreenWeatherPanelManager {
|
|||
private var window: NSWindow?
|
||||
private var hasDelegated = false
|
||||
private(set) var latestFrame: NSRect?
|
||||
private var lastSnapshot: LockScreenWeatherSnapshot?
|
||||
private var lastContentSize: CGSize?
|
||||
|
||||
private init() {}
|
||||
|
||||
|
|
@ -25,6 +29,8 @@ final class LockScreenWeatherPanelManager {
|
|||
window.orderOut(nil)
|
||||
window.contentView = nil
|
||||
latestFrame = nil
|
||||
lastSnapshot = nil
|
||||
lastContentSize = nil
|
||||
}
|
||||
|
||||
private func render(snapshot: LockScreenWeatherSnapshot, makeVisible: Bool) {
|
||||
|
|
@ -43,6 +49,8 @@ final class LockScreenWeatherPanelManager {
|
|||
window.setFrame(targetFrame, display: true)
|
||||
latestFrame = targetFrame
|
||||
window.contentView = hostingView
|
||||
lastSnapshot = snapshot
|
||||
lastContentSize = fittingSize
|
||||
|
||||
if makeVisible {
|
||||
window.orderFrontRegardless()
|
||||
|
|
@ -86,10 +94,30 @@ final class LockScreenWeatherPanelManager {
|
|||
let baseY = min(maxY, screenFrame.midY + verticalOffset)
|
||||
let loweredY = baseY - 36
|
||||
|
||||
let inlineLift: CGFloat = snapshot.widgetStyle == .inline ? 28 : 0
|
||||
let adjustedY = loweredY + inlineLift
|
||||
let inlineLift: CGFloat = snapshot.widgetStyle == .inline ? 44 : 0
|
||||
let userOffset = CGFloat(Defaults[.lockScreenWeatherVerticalOffset])
|
||||
let clampedOffset = min(max(userOffset, -160), 160)
|
||||
let adjustedY = loweredY + inlineLift + clampedOffset
|
||||
let upperClampedY = min(maxY, adjustedY)
|
||||
let clampedY = max(screenFrame.minY + 80, upperClampedY)
|
||||
return NSRect(x: originX, y: clampedY, width: size.width, height: size.height)
|
||||
}
|
||||
|
||||
func refreshPositionForOffsets(animated: Bool = true) {
|
||||
guard let window, let snapshot = lastSnapshot else { return }
|
||||
guard let screen = NSScreen.main else { return }
|
||||
let size = lastContentSize ?? window.frame.size
|
||||
let targetFrame = frame(for: size, snapshot: snapshot, on: screen)
|
||||
latestFrame = targetFrame
|
||||
|
||||
if animated {
|
||||
NSAnimationContext.runAnimationGroup { context in
|
||||
context.duration = 0.22
|
||||
context.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
|
||||
window.animator().setFrame(targetFrame, display: true)
|
||||
}
|
||||
} else {
|
||||
window.setFrame(targetFrame, display: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue