Skip to content

Commit

Permalink
Search table styling
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-venugopal committed May 25, 2024
1 parent 7597b05 commit 2614d1b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 63 deletions.
64 changes: 16 additions & 48 deletions macOS/Source/UI/Search/Search.xib
Original file line number Diff line number Diff line change
Expand Up @@ -241,47 +241,15 @@ Gw
<rect key="frame" x="1" y="1" width="458" height="377"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnReordering="NO" autosaveColumns="NO" rowHeight="24" rowSizeStyle="automatic" headerView="1Rx-VA-4ps" viewBased="YES" id="jrU-2c-JGF">
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnReordering="NO" multipleSelection="NO" emptySelection="NO" autosaveColumns="NO" typeSelect="NO" rowHeight="24" rowSizeStyle="automatic" headerView="1Rx-VA-4ps" viewBased="YES" id="jrU-2c-JGF">
<rect key="frame" x="0.0" y="0.0" width="458" height="349"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<size key="intercellSpacing" width="17" height="0.0"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
<tableColumns>
<tableColumn identifier="cid_searchResultTrack" width="200" minWidth="40" maxWidth="1000" id="YOq-Dd-FG8">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" title="Track">
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
</tableHeaderCell>
<textFieldCell key="dataCell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" title="Text Cell" id="afA-cE-wbZ">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView identifier="cid_searchResultTrack" id="3oJ-Ve-UAc">
<rect key="frame" x="8" y="0.0" width="198" height="24"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="10d-XA-Igb">
<rect key="frame" x="0.0" y="4" width="198" height="16"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="aL8-zz-7hx">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<connections>
<outlet property="textField" destination="10d-XA-Igb" id="DA1-vk-yA0"/>
</connections>
</tableCellView>
</prototypeCellViews>
</tableColumn>
<tableColumn identifier="cid_searchResultLocation" width="115" minWidth="40" maxWidth="1000" id="aYA-JS-tx4">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" title="Location">
<tableColumn identifier="cid_Index" width="45" minWidth="45" maxWidth="80" id="aYA-JS-tx4">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" title="Index">
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
</tableHeaderCell>
Expand All @@ -292,12 +260,12 @@ Gw
</textFieldCell>
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView identifier="cid_searchResultLocation" id="bMC-F6-CrY">
<rect key="frame" x="223" y="0.0" width="115" height="24"/>
<tableCellView id="bMC-F6-CrY" customClass="AuralTableCellView" customModule="Aural" customModuleProvider="target">
<rect key="frame" x="8" y="0.0" width="43" height="24"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Sla-Cx-CNi">
<rect key="frame" x="0.0" y="4" width="115" height="16"/>
<rect key="frame" x="0.0" y="4" width="43" height="16"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="bPw-iL-ZHs">
<font key="font" usesAppearanceFont="YES"/>
Expand All @@ -312,34 +280,34 @@ Gw
</tableCellView>
</prototypeCellViews>
</tableColumn>
<tableColumn identifier="cid_searchResultMatchedField" width="97" minWidth="10" maxWidth="3.4028234663852886e+38" id="t8t-1z-mFu">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Matched Field">
<tableColumn identifier="cid_Name" width="380" minWidth="40" maxWidth="1000" id="YOq-Dd-FG8">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" title="Track">
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
</tableHeaderCell>
<textFieldCell key="dataCell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" alignment="left" title="Text Cell" id="VLH-n3-zMS">
<textFieldCell key="dataCell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" title="Text Cell" id="afA-cE-wbZ">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView identifier="cid_searchResultMatchedField" id="jLX-UE-PK6">
<rect key="frame" x="355" y="0.0" width="94" height="17"/>
<tableCellView id="3oJ-Ve-UAc" customClass="AuralTableCellView" customModule="Aural" customModuleProvider="target">
<rect key="frame" x="68" y="0.0" width="377" height="24"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="iLB-Sm-cTr">
<rect key="frame" x="0.0" y="1" width="94" height="16"/>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="10d-XA-Igb">
<rect key="frame" x="0.0" y="4" width="377" height="16"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="dvb-aU-qbm">
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="aL8-zz-7hx">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<connections>
<outlet property="textField" destination="iLB-Sm-cTr" id="zRA-RZ-GNP"/>
<outlet property="textField" destination="10d-XA-Igb" id="DA1-vk-yA0"/>
</connections>
</tableCellView>
</prototypeCellViews>
Expand Down
58 changes: 43 additions & 15 deletions macOS/Source/UI/Search/SearchViewController+TableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,61 @@ extension SearchViewController: NSTableViewDataSource {

extension SearchViewController: NSTableViewDelegate {

// Adjust row height based on if the text wraps over to the next line
func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
30
}

func tableView(_ tableView: NSTableView, shouldSelectRow row: Int) -> Bool {
false
}

func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {

guard let columnId = tableColumn?.identifier,
let cell = tableView.makeView(withIdentifier: columnId, owner: nil) as? NSTableCellView,
guard let column = tableColumn?.identifier,
let result = searchResults?.results[row] else {return nil}

switch columnId {
let builder = TableCellBuilder()
let track = result.location.track

switch column {

case .cid_index:

case .cid_searchResultTrackColumn:
cell.text = result.location.track.displayName
// if track == playQueueDelegate.currentTrack {
// builder.withImage(image: .imgPlayFilled, inColor: systemColorScheme.activeControlColor)
//
// } else {

case .cid_searchResultLocationColumn:
cell.text = result.location.description
builder.withText(text: "\(row + 1)",
inFont: systemFontScheme.normalFont, andColor: systemColorScheme.tertiaryTextColor,
selectedTextColor: systemColorScheme.tertiarySelectedTextColor,
bottomYOffset: systemFontScheme.tableYOffset)
// }

case .cid_searchResultMatchedFieldColumn:
cell.text = result.match.fieldKey
case .cid_trackName:

let titleAndArtist = track.titleAndArtist

if let artist = titleAndArtist.artist {

builder.withAttributedText(strings: [(text: artist + " ", font: systemFontScheme.normalFont, color: systemColorScheme.secondaryTextColor),
(text: titleAndArtist.title, font: systemFontScheme.normalFont, color: systemColorScheme.primaryTextColor)],
selectedTextColors: [systemColorScheme.secondarySelectedTextColor, systemColorScheme.primarySelectedTextColor],
bottomYOffset: systemFontScheme.tableYOffset)

} else {

builder.withText(text: titleAndArtist.title, inFont: systemFontScheme.normalFont, andColor: systemColorScheme.primaryTextColor,
selectedTextColor: systemColorScheme.primarySelectedTextColor, bottomYOffset: systemFontScheme.tableYOffset)
}

default:

return nil
}

return cell
}

// Adjust row height based on if the text wraps over to the next line
func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
26
return builder.buildCell(forTableView: tableView, forColumnWithId: column, inRow: row)
}
}

Expand Down

0 comments on commit 2614d1b

Please sign in to comment.