1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-01 10:02:36 +03:00
vimr/VimR/ImageAndTextTableCell.swift

79 lines
1.9 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
2016-09-27 19:02:05 +03:00
var attributedText: NSAttributedString {
2016-09-06 00:29:32 +03:00
get {
return self.textField.attributedStringValue
}
2016-09-27 19:02:05 +03:00
2016-09-06 00:29:32 +03:00
set {
self.textField.attributedStringValue = newValue
}
}
2016-09-27 19:02:05 +03:00
var text: String {
get {
return self.textField.stringValue
}
set {
self.textField.stringValue = newValue
}
}
2016-09-06 00:29:32 +03:00
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
2016-09-27 19:02:05 +03:00
textField.isBezeled = false
textField.allowsDefaultTighteningForTruncation = true
textField.allowsEditingTextAttributes = false
2016-09-25 18:50:33 +03:00
textField.isEditable = false
2016-09-27 19:02:05 +03:00
textField.usesSingleLineMode = true
2016-09-25 18:50:33 +03:00
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
}