Skip to content

Fastest and only macOS Dictation app with on-device STT and custom trained AI enhancement model. Windows, iOS testflight! Android, Linux waitlist open! A local Wispr Flow alternative. Follow https://x.com/fluidvoiceapp for more

feat(theme): bound native button style hit areas to their shapes (#1090)

Siddhartha Singhfa5b90982e8e
diff --git a/Fluid.xcodeproj/project.pbxproj b/Fluid.xcodeproj/project.pbxproj
index c3591cf5..1d143099 100644
--- a/Fluid.xcodeproj/project.pbxproj
+++ b/Fluid.xcodeproj/project.pbxproj
@@ -51,6 +51,7 @@
D1A700000000000000000002 /* MeetingExistingAudioReplayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1A700000000000000000001 /* MeetingExistingAudioReplayTests.swift */; };
F1BD00000000000000000002 /* StripThinkingTagsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1BD00000000000000000001 /* StripThinkingTagsTests.swift */; };
D1A600000000000000000204 /* MeetingWindowSelectorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1A600000000000000000203 /* MeetingWindowSelectorTests.swift */; };
+ A11CE0030000000000000002 /* NativeButtonStylesHitTargetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A11CE0030000000000000001 /* NativeButtonStylesHitTargetTests.swift */; };
D1A600000000000000000206 /* MeetingRecoveryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1A600000000000000000205 /* MeetingRecoveryTests.swift */; };
B149D69C5977426AB8600002 /* MeetingAPIControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B149D69C5977426AB8600001 /* MeetingAPIControllerTests.swift */; };
BE0A00000000000000000002 /* MeetingTranscriptionBackendTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE0A00000000000000000001 /* MeetingTranscriptionBackendTests.swift */; };
@@ -200,6 +201,7 @@
D1A700000000000000000001 /* MeetingExistingAudioReplayTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeetingExistingAudioReplayTests.swift; sourceTree = "<group>"; };
F1BD00000000000000000001 /* StripThinkingTagsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StripThinkingTagsTests.swift; sourceTree = "<group>"; };
D1A600000000000000000203 /* MeetingWindowSelectorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeetingWindowSelectorTests.swift; sourceTree = "<group>"; };
+ A11CE0030000000000000001 /* NativeButtonStylesHitTargetTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeButtonStylesHitTargetTests.swift; sourceTree = "<group>"; };
D1A600000000000000000205 /* MeetingRecoveryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeetingRecoveryTests.swift; sourceTree = "<group>"; };
B149D69C5977426AB8600001 /* MeetingAPIControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeetingAPIControllerTests.swift; sourceTree = "<group>"; };
BE0A00000000000000000001 /* MeetingTranscriptionBackendTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeetingTranscriptionBackendTests.swift; sourceTree = "<group>"; };
@@ -429,6 +431,7 @@
D1A700000000000000000001 /* MeetingExistingAudioReplayTests.swift */,
F1BD00000000000000000001 /* StripThinkingTagsTests.swift */,
D1A600000000000000000203 /* MeetingWindowSelectorTests.swift */,
+ A11CE0030000000000000001 /* NativeButtonStylesHitTargetTests.swift */,
D1A600000000000000000205 /* MeetingRecoveryTests.swift */,
B149D69C5977426AB8600001 /* MeetingAPIControllerTests.swift */,
BE0A00000000000000000001 /* MeetingTranscriptionBackendTests.swift */,
@@ -801,6 +804,7 @@
D1A700000000000000000002 /* MeetingExistingAudioReplayTests.swift in Sources */,
F1BD00000000000000000002 /* StripThinkingTagsTests.swift in Sources */,
D1A600000000000000000204 /* MeetingWindowSelectorTests.swift in Sources */,
+ A11CE0030000000000000002 /* NativeButtonStylesHitTargetTests.swift in Sources */,
D1A600000000000000000206 /* MeetingRecoveryTests.swift in Sources */,
B149D69C5977426AB8600002 /* MeetingAPIControllerTests.swift in Sources */,
BE0A00000000000000000002 /* MeetingTranscriptionBackendTests.swift in Sources */,
diff --git a/Sources/Fluid/Theme/NativeButtonStyles.swift b/Sources/Fluid/Theme/NativeButtonStyles.swift
index c3af6e03..729a4276 100644
--- a/Sources/Fluid/Theme/NativeButtonStyles.swift
+++ b/Sources/Fluid/Theme/NativeButtonStyles.swift
@@ -165,6 +165,7 @@ struct GlassButtonStyle: ButtonStyle {
.padding(.horizontal, self.theme.metrics.spacing.lg)
.padding(.vertical, self.theme.metrics.spacing.sm)
.frame(height: self.height ?? 36)
+ .contentShape(self.shape)
.foregroundStyle(self.theme.palette.primaryText)
.background(self.theme.materials.card, in: self.shape)
.background(
@@ -244,6 +245,7 @@ struct PremiumButtonStyle: ButtonStyle {
.fontWeight(.semibold)
.frame(maxWidth: .infinity)
.frame(height: self.height)
+ .contentShape(self.shape)
.foregroundStyle(self.isRecording ? Color.white : self.theme.palette.primaryText)
.background(
self.shape
@@ -328,6 +330,7 @@ struct AccentButtonStyle: ButtonStyle {
.padding(.horizontal, self.compact ? 12 : self.theme.metrics.spacing.lg)
.padding(.vertical, self.compact ? 8 : self.theme.metrics.spacing.md)
.frame(minHeight: self.compact ? 32 : 36)
+ .contentShape(self.shape)
.foregroundStyle(Color.white)
.background(
self.shape
@@ -382,6 +385,7 @@ struct InlineButtonStyle: ButtonStyle {
.fontWeight(.medium)
.padding(.horizontal, self.theme.metrics.spacing.md)
.padding(.vertical, self.theme.metrics.spacing.xs)
+ .contentShape(self.shape)
.foregroundStyle(Color.white)
.background(
self.shape
@@ -558,6 +562,8 @@ struct SquareIconButtonStyle: ButtonStyle {
let foregroundColor = self.foreground ?? self.theme.palette.primaryText
self.configuration.label
+ .frame(minWidth: 24, minHeight: 24)
+ .contentShape(self.shape)
.foregroundStyle(foregroundColor)
.background(self.theme.materials.card, in: self.shape)
.background(
diff --git a/Tests/FluidDictationIntegrationTests/NativeButtonStylesHitTargetTests.swift b/Tests/FluidDictationIntegrationTests/NativeButtonStylesHitTargetTests.swift
new file mode 100644
index 00000000..a75c14ef
--- /dev/null
+++ b/Tests/FluidDictationIntegrationTests/NativeButtonStylesHitTargetTests.swift
@@ -0,0 +1,207 @@
+import AppKit
+@testable import FluidVoice_Debug
+import SwiftUI
+import XCTest
+
+/// Delivers real mouse events to buttons using the shared native button
+/// styles and asserts each style's clickable region matches its visible shape.
+@MainActor
+final class NativeButtonStylesHitTargetTests: XCTestCase {
+ /// Empty margin around the view under test so clicks just outside its
+ /// bounds still land inside the hosting view and reach SwiftUI hit testing.
+ private static let margin: CGFloat = 20
+
+ private final class HitTestWindow: NSWindow {
+ override var canBecomeKey: Bool {
+ true
+ }
+
+ override var canBecomeMain: Bool {
+ true
+ }
+ }
+
+ private final class HitTestHostingView: NSHostingView<AnyView> {
+ override func acceptsFirstMouse(for event: NSEvent?) -> Bool {
+ true
+ }
+ }
+
+ private struct Harness {
+ let window: HitTestWindow
+ let hostingView: HitTestHostingView
+ let targetSize: CGSize
+
+ /// Converts a point in the target's top-left-origin space into the
+ /// hosting view's coordinate space.
+ func hostPoint(_ x: CGFloat, _ y: CGFloat) -> NSPoint {
+ let margin = NativeButtonStylesHitTargetTests.margin
+ let flippedY = self.hostingView.isFlipped ? margin + y : self.hostingView.bounds.height - margin - y
+ return NSPoint(x: margin + x, y: flippedY)
+ }
+
+ func tearDown() {
+ self.window.contentView = nil
+ self.window.orderOut(nil)
+ self.window.close()
+ RunLoop.current.run(until: Date().addingTimeInterval(0.02))
+ }
+ }
+
+ private struct StyleCase {
+ let name: String
+ let makeButton: (@escaping () -> Void) -> AnyView
+ }
+
+ private var eventNumber = 0
+
+ private func makeHarness(_ content: some View) -> Harness {
+ let targetSize = NSHostingView(rootView: content.fixedSize()).fittingSize
+ let root = AnyView(
+ content
+ .frame(width: targetSize.width, height: targetSize.height)
+ .padding(Self.margin)
+ )
+ let size = NSSize(width: targetSize.width + Self.margin * 2, height: targetSize.height + Self.margin * 2)
+ let hostingView = HitTestHostingView(rootView: root)
+ hostingView.frame = NSRect(origin: .zero, size: size)
+
+ let window = HitTestWindow(
+ contentRect: NSRect(origin: NSPoint(x: -10_000, y: -10_000), size: size),
+ styleMask: [.borderless],
+ backing: .buffered,
+ defer: false
+ )
+ window.isReleasedWhenClosed = false
+ window.contentView = hostingView
+ window.makeKeyAndOrderFront(nil)
+ hostingView.layoutSubtreeIfNeeded()
+ RunLoop.current.run(until: Date().addingTimeInterval(0.05))
+ return Harness(window: window, hostingView: hostingView, targetSize: targetSize)
+ }
+
+ private func simulateClick(in window: NSWindow, at point: NSPoint, in view: NSView? = nil) throws {
+ let windowPoint = view.map { $0.convert(point, to: nil) } ?? point
+ let timestamp = ProcessInfo.processInfo.systemUptime
+
+ self.eventNumber += 1
+ let down = try XCTUnwrap(NSEvent.mouseEvent(
+ with: .leftMouseDown,
+ location: windowPoint,
+ modifierFlags: [],
+ timestamp: timestamp,
+ windowNumber: window.windowNumber,
+ context: nil,
+ eventNumber: self.eventNumber,
+ clickCount: 1,
+ pressure: 1.0
+ ))
+ self.eventNumber += 1
+ let up = try XCTUnwrap(NSEvent.mouseEvent(
+ with: .leftMouseUp,
+ location: windowPoint,
+ modifierFlags: [],
+ timestamp: timestamp + 0.05,
+ windowNumber: window.windowNumber,
+ context: nil,
+ eventNumber: self.eventNumber,
+ clickCount: 1,
+ pressure: 0.0
+ ))
+
+ window.sendEvent(down)
+ // Let SwiftUI's gesture recognizer observe the press before the release.
+ RunLoop.current.run(until: Date().addingTimeInterval(0.01))
+ window.sendEvent(up)
+ for _ in 0..<5 {
+ RunLoop.current.run(until: Date().addingTimeInterval(0.01))
+ }
+ }
+
+ private let styleCases: [StyleCase] = [
+ StyleCase(name: "GlassButtonStyle") { action in
+ AnyView(Button("Action", action: action).buttonStyle(GlassButtonStyle()))
+ },
+ StyleCase(name: "PremiumButtonStyle") { action in
+ AnyView(Button("Action", action: action).buttonStyle(PremiumButtonStyle()).frame(width: 160))
+ },
+ StyleCase(name: "AccentButtonStyle") { action in
+ AnyView(Button("Action", action: action).buttonStyle(AccentButtonStyle()))
+ },
+ StyleCase(name: "InlineButtonStyle") { action in
+ AnyView(Button("Action", action: action).buttonStyle(InlineButtonStyle()))
+ },
+ StyleCase(name: "SquareIconButtonStyle") { action in
+ AnyView(
+ Button(action: action) {
+ Image(systemName: "gear").frame(width: 28, height: 28)
+ }
+ .buttonStyle(SquareIconButtonStyle())
+ )
+ },
+ ]
+
+ func testButtonStylesAcceptClicksAcrossTheirShape() throws {
+ for style in self.styleCases {
+ var clicks = 0
+ let harness = self.makeHarness(style.makeButton { clicks += 1 })
+ defer { harness.tearDown() }
+ let size = harness.targetSize
+
+ for (x, y) in [(size.width / 2, size.height / 2), (3, size.height / 2), (size.width - 3, size.height / 2)] {
+ try self.simulateClick(in: harness.window, at: harness.hostPoint(x, y), in: harness.hostingView)
+ }
+ XCTAssertEqual(clicks, 3, "\(style.name) must accept clicks at its center and near its padded edges")
+ }
+ }
+
+ func testButtonStylesRejectClicksOutsideTheirShape() throws {
+ for style in self.styleCases {
+ var clicks = 0
+ let harness = self.makeHarness(style.makeButton { clicks += 1 })
+ defer { harness.tearDown() }
+ let size = harness.targetSize
+
+ // First prove this harness window actively delivers clicks to the button
+ try self.simulateClick(in: harness.window, at: harness.hostPoint(size.width / 2, size.height / 2), in: harness.hostingView)
+ XCTAssertEqual(clicks, 1, "\(style.name) baseline center click must register")
+ clicks = 0
+
+ // Corners clipped by the rounded / capsule shape, then just outside the bounds.
+ let outsidePoints: [(CGFloat, CGFloat)] = [
+ (1, 1),
+ (size.width - 1, 1),
+ (1, size.height - 1),
+ (size.width - 1, size.height - 1),
+ (-4, size.height / 2),
+ (size.width + 4, size.height / 2),
+ ]
+ for (x, y) in outsidePoints {
+ try self.simulateClick(in: harness.window, at: harness.hostPoint(x, y), in: harness.hostingView)
+ }
+ XCTAssertEqual(clicks, 0, "\(style.name) must ignore clicks outside its shape")
+ }
+ }
+
+ func testSquareIconButtonStyleEnforcesMinimumHitTarget() throws {
+ var clicks = 0
+ let button = Button {
+ clicks += 1
+ } label: {
+ Image(systemName: "xmark").font(.system(size: 8))
+ }
+ .buttonStyle(SquareIconButtonStyle())
+
+ let harness = self.makeHarness(button)
+ defer { harness.tearDown() }
+ XCTAssertGreaterThanOrEqual(harness.targetSize.width, 24, "SquareIconButtonStyle must be at least 24pt wide")
+ XCTAssertGreaterThanOrEqual(harness.targetSize.height, 24, "SquareIconButtonStyle must be at least 24pt tall")
+
+ // Near each edge midpoint of the 24pt square, well outside the small glyph.
+ let size = harness.targetSize
+ for (x, y) in [(3, size.height / 2), (size.width - 3, size.height / 2), (size.width / 2, 3), (size.width / 2, size.height - 3)] {
+ try self.simulateClick(in: harness.window, at: harness.hostPoint(x, y), in: harness.hostingView)
+ }
+ XCTAssertEqual(clicks, 4, "SquareIconButtonStyle must accept clicks across its minimum 24pt target")
+ }
+}