feat(menubar): 实现紧凑独立双列与按内容定高
This commit is contained in:
@@ -30,6 +30,7 @@ enum PanelPage: Hashable { case overview, processes }
|
||||
private let openSettings: () -> Void
|
||||
private var showingStatusMenu = false
|
||||
private var isHiding = false
|
||||
private var preferredContentHeight = PanelLayout.defaultHeight
|
||||
|
||||
init<Content: View>(installStatusItem: Bool = true, visibility: @escaping (Bool) -> Void,
|
||||
pageChanged: @escaping (PanelPage) -> Void = { _ in },
|
||||
@@ -168,9 +169,22 @@ enum PanelPage: Hashable { case overview, processes }
|
||||
visibilityObservation = nil
|
||||
}
|
||||
|
||||
func setPreferredContentHeight(_ height: CGFloat) {
|
||||
guard height.isFinite, height > 0 else { return }
|
||||
let height = min(PanelLayout.maximumHeight, max(360, height))
|
||||
guard preferredContentHeight != height else { return }
|
||||
preferredContentHeight = height
|
||||
#if DEBUG || KYMO_AUDIT
|
||||
// An explicit diagnostic viewport must not be overridden by automatic sizing.
|
||||
if ProcessInfo.processInfo.environment["KYMO_AUDIT_INTERACTIVE"] == "1",
|
||||
ProcessInfo.processInfo.environment["KYMO_AUDIT_SIZE"] != nil { return }
|
||||
#endif
|
||||
if presentation.isOpen { place() }
|
||||
}
|
||||
|
||||
private func place() {
|
||||
guard let screen = statusItem?.button?.window?.screen ?? panel.screen ?? NSScreen.main else { return }
|
||||
let size = PanelLayout.contentSize(visible: screen.visibleFrame)
|
||||
let size = PanelLayout.contentSize(visible: screen.visibleFrame, preferredHeight: preferredContentHeight)
|
||||
let initial = CGRect(x: screen.visibleFrame.midX - size.width / 2, y: screen.visibleFrame.maxY - size.height - 16,
|
||||
width: size.width, height: size.height)
|
||||
panel.setFrame(PanelLayout.centeredFrame(initial, visible: screen.visibleFrame), display: panel.isVisible)
|
||||
|
||||
Reference in New Issue
Block a user