Skip to content

Commit

Permalink
Compact lyrics done
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-venugopal committed Jan 6, 2025
1 parent 3cf71d9 commit 800bd60
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ class CompactPlayerLyricsViewController: LyricsViewController {

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

private static var columnBounds = NSMakeRect(.zero, .zero, 270, .greatestFiniteMagnitude)
override var lineBreakMode: NSLineBreakMode {.byWordWrapping}

// 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

let columnWidth = tableView.tableColumn(withIdentifier: .cid_lyricsLine)?.width ?? 270
let columnBounds = NSMakeRect(.zero, .zero, columnWidth, .greatestFiniteMagnitude)

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

// The desired row height is the maximum of the two heights, plus some padding
return max(30, rowHeight + 5)
Expand Down
24 changes: 6 additions & 18 deletions Source/UI/Lyrics/LyricsViewController+Timed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ extension LyricsViewController: NSTableViewDelegate {

private static let rowHeight: CGFloat = 30

@objc var lineBreakMode: NSLineBreakMode {.byTruncatingTail}

func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
Self.rowHeight
}
Expand Down Expand Up @@ -187,7 +189,7 @@ extension LyricsViewController: NSTableViewDelegate {
}

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

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

return
}
Expand All @@ -216,17 +217,11 @@ extension LyricsViewController: NSTableViewDelegate {
let preSegmentRange = NSMakeRange(0, segmentLoc)

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
mutStr = mutStr + subString.attributed(font: systemFontScheme.lyricsHighlightFont, color: systemColorScheme.primarySelectedTextColor)
}

let subString = line.content.substring(range: segment.range.intRange)

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

mutStr = mutStr + attrStr
mutStr = mutStr + subString.attributed(font: systemFontScheme.lyricsHighlightFont, color: systemColorScheme.activeControlColor)

let segmentLen = segment.range.length
let segmentEnd = segmentLoc + segmentLen
Expand All @@ -237,15 +232,9 @@ extension LyricsViewController: NSTableViewDelegate {
let postSegmentRange = NSMakeRange(segmentEnd, contentLength - segmentEnd)

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 = mutStr + subString.attributed(font: systemFontScheme.lyricsHighlightFont, color: systemColorScheme.primarySelectedTextColor)
}

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

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

Expand All @@ -254,6 +243,5 @@ 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
}
}

0 comments on commit 800bd60

Please sign in to comment.