aboutsummaryrefslogtreecommitdiffstats
path: root/Sources/WireGuardApp/UI/macOS/View/LogViewCell.swift
diff options
context:
space:
mode:
Diffstat (limited to 'Sources/WireGuardApp/UI/macOS/View/LogViewCell.swift')
-rw-r--r--Sources/WireGuardApp/UI/macOS/View/LogViewCell.swift66
1 files changed, 66 insertions, 0 deletions
diff --git a/Sources/WireGuardApp/UI/macOS/View/LogViewCell.swift b/Sources/WireGuardApp/UI/macOS/View/LogViewCell.swift
new file mode 100644
index 0000000..c1c6cc5
--- /dev/null
+++ b/Sources/WireGuardApp/UI/macOS/View/LogViewCell.swift
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: MIT
+// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
+
+import Cocoa
+
+class LogViewCell: NSTableCellView {
+ var text: String = "" {
+ didSet { textField?.stringValue = text }
+ }
+
+ init() {
+ super.init(frame: .zero)
+
+ let textField = NSTextField(wrappingLabelWithString: "")
+ addSubview(textField)
+ textField.translatesAutoresizingMaskIntoConstraints = false
+ NSLayoutConstraint.activate([
+ textField.leadingAnchor.constraint(equalTo: self.leadingAnchor),
+ textField.trailingAnchor.constraint(equalTo: self.trailingAnchor),
+ textField.topAnchor.constraint(equalTo: self.topAnchor),
+ textField.bottomAnchor.constraint(equalTo: self.bottomAnchor)
+ ])
+
+ self.textField = textField
+ }
+
+ required init?(coder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
+ }
+
+ override func prepareForReuse() {
+ textField?.stringValue = ""
+ }
+}
+
+class LogViewTimestampCell: LogViewCell {
+ override init() {
+ super.init()
+ if let textField = textField {
+ textField.maximumNumberOfLines = 1
+ textField.lineBreakMode = .byClipping
+ textField.setContentCompressionResistancePriority(.defaultHigh, for: .vertical)
+ textField.setContentHuggingPriority(.defaultLow, for: .vertical)
+ }
+ }
+
+ required init?(coder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
+ }
+}
+
+class LogViewMessageCell: LogViewCell {
+ override init() {
+ super.init()
+ if let textField = textField {
+ textField.maximumNumberOfLines = 0
+ textField.lineBreakMode = .byWordWrapping
+ textField.setContentCompressionResistancePriority(.required, for: .vertical)
+ textField.setContentHuggingPriority(.required, for: .vertical)
+ }
+ }
+
+ required init?(coder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
+ }
+}