mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
Added positioning mocks
This commit is contained in:
parent
ea2706ad96
commit
0a6b4a576b
5 changed files with 310 additions and 7 deletions
|
|
@ -23,6 +23,8 @@ class LockScreenPanelManager {
|
|||
private var panelWindow: NSWindow?
|
||||
private var hasDelegated = false
|
||||
private var collapsedFrame: NSRect?
|
||||
private var isPanelExpanded = false
|
||||
private var currentAdditionalHeight: CGFloat = 0
|
||||
private let collapsedPanelCornerRadius: CGFloat = 28
|
||||
private let expandedPanelCornerRadius: CGFloat = 52
|
||||
private(set) var latestFrame: NSRect?
|
||||
|
|
@ -53,13 +55,11 @@ class LockScreenPanelManager {
|
|||
return
|
||||
}
|
||||
|
||||
let collapsedSize = LockScreenMusicPanel.collapsedSize
|
||||
let screenFrame = screen.frame
|
||||
let centerX = screenFrame.origin.x + (screenFrame.width / 2)
|
||||
let originX = centerX - (collapsedSize.width / 2)
|
||||
let originY = screenFrame.origin.y + (screenFrame.height / 2) - collapsedSize.height - 32
|
||||
let targetFrame = NSRect(x: originX, y: originY, width: collapsedSize.width, height: collapsedSize.height)
|
||||
let targetFrame = collapsedFrame(for: screenFrame)
|
||||
collapsedFrame = targetFrame
|
||||
isPanelExpanded = false
|
||||
currentAdditionalHeight = 0
|
||||
|
||||
let window: NSWindow
|
||||
|
||||
|
|
@ -152,6 +152,19 @@ class LockScreenPanelManager {
|
|||
} else {
|
||||
window.contentView?.layer?.cornerRadius = targetRadius
|
||||
}
|
||||
|
||||
isPanelExpanded = expanded
|
||||
currentAdditionalHeight = additionalHeight
|
||||
}
|
||||
|
||||
func applyOffsetAdjustment(animated: Bool = true) {
|
||||
guard let screen = NSScreen.main else { return }
|
||||
let screenFrame = screen.frame
|
||||
let newCollapsed = collapsedFrame(for: screenFrame)
|
||||
collapsedFrame = newCollapsed
|
||||
|
||||
guard panelWindow != nil else { return }
|
||||
updatePanelSize(expanded: isPanelExpanded, additionalHeight: currentAdditionalHeight, animated: animated)
|
||||
}
|
||||
|
||||
func hidePanel() {
|
||||
|
|
@ -177,4 +190,14 @@ class LockScreenPanelManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func collapsedFrame(for screenFrame: NSRect) -> NSRect {
|
||||
let collapsedSize = LockScreenMusicPanel.collapsedSize
|
||||
let originX = screenFrame.midX - (collapsedSize.width / 2)
|
||||
let baseOriginY = screenFrame.origin.y + (screenFrame.height / 2) - collapsedSize.height - 32
|
||||
let userOffset = CGFloat(Defaults[.lockScreenMusicVerticalOffset])
|
||||
let clampedOffset = min(max(userOffset, -160), 160)
|
||||
let originY = baseOriginY + clampedOffset
|
||||
return NSRect(x: originX, y: originY, width: collapsedSize.width, height: collapsedSize.height)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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