feat: smoother rounded corners for the main window
This commit is contained in:
1 parent
d7b6b7c0ae
commit
5d0fff2276
3 files changed
+17
-3
No files matched your search
+1
-1
@@ -97,7 +97,7 @@ class App: AppCenterApplication, NSApplicationDelegate {
|
|||||||
// we put application code here which should be executed on init() and Preferences change
|
// we put application code here which should be executed on init() and Preferences change
|
||||||
func resetPreferencesDependentComponents() {
|
func resetPreferencesDependentComponents() {
|
||||||
ThumbnailsView.recycledViews = ThumbnailsView.recycledViews.map { _ in ThumbnailView() }
|
ThumbnailsView.recycledViews = ThumbnailsView.recycledViews.map { _ in ThumbnailView() }
|
||||||
thumbnailsPanel.thumbnailsView.layer!.cornerRadius = Preferences.windowCornerRadius
|
thumbnailsPanel.thumbnailsView.updateRoundedCorners(Preferences.windowCornerRadius)
|
||||||
}
|
}
|
||||||
|
|
||||||
func restart() {
|
func restart() {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class ThumbnailsPanel: NSPanel, NSWindowDelegate {
|
|||||||
hasShadow = false
|
hasShadow = false
|
||||||
titleVisibility = .hidden
|
titleVisibility = .hidden
|
||||||
backgroundColor = .clear
|
backgroundColor = .clear
|
||||||
contentView!.addSubview(thumbnailsView)
|
contentView! = thumbnailsView
|
||||||
// triggering AltTab before or during Space transition animation brings the window on the Space post-transition
|
// triggering AltTab before or during Space transition animation brings the window on the Space post-transition
|
||||||
collectionBehavior = .canJoinAllSpaces
|
collectionBehavior = .canJoinAllSpaces
|
||||||
// 2nd highest level possible; this allows the app to go on top of context menus
|
// 2nd highest level possible; this allows the app to go on top of context menus
|
||||||
|
|||||||
@@ -10,12 +10,26 @@ class ThumbnailsView: NSVisualEffectView {
|
|||||||
material = Preferences.windowMaterial
|
material = Preferences.windowMaterial
|
||||||
state = .active
|
state = .active
|
||||||
wantsLayer = true
|
wantsLayer = true
|
||||||
layer!.cornerRadius = Preferences.windowCornerRadius
|
updateRoundedCorners(Preferences.windowCornerRadius)
|
||||||
addSubview(scrollView)
|
addSubview(scrollView)
|
||||||
// TODO: think about this optimization more
|
// TODO: think about this optimization more
|
||||||
(1...100).forEach { _ in ThumbnailsView.recycledViews.append(ThumbnailView()) }
|
(1...100).forEach { _ in ThumbnailsView.recycledViews.append(ThumbnailView()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// using layer!.cornerRadius works but the corners are aliased; this custom approach gives smooth rounded corners
|
||||||
|
/// see https://stackoverflow.com/a/29386935/2249756
|
||||||
|
func updateRoundedCorners(_ cornerRadius: CGFloat) {
|
||||||
|
let edgeLength = 2.0 * cornerRadius + 1.0
|
||||||
|
maskImage = NSImage(size: NSSize(width: edgeLength, height: edgeLength), flipped: false) { rect in
|
||||||
|
let bezierPath = NSBezierPath(roundedRect: rect, xRadius: cornerRadius, yRadius: cornerRadius)
|
||||||
|
NSColor.black.set()
|
||||||
|
bezierPath.fill()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
maskImage!.capInsets = NSEdgeInsets(top: cornerRadius, left: cornerRadius, bottom: cornerRadius, right: cornerRadius)
|
||||||
|
maskImage!.resizingMode = .stretch
|
||||||
|
}
|
||||||
|
|
||||||
func nextRow(_ direction: Direction) -> [ThumbnailView]? {
|
func nextRow(_ direction: Direction) -> [ThumbnailView]? {
|
||||||
let step = direction == .down ? 1 : -1
|
let step = direction == .down ? 1 : -1
|
||||||
if let currentRow = Windows.focusedWindow()?.row {
|
if let currentRow = Windows.focusedWindow()?.row {
|
||||||
|
|||||||
Reference in new issue
Block a user