Skip to content

Commit

Permalink
Compact lyrics (flexible row height)
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-venugopal committed Jan 5, 2025
1 parent 5a6ddfc commit 3cf71d9
Show file tree
Hide file tree
Showing 11 changed files with 315 additions and 46 deletions.
Binary file not shown.
7 changes: 7 additions & 0 deletions Source/Core/Utils/Extensions/StringExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,13 @@ extension NSMutableParagraphStyle {
return style
}()

static let byWordWrapping: NSMutableParagraphStyle = {

let style: NSMutableParagraphStyle = NSMutableParagraphStyle()
style.lineBreakMode = .byWordWrapping
return style
}()

convenience init(lineSpacing: CGFloat) {

self.init()
Expand Down
1 change: 1 addition & 0 deletions Source/UI/CompactPlayer/CompactPlayerUIState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ enum CompactPlayerDisplayedView {
case search
case effects
case trackInfo
case lyrics
}
11 changes: 11 additions & 0 deletions Source/UI/CompactPlayer/CompactPlayerWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class CompactPlayerWindowController: NSWindowController {
let searchViewController: CompactPlayQueueSearchViewController = .init()
let chaptersListViewController: CompactChaptersListViewController = .init()
let trackInfoViewController: CompactPlayerTrackInfoViewController = .init()
let lyricsViewController: CompactPlayerLyricsViewController = .init()

lazy var effectsViewLoader: LazyViewLoader<EffectsSheetViewController> = .init()
private var effectsSheetViewController: EffectsSheetViewController {effectsViewLoader.controller}
Expand All @@ -56,6 +57,7 @@ class CompactPlayerWindowController: NSWindowController {
tabView.tabViewItem(at: 2).view?.addSubview(searchViewController.view)
tabView.tabViewItem(at: 3).view?.addSubview(chaptersListViewController.view)
tabView.tabViewItem(at: 4).view?.addSubview(trackInfoViewController.view)
tabView.tabViewItem(at: 5).view?.addSubview(lyricsViewController.view)

playQueueViewController.view.anchorToSuperview()
searchViewController.view.anchorToSuperview()
Expand All @@ -81,6 +83,8 @@ class CompactPlayerWindowController: NSWindowController {
messenger.subscribe(to: .View.toggleTrackInfo, handler: showTrackInfo)
messenger.subscribe(to: .Player.trackInfo, handler: showTrackInfo)

messenger.subscribe(to: .View.toggleLyrics, handler: showLyrics)

// messenger.subscribe(to: .View.toggleVisualizer, handler: toggleVisualizer)
messenger.subscribe(to: .View.changeWindowCornerRadius, handler: changeWindowCornerRadius(to:))

Expand Down Expand Up @@ -200,6 +204,10 @@ class CompactPlayerWindowController: NSWindowController {
tabView.selectTabViewItem(at: 4)
}

private func showLyrics() {
tabView.selectTabViewItem(at: 5)
}

func showPlayingTrackInPlayQueue() {
showPlayQueue()
}
Expand Down Expand Up @@ -248,6 +256,9 @@ class CompactPlayerWindowController: NSWindowController {
case 4:
compactPlayerUIState.displayedView = .trackInfo

case 5:
compactPlayerUIState.displayedView = .lyrics

default:
return
}
Expand Down
261 changes: 235 additions & 26 deletions Source/UI/CompactPlayer/Lyrics/CompactPlayerLyrics.xib

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,25 @@ import AppKit

class CompactPlayerLyricsViewController: LyricsViewController {

@IBOutlet weak var prototypeTextField: NSTextField!

override var nibName: NSNib.Name? {"CompactPlayerLyrics"}

private static var columnBounds = NSMakeRect(.zero, .zero, 270, .greatestFiniteMagnitude)

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

guard let text = self.timedLyrics?.lines[row].content else {return 30}

// Set the key and value within the virtual text fields (which are not displayed)
prototypeTextField.font = systemFontScheme.lyricsHighlightFont
prototypeTextField.stringValue = text

// And then compute row height from their cell sizes
let rowHeight = prototypeTextField.cell!.cellSize(forBounds: Self.columnBounds).height

// The desired row height is the maximum of the two heights, plus some padding
return max(30, rowHeight + 5)
}
}
6 changes: 3 additions & 3 deletions Source/UI/FontSchemes/Domain/FontScheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class FontScheme: NSObject, UserManagedObject {
var prominentFont: NSFont {

didSet {
self.lyricsHighlightFont = NSFont(name: prominentFont.familyName!, size: prominentFont.pointSize * 1.2)!
self.lyricsHighlightFont = NSFont(name: prominentFont.familyName!, size: prominentFont.pointSize * 1.1)!
}
}

Expand All @@ -57,7 +57,7 @@ class FontScheme: NSObject, UserManagedObject {
self.captionFont = captionFont
self.normalFont = normalFont
self.prominentFont = prominentFont
self.lyricsHighlightFont = NSFont(name: prominentFont.familyName!, size: prominentFont.pointSize * 1.2)!
self.lyricsHighlightFont = NSFont(name: prominentFont.familyName!, size: prominentFont.pointSize * 1.1)!
self.smallFont = smallFont
self.extraSmallFont = extraSmallFont

Expand Down Expand Up @@ -93,7 +93,7 @@ class FontScheme: NSObject, UserManagedObject {

self.normalFont = normalFont
self.prominentFont = prominentFont
self.lyricsHighlightFont = NSFont(name: prominentFont.familyName!, size: prominentFont.pointSize * 1.2)!
self.lyricsHighlightFont = NSFont(name: prominentFont.familyName!, size: prominentFont.pointSize * 1.1)!
self.smallFont = smallFont
self.extraSmallFont = extraSmallFont

Expand Down
20 changes: 10 additions & 10 deletions Source/UI/Lyrics/Lyrics.xib
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<rect key="frame" x="0.0" y="0.0" width="513" height="356"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="aBL-Sc-nfX" userLabel="Caption Label" customClass="BottomTextLabel" customModule="Aural" customModuleProvider="target">
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="aBL-Sc-nfX" userLabel="Caption Label" customClass="BottomTextLabel" customModule="Aural" customModuleProvider="target">
<rect key="frame" x="28" y="327" width="214" height="25"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="125" id="CdN-m3-O6L"/>
Expand Down Expand Up @@ -57,7 +57,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="textColor" white="0.69835256609999996" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="backgroundColor" white="0.097370866210000004" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<size key="minSize" width="460" height="270"/>
<size key="minSize" width="445" height="270"/>
<size key="maxSize" width="525" height="10000000"/>
<color key="insertionPointColor" white="0.70124099039999999" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</textView>
Expand Down Expand Up @@ -97,16 +97,16 @@
<scrollView borderType="none" horizontalLineScroll="30" horizontalPageScroll="10" verticalLineScroll="30" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Qvy-aA-oGb">
<rect key="frame" x="0.0" y="0.0" width="483" height="288"/>
<clipView key="contentView" id="n2f-37-6gY">
<rect key="frame" x="0.0" y="0.0" width="468" height="288"/>
<rect key="frame" x="0.0" y="0.0" width="483" height="288"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="firstColumnOnly" columnReordering="NO" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" typeSelect="NO" rowHeight="30" viewBased="YES" id="VEn-Ks-t68">
<rect key="frame" x="0.0" y="0.0" width="468" height="288"/>
<rect key="frame" x="0.0" y="0.0" width="483" height="288"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
<tableColumns>
<tableColumn identifier="cid_LyricsLine" width="436" minWidth="40" maxWidth="1000" id="Fc9-X3-Irq" userLabel="Lyrics Line">
<tableColumn identifier="cid_LyricsLine" width="451" minWidth="40" maxWidth="1000" id="Fc9-X3-Irq" userLabel="Lyrics Line">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border">
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -119,11 +119,11 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView id="QDR-Zf-hdH" customClass="AuralTableCellView" customModule="Aural" customModuleProvider="target">
<rect key="frame" x="10" y="0.0" width="448" height="30"/>
<rect key="frame" x="10" y="0.0" width="463" height="30"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="tsF-it-ius" customClass="CenterTextLabel" customModule="Aural" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="448" height="30"/>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="tsF-it-ius" customClass="CenterTextLabel" customModule="Aural" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="463" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="amb-sU-blK"/>
</constraints>
Expand Down Expand Up @@ -163,7 +163,7 @@
</connections>
</scroller>
<scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="ilo-hb-1SA" customClass="PrettyVerticalScroller" customModule="Aural" customModuleProvider="target">
<rect key="frame" x="468" y="0.0" width="15" height="288"/>
<rect key="frame" x="467" y="0.0" width="16" height="288"/>
<autoresizingMask key="autoresizingMask"/>
<connections>
<outlet property="clipView" destination="n2f-37-6gY" id="mF6-9J-vFT"/>
Expand All @@ -186,7 +186,7 @@
<rect key="frame" x="0.0" y="0.0" width="483" height="288"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="gZB-93-eKR" userLabel="Drop a Lyrics file (.lrc / .lrcx)" customClass="CenterTextLabel" customModule="Aural" customModuleProvider="target">
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="gZB-93-eKR" userLabel="Drop a Lyrics file (.lrc / .lrcx)" customClass="CenterTextLabel" customModule="Aural" customModuleProvider="target">
<rect key="frame" x="100" y="175" width="284" height="25"/>
<constraints>
<constraint firstAttribute="width" constant="280" id="1N5-HP-HN6"/>
Expand Down
16 changes: 14 additions & 2 deletions Source/UI/Lyrics/LyricsViewController+Timed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ extension LyricsViewController: NSTableViewDelegate {
}

cell.textField?.show()
cell.textField?.lineBreakMode = .byTruncatingTail
// cell.textField?.lineBreakMode = .byWordWrapping

return cell
}
Expand All @@ -201,6 +201,7 @@ extension LyricsViewController: NSTableViewDelegate {
cell.text = line.content
cell.textFont = systemFontScheme.lyricsHighlightFont
cell.textColor = systemColorScheme.primarySelectedTextColor
cell.textField?.lineBreakMode = .byWordWrapping

return
}
Expand All @@ -216,11 +217,16 @@ extension LyricsViewController: NSTableViewDelegate {

let subString = line.content.substring(range: preSegmentRange.intRange)
let attrStr = subString.attributed(font: systemFontScheme.lyricsHighlightFont, color: systemColorScheme.primarySelectedTextColor)
// attrStr.addAttribute(.paragraphStyle, value: NSMutableParagraphStyle.byWordWrapping, range: NSMakeRange(0, attrStr.length))
mutStr = mutStr + attrStr
}

let subString = line.content.substring(range: segment.range.intRange)
mutStr = mutStr + subString.attributed(font: systemFontScheme.lyricsHighlightFont, color: systemColorScheme.activeControlColor)

let attrStr = subString.attributed(font: systemFontScheme.lyricsHighlightFont, color: systemColorScheme.activeControlColor)
// attrStr.addAttribute(.paragraphStyle, value: NSMutableParagraphStyle.byWordWrapping, range: NSMakeRange(0, attrStr.length))

mutStr = mutStr + attrStr

let segmentLen = segment.range.length
let segmentEnd = segmentLoc + segmentLen
Expand All @@ -232,9 +238,14 @@ extension LyricsViewController: NSTableViewDelegate {

let subString = line.content.substring(range: postSegmentRange.intRange)
let attrStr = subString.attributed(font: systemFontScheme.lyricsHighlightFont, color: systemColorScheme.primarySelectedTextColor)
// attrStr.addAttribute(.paragraphStyle, value: NSMutableParagraphStyle.byWordWrapping, range: NSMakeRange(0, attrStr.length))

mutStr = mutStr + attrStr
}

mutStr.addAttribute(.paragraphStyle, value: NSMutableParagraphStyle.byWordWrapping, range: NSMakeRange(0, mutStr.length))

// cell.textField?.lineBreakMode = .byWordWrapping
cell.attributedText = mutStr
}

Expand All @@ -243,5 +254,6 @@ extension LyricsViewController: NSTableViewDelegate {
cell.text = line.content
cell.textFont = isCurrentLine ? systemFontScheme.lyricsHighlightFont : systemFontScheme.prominentFont
cell.textColor = isCurrentLine ? systemColorScheme.activeControlColor : systemColorScheme.secondaryTextColor
cell.textField?.lineBreakMode = .byWordWrapping
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,15 @@ class WindowLayoutsManager: UserManagedObjects<WindowLayout>, Destroyable, Resto
return WindowLayoutsPersistentState(systemLayout: systemLayoutState, userLayouts: userLayoutsState)
}
}

extension NSRect: @retroactive Hashable {

public func hash(into hasher: inout Hasher) {

hasher.combine(minX)
hasher.combine(minY)

hasher.combine(width)
hasher.combine(height)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,9 @@ class TableCellBuilder {
selAttStr = selAttStr + strings[index].text.attributed(font: strings[index].font, color: selectedTextColors[index])
}
}

let style: NSMutableParagraphStyle = NSMutableParagraphStyle()
style.lineBreakMode = .byTruncatingTail

attStr.addAttribute(.paragraphStyle, value: style, range: NSMakeRange(0, attStr.length))
selAttStr.addAttribute(.paragraphStyle, value: style, range: NSMakeRange(0, selAttStr.length))
attStr.addAttribute(.paragraphStyle, value: NSMutableParagraphStyle.byTruncatingTail, range: NSMakeRange(0, attStr.length))
selAttStr.addAttribute(.paragraphStyle, value: NSMutableParagraphStyle.byTruncatingTail, range: NSMakeRange(0, selAttStr.length))

self.attributedText = attStr
self.selectedAttributedText = selAttStr
Expand Down

0 comments on commit 3cf71d9

Please sign in to comment.