Skip to content

Commit 3d3ee83

Browse files
Round notification close button (#5630)
Keep the hover close button fully inside the notification panel and derive its corner radius from the final bounds.
1 parent 551f2dd commit 3d3ee83

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

crates/notification-macos/swift-lib/src/NotificationButtons.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ class CloseButton: NSButton, TrackableButton {
6969
NSSize(width: CloseButtonConfig.size, height: CloseButtonConfig.size)
7070
}
7171

72+
override func layout() {
73+
super.layout()
74+
layer?.cornerRadius = min(bounds.width, bounds.height) / 2
75+
}
76+
7277
override func updateTrackingAreas() {
7378
super.updateTrackingAreas()
7479
setupTrackingArea()

crates/notification-macos/swift-lib/src/NotificationManager+Creation.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,14 @@ extension NotificationManager {
270270
closeButton.translatesAutoresizingMaskIntoConstraints = false
271271
clickableView.addSubview(closeButton, positioned: .above, relativeTo: nil)
272272

273-
let buttonOffset =
273+
let horizontalButtonOffset =
274274
isMacOS26() ? (CloseButtonConfig.size / 2) + 4 : (CloseButtonConfig.size / 2) - 2
275+
let verticalButtonOffset = buttonOverhang() - (CloseButtonConfig.size / 2)
275276
NSLayoutConstraint.activate([
276-
closeButton.centerYAnchor.constraint(equalTo: container.topAnchor, constant: buttonOffset),
277+
closeButton.centerYAnchor.constraint(
278+
equalTo: container.topAnchor, constant: verticalButtonOffset),
277279
closeButton.centerXAnchor.constraint(
278-
equalTo: container.leadingAnchor, constant: buttonOffset),
280+
equalTo: container.leadingAnchor, constant: horizontalButtonOffset),
279281
closeButton.widthAnchor.constraint(equalToConstant: CloseButtonConfig.size),
280282
closeButton.heightAnchor.constraint(equalToConstant: CloseButtonConfig.size),
281283
])

0 commit comments

Comments
 (0)