1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-23 05:32:13 +03:00
vimr/VimR/ImageAndTextTableCell.swift

65 lines
1.6 KiB
Swift
Raw Normal View History

2016-09-04 00:13:52 +03:00
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import Cocoa
import PureLayout
class ImageAndTextTableCell: NSView {
2016-09-06 00:29:32 +03:00
var text: NSAttributedString {
get {
return self.textField.attributedStringValue
}
set {
self.textField.attributedStringValue = newValue
}
}
var image: NSImage? {
get {
return self.imageView.image
}
set {
self.imageView.image = newValue
}
}
2016-09-04 00:13:52 +03:00
2016-09-25 18:50:33 +03:00
fileprivate let textField: NSTextField = NSTextField(forAutoLayout: ())
fileprivate let imageView: NSImageView = NSImageView(forAutoLayout: ())
2016-09-04 00:13:52 +03:00
init(withIdentifier identifier: String) {
super.init(frame: CGRect.zero)
self.identifier = identifier
let textField = self.textField
2016-09-25 18:50:33 +03:00
textField.isBordered = false
textField.isEditable = false
textField.lineBreakMode = .byTruncatingTail
2016-09-04 00:13:52 +03:00
textField.drawsBackground = false
let imageView = self.imageView
self.addSubview(textField)
self.addSubview(imageView)
2016-09-25 18:50:33 +03:00
imageView.autoPinEdge(toSuperviewEdge: .top, withInset: 2)
imageView.autoPinEdge(toSuperviewEdge: .left, withInset: 2)
imageView.autoSetDimension(.width, toSize: 16)
imageView.autoSetDimension(.height, toSize: 16)
2016-09-04 00:13:52 +03:00
2016-09-25 18:50:33 +03:00
textField.autoPinEdge(toSuperviewEdge: .top, withInset: 2)
textField.autoPinEdge(toSuperviewEdge: .right, withInset: 2)
textField.autoPinEdge(toSuperviewEdge: .bottom, withInset: 2)
textField.autoPinEdge(.left, to: .right, of: imageView, withOffset: 4)
2016-09-04 00:13:52 +03:00
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
2016-09-25 18:50:33 +03:00
}