1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-22 05:01:50 +03:00
vimr/VimR/ImageAndTextTableCell.swift

84 lines
2.0 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
2016-10-03 16:03:18 +03:00
class ImageAndTextTableCell: NSTableCellView {
2016-10-05 22:09:14 +03:00
static let font = NSFont.systemFont(ofSize: 12)
static let widthWithoutText = CGFloat(2 + 16 + 4 + 2)
2016-10-03 16:03:18 +03:00
fileprivate let _textField = NSTextField(forAutoLayout: ())
fileprivate let _imageView = NSImageView(forAutoLayout: ())
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 {
2016-10-03 16:03:18 +03:00
return self.textField!.attributedStringValue
2016-09-06 00:29:32 +03:00
}
2016-09-27 19:02:05 +03:00
2016-09-06 00:29:32 +03:00
set {
2016-10-03 16:03:18 +03:00
self.textField?.attributedStringValue = newValue
2016-09-06 00:29:32 +03:00
}
}
2016-09-27 19:02:05 +03:00
var text: String {
get {
2016-10-03 16:03:18 +03:00
return self.textField!.stringValue
2016-09-27 19:02:05 +03:00
}
set {
2016-10-03 16:03:18 +03:00
self.textField?.stringValue = newValue
2016-09-27 19:02:05 +03:00
}
}
2016-09-06 00:29:32 +03:00
var image: NSImage? {
get {
2016-10-03 16:03:18 +03:00
return self.imageView?.image
2016-09-06 00:29:32 +03:00
}
set {
2016-10-03 16:03:18 +03:00
self.imageView?.image = newValue
2016-09-06 00:29:32 +03:00
}
}
2016-10-05 22:09:14 +03:00
2016-09-04 00:13:52 +03:00
init(withIdentifier identifier: String) {
super.init(frame: CGRect.zero)
self.identifier = identifier
2016-10-03 16:03:18 +03:00
self.textField = self._textField
self.imageView = self._imageView
let textField = self._textField
2016-10-05 22:09:14 +03:00
textField.font = ImageAndTextTableCell.font
2016-09-25 18:50:33 +03:00
textField.isBordered = false
2016-09-27 19:02:05 +03:00
textField.isBezeled = false
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-04 00:13:52 +03:00
textField.drawsBackground = false
2016-10-03 16:03:18 +03:00
let imageView = self._imageView
2016-09-04 00:13:52 +03:00
self.addSubview(textField)
self.addSubview(imageView)
2016-10-03 16:03:18 +03:00
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
}