Sfoglia il codice sorgente

Fix Join/Cancel button hover styles

Use HoverButton for action buttons and update colors on hover.

Made-with: Cursor
huzaifahayat12 3 mesi fa
parent
commit
c972b21a9e
1 ha cambiato i file con 19 aggiunte e 3 eliminazioni
  1. 19 3
      meetings_app/ViewController.swift

+ 19 - 3
meetings_app/ViewController.swift

@@ -1058,19 +1058,35 @@ private extension ViewController {
     }
 
     func meetActionButton(title: String, color: NSColor, textColor: NSColor, width: CGFloat, action: Selector) -> NSButton {
-        let button = NSButton(title: title, target: self, action: action)
+        let button = HoverButton(title: title, target: self, action: action)
         button.translatesAutoresizingMaskIntoConstraints = false
         button.isBordered = false
         button.bezelStyle = .regularSquare
         button.wantsLayer = true
         button.layer?.cornerRadius = 9
-        button.layer?.backgroundColor = color.cgColor
-        button.layer?.borderColor = (title == "Cancel" ? palette.inputBorder : palette.primaryBlueBorder).cgColor
+        let baseBackground = color
+        let hoverBlend = darkModeEnabled ? NSColor.white : NSColor.black
+        let hoverBackground = baseBackground.blended(withFraction: 0.10, of: hoverBlend) ?? baseBackground
+
+        let baseBorder = (title == "Cancel" ? palette.inputBorder : palette.primaryBlueBorder)
+        let hoverBorder = baseBorder.blended(withFraction: 0.18, of: hoverBlend) ?? baseBorder
+
+        button.layer?.backgroundColor = baseBackground.cgColor
+        button.layer?.borderColor = baseBorder.cgColor
         button.layer?.borderWidth = 1
         button.font = typography.buttonText
         button.contentTintColor = textColor
         button.widthAnchor.constraint(equalToConstant: width).isActive = true
         button.heightAnchor.constraint(equalToConstant: 36).isActive = true
+        button.onHoverChanged = { [weak self, weak button] hovering in
+            guard let self, let button else { return }
+            button.layer?.backgroundColor = (hovering ? hoverBackground : baseBackground).cgColor
+            button.layer?.borderColor = (hovering ? hoverBorder : baseBorder).cgColor
+            if title == "Cancel" {
+                button.contentTintColor = hovering ? (self.darkModeEnabled ? .white : self.palette.textPrimary) : textColor
+            }
+        }
+        button.onHoverChanged?(false)
         return button
     }