Files
wehub-resource-sync bd44b5aa08
Nix / Required Checks: Nix (push) Blocked by required conditions
Nix / check-zig-cache-hash (push) Waiting to run
Test / skip (push) Waiting to run
Test / Required Checks: Test (push) Blocked by required conditions
Test / build-bench (push) Blocked by required conditions
Test / list-examples (push) Blocked by required conditions
Test / Example ${{ matrix.dir }} (Windows) (push) Blocked by required conditions
Test / Example ${{ matrix.dir }} (push) Blocked by required conditions
Test / build-cmake (push) Blocked by required conditions
Test / test-lib-vt-pkgconfig (push) Blocked by required conditions
Test / build-flatpak (push) Blocked by required conditions
Test / build-snap (push) Blocked by required conditions
Test / build-linux (namespace-profile-ghostty-md-arm64) (push) Blocked by required conditions
Test / build-nix (namespace-profile-ghostty-md) (push) Blocked by required conditions
Test / build-libghostty-vt (aarch64-linux) (push) Blocked by required conditions
Test / build-libghostty-vt (aarch64-macos) (push) Blocked by required conditions
Test / build-libghostty-vt (wasm32-freestanding) (push) Blocked by required conditions
Test / build-libghostty-vt (x86_64-linux) (push) Blocked by required conditions
Test / build-libghostty-vt (x86_64-linux-musl) (push) Blocked by required conditions
Test / build-libghostty-vt (x86_64-macos) (push) Blocked by required conditions
Test / build-libghostty-vt (x86_64-windows-gnu) (push) Blocked by required conditions
Test / build-libghostty-vt-macos (aarch64-ios) (push) Blocked by required conditions
Test / build-libghostty-vt-macos (aarch64-macos) (push) Blocked by required conditions
Test / build-libghostty-vt-macos (x86_64-macos) (push) Blocked by required conditions
Test / build-libghostty-vt-android (aarch64-linux-android) (push) Blocked by required conditions
Test / build-libghostty-vt-android (arm-linux-androideabi) (push) Blocked by required conditions
Test / build-libghostty-vt-android (x86_64-linux-android) (push) Blocked by required conditions
Test / build-libghostty-vt-windows (push) Blocked by required conditions
Test / build-libghostty-windows-gnu (push) Blocked by required conditions
Test / build-linux (namespace-profile-ghostty-md) (push) Blocked by required conditions
Test / build-linux-libghostty (push) Blocked by required conditions
Test / build-nix (namespace-profile-ghostty-md-arm64) (push) Blocked by required conditions
Test / build-dist (push) Blocked by required conditions
Test / build-dist-lib-vt (push) Blocked by required conditions
Test / trigger-snap (push) Blocked by required conditions
Test / trigger-flatpak (push) Blocked by required conditions
Test / build-macos (push) Blocked by required conditions
Test / build-macos-freetype (push) Blocked by required conditions
Test / test (push) Blocked by required conditions
Test / test-lib-vt (push) Blocked by required conditions
Test / GTK x11=false wayland=false (push) Blocked by required conditions
Test / GTK x11=true wayland=false (push) Blocked by required conditions
Test / GTK x11=false wayland=true (push) Blocked by required conditions
Test / GTK x11=true wayland=true (push) Blocked by required conditions
Test / Build -Dsimd=false (push) Blocked by required conditions
Test / Build -Dsimd=true (push) Blocked by required conditions
Test / Build -Dsentry=false (push) Blocked by required conditions
Test / Build -Dsentry=true (push) Blocked by required conditions
Test / test-macos (push) Blocked by required conditions
Test / test-windows (push) Blocked by required conditions
Test / Build -Di18n=false (push) Blocked by required conditions
Test / Build -Di18n=true (push) Blocked by required conditions
Test / Build test/fuzz-libghostty (push) Blocked by required conditions
Test / zig-fmt (push) Blocked by required conditions
Test / GitHub Actions Pins (push) Blocked by required conditions
Test / prettier (push) Blocked by required conditions
Test / swiftlint (push) Blocked by required conditions
Test / alejandra (push) Blocked by required conditions
Test / typos (push) Blocked by required conditions
Test / shellcheck (push) Blocked by required conditions
Test / translations (push) Blocked by required conditions
Test / blueprint-compiler (push) Blocked by required conditions
Test / Test pkg/wuffs (push) Blocked by required conditions
Test / Test build on Debian 13 (push) Blocked by required conditions
Test / valgrind (push) Blocked by required conditions
chore: import upstream snapshot with attribution
2026-07-13 12:02:48 +08:00

120 lines
3.6 KiB
Swift

import SwiftUI
extension SplitView {
/// The split divider that is rendered and can be used to resize a split view.
struct Divider: View {
let direction: SplitViewDirection
let visibleSize: CGFloat
let invisibleSize: CGFloat
let color: Color
@Binding var split: CGFloat
private var visibleWidth: CGFloat? {
switch direction {
case .horizontal:
return visibleSize
case .vertical:
return nil
}
}
private var visibleHeight: CGFloat? {
switch direction {
case .horizontal:
return nil
case .vertical:
return visibleSize
}
}
private var invisibleWidth: CGFloat? {
switch direction {
case .horizontal:
return visibleSize + invisibleSize
case .vertical:
return nil
}
}
private var invisibleHeight: CGFloat? {
switch direction {
case .horizontal:
return nil
case .vertical:
return visibleSize + invisibleSize
}
}
private var pointerStyle: BackportPointerStyle {
return switch direction {
case .horizontal: .resizeLeftRight
case .vertical: .resizeUpDown
}
}
var body: some View {
ZStack {
Color.clear
.frame(width: invisibleWidth, height: invisibleHeight)
.contentShape(Rectangle()) // Makes it hit testable for pointerStyle
Rectangle()
.fill(color)
.frame(width: visibleWidth, height: visibleHeight)
}
.backport.pointerStyle(pointerStyle)
.onHover { isHovered in
// macOS 15+ we use the pointerStyle helper which is much less
// error-prone versus manual NSCursor push/pop
if #available(macOS 15, *) {
return
}
if isHovered {
switch direction {
case .horizontal:
NSCursor.resizeLeftRight.push()
case .vertical:
NSCursor.resizeUpDown.push()
}
} else {
NSCursor.pop()
}
}
.accessibilityElement(children: .ignore)
.accessibilityLabel(axLabel)
.accessibilityValue("\(Int(split * 100))%")
.accessibilityHint(axHint)
.accessibilityAddTraits(.isButton)
.accessibilityAdjustableAction { direction in
let adjustment: CGFloat = 0.025
switch direction {
case .increment:
split = min(split + adjustment, 0.9)
case .decrement:
split = max(split - adjustment, 0.1)
@unknown default:
break
}
}
}
private var axLabel: String {
switch direction {
case .horizontal:
return "Horizontal split divider"
case .vertical:
return "Vertical split divider"
}
}
private var axHint: String {
switch direction {
case .horizontal:
return "Drag to resize the left and right panes"
case .vertical:
return "Drag to resize the top and bottom panes"
}
}
}
}