Skip to content

Commit 2ebd88a

Browse files
committed
Adapt to system sidebar size
As can be set in system settings. The default row height automatically adjusts, even for group rows, so the delegate method is unneeded. Tweak the constraints in the row view item to be less hardcoded as well.
1 parent 676a2b7 commit 2ebd88a

File tree

3 files changed

+8
-21
lines changed

3 files changed

+8
-21
lines changed

Submariner/Database.xib

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@
8181
<rect key="frame" x="0.0" y="0.0" width="218" height="600"/>
8282
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
8383
<subviews>
84-
<scrollView focusRingType="none" borderType="none" autohidesScrollers="YES" horizontalLineScroll="24" horizontalPageScroll="10" verticalLineScroll="24" verticalPageScroll="10" usesPredominantAxisScrolling="NO" id="11">
84+
<scrollView focusRingType="none" borderType="none" autohidesScrollers="YES" horizontalLineScroll="28" horizontalPageScroll="10" verticalLineScroll="28" verticalPageScroll="10" usesPredominantAxisScrolling="NO" id="11">
8585
<rect key="frame" x="0.0" y="0.0" width="218" height="600"/>
8686
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
8787
<clipView key="contentView" drawsBackground="NO" id="cdO-el-ZLY">
8888
<rect key="frame" x="0.0" y="0.0" width="218" height="600"/>
8989
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
9090
<subviews>
91-
<outlineView focusRingType="none" verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" tableStyle="sourceList" multipleSelection="NO" autosaveColumns="NO" autosaveName="SourceList" rowHeight="24" rowSizeStyle="automatic" viewBased="YES" floatsGroupRows="NO" indentationPerLevel="13" autosaveExpandedItems="YES" indentationMarkerFollowsCell="NO" outlineTableColumn="16" id="15">
91+
<outlineView focusRingType="none" verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" tableStyle="sourceList" multipleSelection="NO" autosaveColumns="NO" autosaveName="SourceList" rowHeight="28" rowSizeStyle="systemDefault" viewBased="YES" floatsGroupRows="NO" indentationPerLevel="13" autosaveExpandedItems="YES" indentationMarkerFollowsCell="NO" outlineTableColumn="16" id="15">
9292
<rect key="frame" x="0.0" y="0.0" width="218" height="600"/>
9393
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
9494
<size key="intercellSpacing" width="3" height="0.0"/>

Submariner/SBDatabaseController.m

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,14 +1660,6 @@ - (void)outlineViewSelectionDidChange:(NSNotification *)notification {
16601660
}
16611661
}
16621662

1663-
- (CGFloat)outlineView:(NSOutlineView *)outlineView heightOfRowByItem:(id)item {
1664-
if ([[item representedObject] isKindOfClass:[SBSection class]]) {
1665-
return 22.0f;
1666-
}
1667-
// Medium size sidebar; https://developer.apple.com/design/human-interface-guidelines/sidebars#macOS
1668-
return 28.0f;
1669-
}
1670-
16711663
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item {
16721664
if([[item representedObject] isKindOfClass:[SBSection class]])
16731665
return NO;

Submariner/SBSourceListViewItem.swift

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
import Cocoa
1212

1313
@objc(SBSourceListViewItem) class SBSourceListViewItem: NSTableCellView {
14-
// https://developer.apple.com/design/human-interface-guidelines/sidebars#macOS
15-
// Our row height comes from our hosting NSOutlineView's delegate
16-
// Small: 16px icons, subheading text; Medium: 20px icons, body text
17-
// XXX: Resize to match system sidebar size
18-
1914
var resource: SBResource! {
2015
objectValue as? SBResource
2116
}
@@ -96,11 +91,12 @@ import Cocoa
9691
imageView.image = self.icon
9792
self.imageView = imageView
9893
self.addSubview(imageView)
99-
// 28 high sidebar, 4 point to be centered
100-
imageView.topAnchor.constraint(equalTo: self.topAnchor, constant: 4.0).isActive = true
94+
// image always has a vertical inset of 4px (i.e. medium 28pt row height, 20pt image)
95+
// https://developer.apple.com/design/human-interface-guidelines/sidebars#macOS
96+
imageView.topAnchor.constraint(equalTo: self.topAnchor, constant: 10.0).isActive = true
97+
imageView.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: -4.0).isActive = true
98+
imageView.widthAnchor.constraint(equalTo: self.heightAnchor).isActive = true
10199
imageView.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true
102-
imageView.widthAnchor.constraint(equalToConstant: 20).isActive = true
103-
imageView.heightAnchor.constraint(equalToConstant: 20).isActive = true
104100

105101
let textField = NSTextField()
106102
textField.translatesAutoresizingMaskIntoConstraints = false
@@ -114,11 +110,10 @@ import Cocoa
114110
// XXX: Seet it here as bindings will set this
115111
textField.target = self
116112
textField.action = #selector(SBSourceListViewItem.renameItem(_:))
117-
textField.font = NSFont.preferredFont(forTextStyle: .body)
118113
self.textField = textField
119114
self.addSubview(textField)
120115
textField.centerYAnchor.constraint(equalTo: imageView.centerYAnchor).isActive = true
121-
textField.leadingAnchor.constraint(equalTo: imageView.trailingAnchor, constant: 4.0).isActive = true
116+
textField.leadingAnchor.constraint(equalTo: imageView.trailingAnchor).isActive = true
122117
// XXX: For some reason, this anchor breaks the editing mode for the text field
123118
//textField.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true
124119
}

0 commit comments

Comments
 (0)