Skip to content

Commit 5c9dfc3

Browse files
committed
feat: add liquid glass to slash command menu
1 parent 7a33936 commit 5c9dfc3

2 files changed

Lines changed: 74 additions & 11 deletions

File tree

‎EdgeMark/Core/Editor/SlashCommandPopup.swift‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,6 @@ final class SlashCommandPopup: NSObject, NSTableViewDataSource, NSTableViewDeleg
5858
panel.level = .popUpMenu
5959
panel.hasShadow = true
6060

61-
// Container with rounded corners
62-
let container = NSVisualEffectView(frame: NSRect(x: 0, y: 0, width: panelWidth, height: panelHeight))
63-
container.material = .popover
64-
container.blendingMode = .behindWindow
65-
container.state = .active
66-
container.wantsLayer = true
67-
container.layer?.cornerRadius = 8
68-
container.layer?.masksToBounds = true
69-
7061
// Table view
7162
let column = NSTableColumn(identifier: NSUserInterfaceItemIdentifier("command"))
7263
column.width = panelWidth - 4
@@ -83,14 +74,21 @@ final class SlashCommandPopup: NSObject, NSTableViewDataSource, NSTableViewDeleg
8374
tableView.target = self
8475
tableView.doubleAction = #selector(rowDoubleClicked)
8576

86-
let scrollView = NSScrollView(frame: container.bounds)
77+
let contentFrame = NSRect(x: 0, y: 0, width: panelWidth, height: panelHeight)
78+
let scrollView = NSScrollView(frame: contentFrame)
8779
scrollView.documentView = tableView
8880
scrollView.hasVerticalScroller = true
8981
scrollView.autohidesScrollers = true
9082
scrollView.drawsBackground = false
9183
scrollView.autoresizingMask = [.width, .height]
9284

93-
container.addSubview(scrollView)
85+
let container = AppKitGlassSurface(
86+
frame: contentFrame,
87+
contentView: scrollView,
88+
style: .regular,
89+
cornerRadius: 8,
90+
isInteractive: true,
91+
)
9492
panel.contentView = container
9593

9694
self.panel = panel
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import AppKit
2+
3+
/// Availability boundary for AppKit-owned floating surfaces that use Liquid Glass.
4+
final class AppKitGlassSurface: NSView {
5+
enum Style {
6+
case regular
7+
case clear
8+
}
9+
10+
init(
11+
frame: NSRect,
12+
contentView: NSView,
13+
style: Style = .regular,
14+
cornerRadius: CGFloat,
15+
tintColor: NSColor? = nil,
16+
isInteractive: Bool = false,
17+
) {
18+
super.init(frame: frame)
19+
20+
wantsLayer = true
21+
layer?.cornerRadius = cornerRadius
22+
layer?.masksToBounds = true
23+
24+
contentView.frame = bounds
25+
contentView.autoresizingMask = [.width, .height]
26+
27+
if #available(macOS 26.0, *) {
28+
let glassView = NSGlassEffectView(frame: bounds)
29+
glassView.autoresizingMask = [.width, .height]
30+
glassView.cornerRadius = cornerRadius
31+
glassView.style = style.glassStyle
32+
glassView.tintColor = tintColor
33+
glassView.contentView = contentView
34+
if #available(macOS 27.0, *) {
35+
glassView.effectIsInteractive = isInteractive
36+
}
37+
addSubview(glassView)
38+
} else {
39+
let materialView = NSVisualEffectView(frame: bounds)
40+
materialView.autoresizingMask = [.width, .height]
41+
materialView.material = .popover
42+
materialView.blendingMode = .behindWindow
43+
materialView.state = .active
44+
materialView.addSubview(contentView)
45+
addSubview(materialView)
46+
}
47+
}
48+
49+
@available(*, unavailable)
50+
required init?(coder _: NSCoder) {
51+
fatalError("init(coder:) has not been implemented")
52+
}
53+
}
54+
55+
@available(macOS 26.0, *)
56+
private extension AppKitGlassSurface.Style {
57+
var glassStyle: NSGlassEffectView.Style {
58+
switch self {
59+
case .regular:
60+
.regular
61+
case .clear:
62+
.clear
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)