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, *) {
return content.pointerStyle(style.official)
return content.pointerStyle(style?.official)
} else {
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 {
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: