You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.4 KiB
48 lines
1.4 KiB
6 years ago
|
// Copyright © 2015 Abhishek Banthia
|
||
|
|
||
|
extension NSTextField {
|
||
|
|
||
|
func applyDefaultStyle() {
|
||
|
backgroundColor = NSColor.clear
|
||
|
isEditable = false
|
||
|
isBordered = false
|
||
|
allowsDefaultTighteningForTruncation = true
|
||
|
|
||
|
if #available(OSX 10.12.2, *) {
|
||
|
isAutomaticTextCompletionEnabled = false
|
||
|
allowsCharacterPickerTouchBarItem = false
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func disableWrapping() {
|
||
|
usesSingleLineMode = false
|
||
|
cell?.wraps = false
|
||
|
cell?.isScrollable = true
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
extension NSFont {
|
||
|
|
||
|
func size(_ string: String, _ width: Double, attributes: [NSAttributedString.Key: AnyObject]) -> CGSize {
|
||
|
let size = CGSize(width: width,
|
||
|
height: Double.greatestFiniteMagnitude)
|
||
|
|
||
|
var otherAttributes: [NSAttributedString.Key: AnyObject] = [NSAttributedString.Key.font: self]
|
||
|
|
||
|
attributes.forEach { (arg) in let (key, value) = arg; otherAttributes[key] = value }
|
||
|
|
||
|
return NSString(string: string).boundingRect(with: size,
|
||
|
options: NSString.DrawingOptions.usesLineFragmentOrigin,
|
||
|
attributes: attributes).size
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
class ClockerSearchField: NSSearchField {
|
||
|
override func awakeFromNib() {
|
||
|
super.awakeFromNib()
|
||
|
bezelStyle = .roundedBezel
|
||
|
}
|
||
|
}
|