forked from insidegui/WWDC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTranscriptTableCellView.swift
More file actions
75 lines (56 loc) · 2.17 KB
/
TranscriptTableCellView.swift
File metadata and controls
75 lines (56 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// TranscriptTableCellView.swift
// WWDC
//
// Created by Guilherme Rambo on 29/05/17.
// Copyright © 2017 Guilherme Rambo. All rights reserved.
//
import Cocoa
import ConfCore
import PlayerUI
class TranscriptTableCellView: NSTableCellView {
var annotation: TranscriptAnnotation? {
didSet {
updateUI()
}
}
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
buildUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private lazy var titleLabel: NSTextField = {
let l = NSTextField(labelWithString: "")
l.translatesAutoresizingMaskIntoConstraints = false
l.font = NSFont.systemFont(ofSize: 14, weight: NSFontWeightMedium)
l.textColor = .primaryText
l.cell?.backgroundStyle = .dark
l.lineBreakMode = .byTruncatingTail
return l
}()
private lazy var subtitleLabel: NSTextField = {
let l = NSTextField(labelWithString: "")
l.translatesAutoresizingMaskIntoConstraints = false
l.font = NSFont.systemFont(ofSize: 12)
l.textColor = .secondaryText
l.cell?.backgroundStyle = .dark
l.lineBreakMode = .byTruncatingTail
return l
}()
private func buildUI() {
addSubview(titleLabel)
addSubview(subtitleLabel)
titleLabel.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
subtitleLabel.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
subtitleLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 12).isActive = true
titleLabel.leadingAnchor.constraint(equalTo: subtitleLabel.trailingAnchor, constant: 8).isActive = true
titleLabel.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -12).isActive = true
}
private func updateUI() {
guard let annotation = annotation else { return }
titleLabel.stringValue = annotation.body
subtitleLabel.stringValue = String(timestamp: annotation.timecode) ?? ""
}
}