macos: use pointerStyle for SplitView Divider

This commit is contained in:
Mitchell Hashimoto
2024-09-20 21:46:39 -07:00
parent 0e1258b7fe
commit c01bdc6d7c
2 changed files with 17 additions and 2 deletions

View File

@ -33,9 +33,9 @@ extension Backport where Content: View {
} }
} }
func pointerStyle(_ style: BackportPointerStyle) -> some View { func pointerStyle(_ style: BackportPointerStyle?) -> some View {
if #available(macOS 15, *) { if #available(macOS 15, *) {
return content.pointerStyle(style.official) return content.pointerStyle(style?.official)
} else { } else {
return content return content
} }

View File

@ -44,15 +44,30 @@ extension SplitView {
} }
} }
private var pointerStyle: BackportPointerStyle {
return switch (direction) {
case .horizontal: .resizeLeftRight
case .vertical: .resizeUpDown
}
}
var body: some View { var body: some View {
ZStack { ZStack {
Color.clear Color.clear
.frame(width: invisibleWidth, height: invisibleHeight) .frame(width: invisibleWidth, height: invisibleHeight)
.contentShape(Rectangle()) // Makes it hit testable for pointerStyle
Rectangle() Rectangle()
.fill(color) .fill(color)
.frame(width: visibleWidth, height: visibleHeight) .frame(width: visibleWidth, height: visibleHeight)
} }
.backport.pointerStyle(pointerStyle)
.onHover { isHovered in .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) { if (isHovered) {
switch (direction) { switch (direction) {
case .horizontal: case .horizontal: