diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-07-11 10:52:37 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-07-11 10:52:37 +0200 |
| commit | ceb1654ced23d545e1b2437751a70113cb1a2d2a (patch) | |
| tree | b1ed19aa19929e16cd771e1cfa0faf656c4ff273 /Map/Presentation/Base Components/MapTextEditor/HoverView.swift | |
| parent | 8564439356f4bcc3e21b19738eb87b4c0722c623 (diff) | |
Improve text rendering and component detection.
Diffstat (limited to 'Map/Presentation/Base Components/MapTextEditor/HoverView.swift')
| -rw-r--r-- | Map/Presentation/Base Components/MapTextEditor/HoverView.swift | 40 |
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), ]) |