Skip to content

Commit

Permalink
Fix splitView divider on macOS 11 and 12
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlaubischlump committed Feb 24, 2023
1 parent 4a74187 commit c26c246
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 16 deletions.
16 changes: 8 additions & 8 deletions LocationSimulator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
635C95B6299AE7A6002FB162 /* ToolbarController+NSToolbarDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 635C95B5299AE7A6002FB162 /* ToolbarController+NSToolbarDelegate.swift */; };
635C95B8299AF2FE002FB162 /* SidebarStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 635C95B7299AF2FE002FB162 /* SidebarStyle.swift */; };
635C95BA299C378B002FB162 /* SearchBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 635C95B9299C378B002FB162 /* SearchBarView.swift */; };
635C95C4299D931A002FB162 /* SuggestionPopup in Frameworks */ = {isa = PBXBuildFile; productRef = 635C95C3299D931A002FB162 /* SuggestionPopup */; };
635C95C629A19A98002FB162 /* GeocodingTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 635C95C529A19A98002FB162 /* GeocodingTask.swift */; };
635C95D529A83A2E002FB162 /* SuggestionPopup in Frameworks */ = {isa = PBXBuildFile; productRef = 635C95D429A83A2E002FB162 /* SuggestionPopup */; };
635CF717280E03820092A99B /* DonateWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 635CF716280E03820092A99B /* DonateWindowController.swift */; };
635CF719280E039B0092A99B /* DonateSidebarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 635CF718280E039B0092A99B /* DonateSidebarViewController.swift */; };
635CF71B280E03AB0092A99B /* DonateDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 635CF71A280E03AB0092A99B /* DonateDetailViewController.swift */; };
Expand Down Expand Up @@ -350,7 +350,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
635C95C4299D931A002FB162 /* SuggestionPopup in Frameworks */,
635C95D529A83A2E002FB162 /* SuggestionPopup in Frameworks */,
63D734FE27E90C800044918C /* CLogger in Frameworks */,
635F9BBC297F3BE300F0B2E1 /* Downloader in Frameworks */,
635F9BB0297F36D100F0B2E1 /* LocationSpoofer in Frameworks */,
Expand Down Expand Up @@ -1034,7 +1034,7 @@
63D734FD27E90C800044918C /* CLogger */,
635F9BAF297F36D100F0B2E1 /* LocationSpoofer */,
635F9BBB297F3BE300F0B2E1 /* Downloader */,
635C95C3299D931A002FB162 /* SuggestionPopup */,
635C95D429A83A2E002FB162 /* SuggestionPopup */,
);
productName = LocationSimulator;
productReference = 13BA351620A433EE00A0431C /* LocationSimulator.app */;
Expand Down Expand Up @@ -1112,7 +1112,7 @@
63D734FC27E90C800044918C /* XCRemoteSwiftPackageReference "CLogger" */,
63016FAE2915CB0F00785E9B /* XCRemoteSwiftPackageReference "LocationSpoofer" */,
635F9BBA297F3BE300F0B2E1 /* XCRemoteSwiftPackageReference "Downloader" */,
635C95C2299D931A002FB162 /* XCRemoteSwiftPackageReference "SuggestionPopup" */,
635C95D329A83A2E002FB162 /* XCRemoteSwiftPackageReference "SuggestionPopup" */,
);
productRefGroup = 13BA351720A433EE00A0431C /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -1791,12 +1791,12 @@
minimumVersion = 0.0.2;
};
};
635C95C2299D931A002FB162 /* XCRemoteSwiftPackageReference "SuggestionPopup" */ = {
635C95D329A83A2E002FB162 /* XCRemoteSwiftPackageReference "SuggestionPopup" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/Schlaubischlump/SuggestionPopup.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.0.4;
minimumVersion = 0.0.6;
};
};
635F9BBA297F3BE300F0B2E1 /* XCRemoteSwiftPackageReference "Downloader" */ = {
Expand All @@ -1823,9 +1823,9 @@
package = 635C137F2596EA5700BEB53B /* XCRemoteSwiftPackageReference "GPXParser" */;
productName = GPXParser;
};
635C95C3299D931A002FB162 /* SuggestionPopup */ = {
635C95D429A83A2E002FB162 /* SuggestionPopup */ = {
isa = XCSwiftPackageProductDependency;
package = 635C95C2299D931A002FB162 /* XCRemoteSwiftPackageReference "SuggestionPopup" */;
package = 635C95D329A83A2E002FB162 /* XCRemoteSwiftPackageReference "SuggestionPopup" */;
productName = SuggestionPopup;
};
635F9BAF297F36D100F0B2E1 /* LocationSpoofer */ = {
Expand Down
16 changes: 8 additions & 8 deletions LocationSimulator/Storyboard/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -2745,9 +2745,9 @@
<autoresizingMask key="autoresizingMask"/>
<subviews>
<scrollView borderType="line" autohidesScrollers="YES" horizontalLineScroll="24" horizontalPageScroll="10" verticalLineScroll="24" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vrm-tL-iw9">
<rect key="frame" x="20" y="35" width="227" height="250"/>
<rect key="frame" x="20" y="35" width="207" height="250"/>
<clipView key="contentView" id="3ld-57-Iej">
<rect key="frame" x="1" y="1" width="225" height="248"/>
<rect key="frame" x="1" y="1" width="205" height="248"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" alternatingRowBackgroundColors="YES" columnReordering="NO" multipleSelection="NO" autosaveColumns="NO" rowHeight="24" rowSizeStyle="automatic" viewBased="YES" id="cnR-eo-JKu">
Expand Down Expand Up @@ -2800,8 +2800,8 @@
</tableView>
</subviews>
</clipView>
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="C3E-8o-9An">
<rect key="frame" x="1" y="233" width="85" height="16"/>
<scroller key="horizontalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="C3E-8o-9An">
<rect key="frame" x="1" y="233" width="205" height="16"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="cLO-Jm-K3v">
Expand All @@ -2810,7 +2810,7 @@
</scroller>
</scrollView>
<segmentedControl verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="2rS-KZ-F6L">
<rect key="frame" x="20" y="283" width="305" height="23"/>
<rect key="frame" x="20" y="283" width="187" height="23"/>
<segmentedCell key="cell" borderStyle="border" alignment="left" style="smallSquare" trackingMode="selectOne" id="bBe-oX-oAl">
<font key="font" metaFont="system"/>
<segments>
Expand All @@ -2824,7 +2824,7 @@
</connections>
</segmentedControl>
<segmentedControl verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="VaG-O8-E1G" userLabel="Add Remove Segment">
<rect key="frame" x="20" y="14" width="305" height="23"/>
<rect key="frame" x="20" y="14" width="207" height="23"/>
<segmentedCell key="cell" borderStyle="border" alignment="left" style="smallSquare" trackingMode="momentary" id="5v1-mC-Drn">
<font key="font" metaFont="system"/>
<segments>
Expand All @@ -2841,7 +2841,7 @@
</connections>
</segmentedControl>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="BHm-g2-ImW">
<rect key="frame" x="18" y="388" width="307" height="18"/>
<rect key="frame" x="18" y="388" width="189" height="18"/>
<buttonCell key="cell" type="check" title="Custom DeveloperDiskImagePath" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="WMO-1M-pcy">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
Expand Down Expand Up @@ -2881,7 +2881,7 @@
</connections>
</button>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="A0t-cb-vDt">
<rect key="frame" x="66" y="354" width="259" height="25"/>
<rect key="frame" x="66" y="354" width="141" height="25"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="border" drawsBackground="YES" id="Qge-O6-1Wz">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ class SplitViewController: NSSplitViewController {
}
return .orderedAscending
}, context: nil)

self.splitView.setNeedsDisplay(self.splitView.bounds)
}

// MARK: - Toggle Sidebar
Expand All @@ -143,4 +145,43 @@ class SplitViewController: NSSplitViewController {
override func splitView(_ splitView: NSSplitView, canCollapseSubview subview: NSView) -> Bool {
return false
}

// Ugly fix to show the divider on macOS 11 and 12
override func splitView(_ splitView: NSSplitView, effectiveRect proposedEffectiveRect: NSRect,
forDrawnRect drawnRect: NSRect, ofDividerAt dividerIndex: Int) -> NSRect {

// Don't do anything for macOS versions lower than 11.0
guard #available(macOS 11.0, *) else { return drawnRect }
// Don't do anything for macOS versions greater than 13.0
guard #unavailable(macOS 13.0) else { return drawnRect }

// Get a reference to the content view
let mapViewController = self.detailViewController as? MapViewController
guard let mapView = mapViewController?.mapView else {
return drawnRect
}

// This assume the mapView has the same frame as the splitView
let rect = drawnRect
if rect.minX < kMinimumSidebarWidth {
mapView.layer?.mask = nil
} else {
let width = self.splitView.bounds.width
let leftSide = CGRect(x: 0, y: 0, width: rect.minX, height: rect.height)
let rightSide = CGRect(x: rect.minX+rect.width, y: 0, width: width - rect.minX, height: rect.height)

// Cut out a line from the mapView, where the border is
let path = CGMutablePath(rect: leftSide, transform: .none)
path.addPath(CGPath(rect: rightSide, transform: .none))

let maskLayer = CAShapeLayer()
maskLayer.path = path
maskLayer.backgroundColor = .black
maskLayer.fillRule = .evenOdd

mapView.layer?.mask = maskLayer
}

return drawnRect
}
}

0 comments on commit c26c246

Please sign in to comment.