macos: add hover styles to search buttons, cursor changes

pull/9734/head
Mitchell Hashimoto 2025-11-27 12:56:49 -08:00
parent 4ff0e0c9d2
commit 5c1679209d
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
1 changed files with 33 additions and 4 deletions

View File

@ -405,7 +405,7 @@ extension Ghostty {
var body: some View { var body: some View {
GeometryReader { geo in GeometryReader { geo in
HStack(spacing: 8) { HStack(spacing: 4) {
TextField("Search", text: $searchState.needle) TextField("Search", text: $searchState.needle)
.textFieldStyle(.plain) .textFieldStyle(.plain)
.frame(width: 180) .frame(width: 180)
@ -451,7 +451,7 @@ extension Ghostty {
}) { }) {
Image(systemName: "chevron.up") Image(systemName: "chevron.up")
} }
.buttonStyle(.borderless) .buttonStyle(SearchButtonStyle())
Button(action: { Button(action: {
guard let surface = surfaceView.surface else { return } guard let surface = surfaceView.surface else { return }
@ -460,12 +460,12 @@ extension Ghostty {
}) { }) {
Image(systemName: "chevron.down") Image(systemName: "chevron.down")
} }
.buttonStyle(.borderless) .buttonStyle(SearchButtonStyle())
Button(action: onClose) { Button(action: onClose) {
Image(systemName: "xmark") Image(systemName: "xmark")
} }
.buttonStyle(.borderless) .buttonStyle(SearchButtonStyle())
} }
.padding(8) .padding(8)
.background(.background) .background(.background)
@ -556,6 +556,35 @@ extension Ghostty {
return point.y < midY ? .topRight : .bottomRight return point.y < midY ? .topRight : .bottomRight
} }
} }
struct SearchButtonStyle: ButtonStyle {
@State private var isHovered = false
func makeBody(configuration: Configuration) -> some View {
configuration.label
.foregroundStyle(isHovered || configuration.isPressed ? .primary : .secondary)
.padding(.horizontal, 2)
.frame(height: 26)
.background(
RoundedRectangle(cornerRadius: 6)
.fill(backgroundColor(isPressed: configuration.isPressed))
)
.onHover { hovering in
isHovered = hovering
}
.backport.pointerStyle(.link)
}
private func backgroundColor(isPressed: Bool) -> Color {
if isPressed {
return Color.primary.opacity(0.2)
} else if isHovered {
return Color.primary.opacity(0.1)
} else {
return Color.clear
}
}
}
} }
/// A surface is terminology in Ghostty for a terminal surface, or a place where a terminal is actually drawn /// A surface is terminology in Ghostty for a terminal surface, or a place where a terminal is actually drawn