-
Notifications
You must be signed in to change notification settings - Fork 895
/
Copy pathAddContactTableItem.swift
105 lines (84 loc) · 3.02 KB
/
AddContactTableItem.swift
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//
// AddContactTableItem.swift
// Telegram
//
// Created by keepcoder on 10/04/2017.
// Copyright © 2017 Telegram. All rights reserved.
//
import Cocoa
import TGUIKit
class AddContactTableItem: TableRowItem {
private let _stableId:AnyHashable
fileprivate let text:TextViewLayout
override var stableId: AnyHashable {
return _stableId
}
fileprivate let addContact:()->Void
init(_ initialSize: NSSize, stableId: AnyHashable, addContact: @escaping()->Void) {
_stableId = stableId
self.text = TextViewLayout(.initialize(string: strings().contactsAddContact, color: theme.colors.accent, font: .normal(.title)), maximumNumberOfLines: 1)
self.addContact = addContact
super.init(initialSize)
}
override func makeSize(_ width: CGFloat, oldWidth: CGFloat) -> Bool {
let success = super.makeSize(width, oldWidth: oldWidth)
text.measure(width: width - 80)
return success
}
override func viewClass() -> AnyClass {
return AddContactTableRowView.self
}
override var height: CGFloat {
return 50
}
}
class AddContactTableRowView : TableRowView {
private let imageView = ImageView()
private let textView = TextView()
required init(frame frameRect: NSRect) {
super.init(frame: frameRect)
addSubview(imageView)
addSubview(textView)
textView.userInteractionEnabled = false
textView.isSelectable = false
}
override func mouseUp(with event: NSEvent) {
if mouseInside() {
if let item = item as? AddContactTableItem {
item.addContact()
}
}
}
override func updateColors() {
super.updateColors()
textView.backgroundColor = backdorColor
}
override func set(item: TableRowItem, animated: Bool) {
super.set(item: item, animated: animated)
if let item = item as? AddContactTableItem {
self.textView.update(item.text)
imageView.image = theme.icons.contactsNewContact
imageView.sizeToFit()
needsLayout = true
}
}
override var backdorColor: NSColor {
return theme.colors.background
}
override func draw(_ layer: CALayer, in ctx: CGContext) {
super.draw(layer, in: ctx)
ctx.setFillColor(theme.colors.border.cgColor)
ctx.fill(NSMakeRect(56, frame.height - .borderSize, frame.width - 56, .borderSize))
ctx.fill(NSMakeRect(frame.width - .borderSize, 0, .borderSize, frame.height))
}
override func layout() {
super.layout()
imageView.centerY(x: floorToScreenPixels(backingScaleFactor, (56 - imageView.frame.width)/2))
textView.textLayout?.measure(width: frame.width - 66)
textView.update(textView.textLayout)
textView.centerY(x: 56)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}