Просмотр исходного кода

Embed the macOS window controls into the app chrome and remove the centered title text.

Add a sidebar top inset so left navigation content clears the in-app traffic lights area.

Made-with: Cursor
huzaifahayat12 1 месяц назад
Родитель
Сommit
00e7c771ba
1 измененных файлов с 7 добавлено и 26 удалено
  1. 7 26
      meetings_app/ViewController.swift

+ 7 - 26
meetings_app/ViewController.swift

@@ -248,7 +248,6 @@ final class ViewController: NSViewController {
248 248
     private var zoomJoinModeByView = [ObjectIdentifier: ZoomJoinMode]()
249 249
     private var zoomJoinModeViews: [ZoomJoinMode: NSView] = [:]
250 250
     private var settingsActionByView = [ObjectIdentifier: SettingsAction]()
251
-    private weak var centeredTitleLabel: NSTextField?
252 251
     private var paywallWindow: NSWindow?
253 252
     private let paywallContentWidth: CGFloat = 520
254 253
     private let launchWindowLeftOffset: CGFloat = 80
@@ -430,6 +429,7 @@ final class ViewController: NSViewController {
430 429
         presentLaunchPaywallIfNeeded()
431 430
         applyWindowTitle(for: selectedSidebarPage)
432 431
         guard let window = view.window else { return }
432
+        configureMainWindowChrome(window)
433 433
 
434 434
         // Ensure launch size is applied even when macOS tries to restore prior window state.
435 435
         window.isRestorable = false
@@ -452,7 +452,6 @@ final class ViewController: NSViewController {
452 452
             }
453 453
 
454 454
             window.minSize = window.frameRect(forContentRect: NSRect(origin: .zero, size: self.launchMinContentSize)).size
455
-            self.installCenteredTitleIfNeeded(on: window)
456 455
         }
457 456
     }
458 457
 
@@ -1866,32 +1865,13 @@ private extension ViewController {
1866 1865
             title = "Settings"
1867 1866
         }
1868 1867
         view.window?.title = title
1869
-        centeredTitleLabel?.stringValue = title
1870 1868
     }
1871 1869
 
1872
-    private func installCenteredTitleIfNeeded(on window: NSWindow) {
1873
-        guard centeredTitleLabel == nil else { return }
1874
-        guard let titlebarView = window.standardWindowButton(.closeButton)?.superview else { return }
1875
-
1876
-        let label = NSTextField(labelWithString: window.title)
1877
-        label.translatesAutoresizingMaskIntoConstraints = false
1878
-        label.alignment = .center
1879
-        label.font = NSFont.titleBarFont(ofSize: 0)
1880
-        label.textColor = .labelColor
1881
-        label.lineBreakMode = .byTruncatingTail
1882
-        label.maximumNumberOfLines = 1
1883
-
1884
-        titlebarView.addSubview(label)
1885
-
1886
-        NSLayoutConstraint.activate([
1887
-            label.centerXAnchor.constraint(equalTo: titlebarView.centerXAnchor),
1888
-            label.centerYAnchor.constraint(equalTo: titlebarView.centerYAnchor),
1889
-            label.leadingAnchor.constraint(greaterThanOrEqualTo: titlebarView.leadingAnchor, constant: 90),
1890
-            label.trailingAnchor.constraint(lessThanOrEqualTo: titlebarView.trailingAnchor, constant: -90)
1891
-        ])
1892
-
1870
+    private func configureMainWindowChrome(_ window: NSWindow) {
1871
+        window.styleMask.insert(.fullSizeContentView)
1893 1872
         window.titleVisibility = .hidden
1894
-        centeredTitleLabel = label
1873
+        window.titlebarAppearsTransparent = true
1874
+        window.isMovableByWindowBackground = true
1895 1875
     }
1896 1876
 
1897 1877
     private func updateSidebarAppearance() {
@@ -1919,6 +1899,7 @@ private extension ViewController {
1919 1899
         sidebar.layer?.shadowOffset = CGSize(width: 2, height: 0)
1920 1900
         sidebar.layer?.shadowRadius = 10
1921 1901
         sidebar.widthAnchor.constraint(equalToConstant: 210).isActive = true
1902
+        let sidebarTopInset: CGFloat = 44
1922 1903
 
1923 1904
         let appIconView = NSImageView()
1924 1905
         if let headerLogo = NSImage(named: "HeaderLogo") {
@@ -1974,7 +1955,7 @@ private extension ViewController {
1974 1955
 
1975 1956
         NSLayoutConstraint.activate([
1976 1957
             titleRow.leadingAnchor.constraint(equalTo: sidebar.leadingAnchor, constant: 16),
1977
-            titleRow.topAnchor.constraint(equalTo: sidebar.topAnchor, constant: 24),
1958
+            titleRow.topAnchor.constraint(equalTo: sidebar.topAnchor, constant: sidebarTopInset),
1978 1959
             titleRow.trailingAnchor.constraint(lessThanOrEqualTo: sidebar.trailingAnchor, constant: -16),
1979 1960
 
1980 1961
             menuStack.leadingAnchor.constraint(equalTo: sidebar.leadingAnchor, constant: 12),