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

refactor(ui): share glass actions and edit controls

altic-devfbe61e0fbaf0
diff --git a/Sources/Fluid/Theme/Components/FluidEditControls.swift b/Sources/Fluid/Theme/Components/FluidEditControls.swift
new file mode 100644
index 00000000..3008c646
--- /dev/null
+++ b/Sources/Fluid/Theme/Components/FluidEditControls.swift
@@ -0,0 +1,44 @@
+import SwiftUI
+
+struct FluidPencilShape: Shape {
+ func path(in rect: CGRect) -> Path {
+ var path = Path()
+ func point(_ x: CGFloat, _ y: CGFloat) -> CGPoint { CGPoint(x: rect.minX + x * rect.width, y: rect.minY + y * rect.height) }
+ path.move(to: point(0.12, 0.88))
+ path.addLine(to: point(0.19, 0.62))
+ path.addLine(to: point(0.69, 0.12))
+ path.addQuadCurve(to: point(0.82, 0.12), control: point(0.755, 0.055))
+ path.addLine(to: point(0.88, 0.18))
+ path.addQuadCurve(to: point(0.88, 0.31), control: point(0.945, 0.245))
+ path.addLine(to: point(0.38, 0.81))
+ path.closeSubpath()
+ path.move(to: point(0.62, 0.19))
+ path.addLine(to: point(0.81, 0.38))
+ path.move(to: point(0.19, 0.62))
+ path.addLine(to: point(0.38, 0.81))
+ return path
+ }
+}
+
+struct FluidHoverIconButtonStyle: ButtonStyle {
+ func makeBody(configuration: Configuration) -> some View {
+ HoverContent(configuration: configuration)
+ }
+
+ private struct HoverContent: View {
+ let configuration: ButtonStyle.Configuration
+ @Environment(\.isEnabled) private var isEnabled
+ @Environment(\.theme) private var theme
+ @State private var isHovered = false
+
+ var body: some View {
+ self.configuration.label
+ .foregroundStyle(self.isHovered && self.isEnabled ? self.theme.palette.accent : self.theme.palette.secondaryText)
+ .padding(4)
+ .background(RoundedRectangle(cornerRadius: 7).fill(self.theme.palette.accent.opacity(self.isEnabled && (self.isHovered || self.configuration.isPressed) ? 0.14 : 0)))
+ .contentShape(Rectangle())
+ .opacity(self.isEnabled ? 1 : 0.4)
+ .onHover { self.isHovered = $0 }
+ }
+ }
+}
diff --git a/Sources/Fluid/Theme/Components/FluidGlassControls.swift b/Sources/Fluid/Theme/Components/FluidGlassControls.swift
index 1f062b3f..c283763f 100644
--- a/Sources/Fluid/Theme/Components/FluidGlassControls.swift
+++ b/Sources/Fluid/Theme/Components/FluidGlassControls.swift
@@ -1,5 +1,108 @@
import SwiftUI
+/// A stationary blue invitation with quiet motion inside; capture uses a static red control.
+struct FluidRecordInvitationStyle: ButtonStyle {
+ let inviting: Bool
+ let recording: Bool
+ var prominent = true
+ var fillsWidth = false
+ @Environment(\.theme) private var theme
+ @Environment(\.accessibilityReduceMotion) private var reduceMotion
+ @Environment(\.accessibilityReduceTransparency) private var reduceTransparency
+ @Environment(\.scenePhase) private var scenePhase
+ @Environment(\.isEnabled) private var isEnabled
+ @State private var visible = false
+ @State private var hovered = false
+
+ func makeBody(configuration: Configuration) -> some View {
+ let animate = self.visible && self.inviting && self.isEnabled && !self.reduceMotion && self.scenePhase == .active
+ let highlighted = self.hovered && self.isEnabled
+ configuration.label
+ .font(self.theme.typography.bodyStrong)
+ .foregroundStyle(self.prominent ? Color.white : self.theme.palette.primaryText)
+ .padding(.horizontal, 22)
+ .frame(minWidth: 144, maxWidth: self.fillsWidth ? .infinity : nil, minHeight: FluidButtonSize.large.controlHeight)
+ .background {
+ Group {
+ if self.prominent {
+ FluidRecordInvitationSurface(
+ animate: animate,
+ recording: self.recording,
+ reduceTransparency: self.reduceTransparency
+ )
+ } else {
+ Capsule().fill(self.theme.palette.contentBackground)
+ }
+ }
+ .brightness(highlighted ? 0.08 : 0)
+ .animation(self.reduceMotion ? nil : .easeOut(duration: 0.18), value: highlighted)
+ }
+ .overlay {
+ Capsule().strokeBorder((self.prominent ? Color.white : self.theme.palette.secondaryText).opacity(configuration.isPressed ? 0.6 : (highlighted ? 0.48 : 0.16)), lineWidth: 1)
+ .animation(self.reduceMotion ? nil : .easeOut(duration: 0.18), value: highlighted)
+ .allowsHitTesting(false)
+ }
+ .contentShape(Capsule())
+ .opacity(self.isEnabled ? 1 : 0.65)
+ .fixedSize(horizontal: !self.fillsWidth, vertical: false)
+ .onHover { self.hovered = $0 && self.isEnabled }
+ .onChange(of: self.isEnabled) { _, enabled in
+ if !enabled { self.hovered = false }
+ }
+ .onAppear { self.visible = true }
+ .onDisappear { self.visible = false; self.hovered = false }
+ }
+}
+
+/// Only this small background redraws. The label, hit target, and surrounding layout stay fixed.
+private struct FluidRecordInvitationSurface: View {
+ let animate: Bool
+ let recording: Bool
+ let reduceTransparency: Bool
+
+ var body: some View {
+ ZStack {
+ if self.recording {
+ Color.red
+ } else {
+ LinearGradient(
+ colors: [Color(red: 0.09, green: 0.34, blue: 0.78), Color(red: 0.15, green: 0.49, blue: 0.94), Color(red: 0.07, green: 0.35, blue: 0.82)],
+ startPoint: .leading,
+ endPoint: .trailing
+ )
+ TimelineView(.animation(minimumInterval: 1.0 / 24, paused: !self.animate)) { timeline in
+ let time = self.animate ? timeline.date.timeIntervalSinceReferenceDate.truncatingRemainder(dividingBy: 24) : 0
+ Canvas { context, size in
+ guard size.width > 0, size.height > 0 else { return }
+ // One broad highlight travels slowly beneath the dots; no blur or particles to retain.
+ if !self.reduceTransparency {
+ let centre = CGPoint(x: size.width * (0.5 + 0.28 * sin(time / 24 * .pi * 2)), y: size.height * 0.35)
+ context.fill(Path(CGRect(origin: .zero, size: size)), with: .radialGradient(
+ Gradient(colors: [.white.opacity(0.12), .clear]),
+ center: centre,
+ startRadius: 0,
+ endRadius: size.width * 0.55
+ ))
+ }
+ for index in 0..<12 {
+ let fraction = (Double(index) * 0.61_803_398_875 + time / 24).truncatingRemainder(dividingBy: 1)
+ let x = size.width * fraction
+ let y = size.height * (0.18 + Double((index * 7) % 13) / 13 * 0.64)
+ let diameter = 1.5 + Double(index % 3) * 0.45
+ let edgeFade = min(1, min(fraction, 1 - fraction) * 12)
+ let opacity = (self.reduceTransparency ? 0.45 : 0.32) * edgeFade
+ context.fill(Path(ellipseIn: CGRect(x: x, y: y, width: diameter, height: diameter)), with: .color(.white.opacity(opacity)))
+ }
+ }
+ }
+ }
+ }
+ .clipShape(Capsule())
+ .allowsHitTesting(false)
+ .accessibilityHidden(true)
+ }
+}
+
struct ProviderDefaultButton: View {
let isCurrent: Bool
let isEnabled: Bool