From 870b5b30a65a4c6d95410ce8d22dee36fa0c1488 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Tue, 21 Jan 2020 22:27:21 +0100 Subject: [PATCH] Reformat --- VimR/VimR/ImageAndTextTableCell.swift | 56 +++++++++++---------------- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/VimR/VimR/ImageAndTextTableCell.swift b/VimR/VimR/ImageAndTextTableCell.swift index e3b3c000..b0dd164d 100644 --- a/VimR/VimR/ImageAndTextTableCell.swift +++ b/VimR/VimR/ImageAndTextTableCell.swift @@ -11,23 +11,26 @@ class ImageAndTextTableCell: NSTableCellView { private let _textField = NSTextField(forAutoLayout: ()) private let _imageView = NSImageView(forAutoLayout: ()) - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } + required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } // MARK: - API static let font = NSFont.systemFont(ofSize: 12) static let widthWithoutText = (2 + 16 + 4 + 2).cgf static func width(with text: String) -> CGFloat { - let attrStr = NSAttributedString(string: text, attributes: [NSAttributedString.Key.font: ImageAndTextTableCell.font]) + let attrStr = NSAttributedString( + string: text, + attributes: [NSAttributedString.Key.font: ImageAndTextTableCell.font] + ) return self.widthWithoutText + attrStr.size().width } override var intrinsicContentSize: CGSize { - return CGSize(width: ImageAndTextTableCell.widthWithoutText + self._textField.intrinsicContentSize.width, - height: max(self._textField.intrinsicContentSize.height, 16)) + return CGSize( + width: ImageAndTextTableCell.widthWithoutText + self._textField.intrinsicContentSize.width, + height: max(self._textField.intrinsicContentSize.height, 16) + ) } override var backgroundStyle: NSView.BackgroundStyle { @@ -38,17 +41,19 @@ class ImageAndTextTableCell: NSTableCellView { var nameRange = NSRange(location: 0, length: 0) let _ = attrStr.attributes(at: 0, longestEffectiveRange: &nameRange, in: wholeRange) - if nameRange.length == attrStr.length { - // If we only have one style, Cocoa automatically inverts the color of the text. - return - } + // If we only have one style, Cocoa automatically inverts the color of the text. + if nameRange.length == attrStr.length { return } switch self.backgroundStyle { case .light: - attrStr.addAttribute(NSAttributedString.Key.foregroundColor, value: NSColor.black, range: nameRange) + attrStr.addAttribute( + NSAttributedString.Key.foregroundColor, value: NSColor.black, range: nameRange + ) case .dark: - attrStr.addAttribute(NSAttributedString.Key.foregroundColor, value: NSColor.white, range: nameRange) + attrStr.addAttribute( + NSAttributedString.Key.foregroundColor, value: NSColor.white, range: nameRange + ) default: return @@ -59,33 +64,18 @@ class ImageAndTextTableCell: NSTableCellView { } var attributedText: NSAttributedString { - get { - return self.textField!.attributedStringValue - } - - set { - self.textField?.attributedStringValue = newValue - } + get { self.textField!.attributedStringValue } + set { self.textField?.attributedStringValue = newValue } } var text: String { - get { - return self.textField!.stringValue - } - - set { - self.textField?.stringValue = newValue - } + get { self.textField!.stringValue } + set { self.textField?.stringValue = newValue } } var image: NSImage? { - get { - return self.imageView?.image - } - - set { - self.imageView?.image = newValue - } + get { self.imageView?.image } + set { self.imageView?.image = newValue } } init(withIdentifier identifier: String) {