Selaa lähdekoodia

Fix Join/Cancel button hover styles

Use HoverButton for action buttons and update colors on hover.

Made-with: Cursor
huzaifahayat12 1 viikko sitten
vanhempi
commit
c972b21a9e
1 muutettua tiedostoa jossa 19 lisäystä ja 3 poistoa
  1. 19 3
      meetings_app/ViewController.swift

+ 19 - 3
meetings_app/ViewController.swift

@@ -1058,19 +1058,35 @@ private extension ViewController {
1058 1058
     }
1059 1059
 
1060 1060
     func meetActionButton(title: String, color: NSColor, textColor: NSColor, width: CGFloat, action: Selector) -> NSButton {
1061
-        let button = NSButton(title: title, target: self, action: action)
1061
+        let button = HoverButton(title: title, target: self, action: action)
1062 1062
         button.translatesAutoresizingMaskIntoConstraints = false
1063 1063
         button.isBordered = false
1064 1064
         button.bezelStyle = .regularSquare
1065 1065
         button.wantsLayer = true
1066 1066
         button.layer?.cornerRadius = 9
1067
-        button.layer?.backgroundColor = color.cgColor
1068
-        button.layer?.borderColor = (title == "Cancel" ? palette.inputBorder : palette.primaryBlueBorder).cgColor
1067
+        let baseBackground = color
1068
+        let hoverBlend = darkModeEnabled ? NSColor.white : NSColor.black
1069
+        let hoverBackground = baseBackground.blended(withFraction: 0.10, of: hoverBlend) ?? baseBackground
1070
+
1071
+        let baseBorder = (title == "Cancel" ? palette.inputBorder : palette.primaryBlueBorder)
1072
+        let hoverBorder = baseBorder.blended(withFraction: 0.18, of: hoverBlend) ?? baseBorder
1073
+
1074
+        button.layer?.backgroundColor = baseBackground.cgColor
1075
+        button.layer?.borderColor = baseBorder.cgColor
1069 1076
         button.layer?.borderWidth = 1
1070 1077
         button.font = typography.buttonText
1071 1078
         button.contentTintColor = textColor
1072 1079
         button.widthAnchor.constraint(equalToConstant: width).isActive = true
1073 1080
         button.heightAnchor.constraint(equalToConstant: 36).isActive = true
1081
+        button.onHoverChanged = { [weak self, weak button] hovering in
1082
+            guard let self, let button else { return }
1083
+            button.layer?.backgroundColor = (hovering ? hoverBackground : baseBackground).cgColor
1084
+            button.layer?.borderColor = (hovering ? hoverBorder : baseBorder).cgColor
1085
+            if title == "Cancel" {
1086
+                button.contentTintColor = hovering ? (self.darkModeEnabled ? .white : self.palette.textPrimary) : textColor
1087
+            }
1088
+        }
1089
+        button.onHoverChanged?(false)
1074 1090
         return button
1075 1091
     }
1076 1092