aboutsummaryrefslogtreecommitdiff
path: root/Map/Presentation/Base Components/MapTextEditor/HoverView.swift
diff options
context:
space:
mode:
Diffstat (limited to 'Map/Presentation/Base Components/MapTextEditor/HoverView.swift')
-rw-r--r--Map/Presentation/Base Components/MapTextEditor/HoverView.swift40
1 files changed, 31 insertions, 9 deletions
diff --git a/Map/Presentation/Base Components/MapTextEditor/HoverView.swift b/Map/Presentation/Base Components/MapTextEditor/HoverView.swift
index 4e42b99..bd6de42 100644
--- a/Map/Presentation/Base Components/MapTextEditor/HoverView.swift
+++ b/Map/Presentation/Base Components/MapTextEditor/HoverView.swift
@@ -37,21 +37,45 @@ class HoverView: NSView {
}
private func setupView(message: String, actionLabel: String) {
- wantsLayer = true
- layer?.backgroundColor = NSColor.controlBackgroundColor.cgColor
- layer?.borderColor = NSColor.separatorColor.cgColor
- layer?.borderWidth = 1
- layer?.cornerRadius = 8
+ let box = NSBox()
+ box.boxType = .custom
+ box.borderType = .lineBorder
+ box.cornerRadius = 8
+ box.borderColor = NSColor.separatorColor
+ box.fillColor = NSColor.controlBackgroundColor
+
+ addSubview(box)
+ box.translatesAutoresizingMaskIntoConstraints = false
+ NSLayoutConstraint.activate([
+ box.topAnchor.constraint(equalTo: topAnchor),
+ box.leadingAnchor.constraint(equalTo: leadingAnchor),
+ box.trailingAnchor.constraint(equalTo: trailingAnchor),
+ box.bottomAnchor.constraint(equalTo: bottomAnchor),
+ ])
let label = NSTextField(labelWithString: message)
label.font = NSFont.Theme.SmallControl.regular
label.textColor = NSColor.labelColor
+ label.backgroundColor = .clear
let button = NSButton(title: actionLabel, target: self, action: #selector(buttonClicked))
button.bezelStyle = .accessoryBarAction
button.font = NSFont.Theme.SmallControl.emphasized
button.controlSize = .mini
+ // Configure button for hover and active states
+ button.wantsLayer = true
+ button.layer?.cornerRadius = 4
+
+ // Set up tracking area for button hover effects
+ let buttonTrackingArea = NSTrackingArea(
+ rect: button.bounds,
+ options: [.mouseEnteredAndExited, .activeInKeyWindow, .inVisibleRect],
+ owner: button,
+ userInfo: nil
+ )
+ button.addTrackingArea(buttonTrackingArea)
+
addSubview(label)
addSubview(button)
@@ -59,14 +83,12 @@ class HoverView: NSView {
button.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
- label.topAnchor.constraint(equalTo: topAnchor, constant: 8),
+ label.centerYAnchor.constraint(equalTo: centerYAnchor),
label.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 8),
- label.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -8),
- button.topAnchor.constraint(equalTo: topAnchor, constant: 8),
+ button.firstBaselineAnchor.constraint(equalTo: label.firstBaselineAnchor),
button.leadingAnchor.constraint(equalTo: label.trailingAnchor, constant: 8),
button.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -8),
- button.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -8),
heightAnchor.constraint(equalToConstant: 32),
])