aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-06-01 20:05:31 +0530
committerRoopesh Chander <roop@roopc.net>2019-06-04 15:48:42 +0530
commit9daae286f477ac7f1acc158baab0aa2c05d7449d (patch)
treeb20c76ca9dde9d53ed216e0a57c5db3c161890fc
parentgo-bridge: bump version (diff)
downloadwireguard-apple-9daae286f477ac7f1acc158baab0aa2c05d7449d.tar.xz
wireguard-apple-9daae286f477ac7f1acc158baab0aa2c05d7449d.zip
macOS: Log view: Allow resizing horizontally
-rw-r--r--WireGuard/WireGuard/UI/macOS/View/LogViewCell.swift46
-rw-r--r--WireGuard/WireGuard/UI/macOS/ViewController/LogViewController.swift8
2 files changed, 34 insertions, 20 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/View/LogViewCell.swift b/WireGuard/WireGuard/UI/macOS/View/LogViewCell.swift
index 1e2312a1..c1c6cc54 100644
--- a/WireGuard/WireGuard/UI/macOS/View/LogViewCell.swift
+++ b/WireGuard/WireGuard/UI/macOS/View/LogViewCell.swift
@@ -3,13 +3,25 @@
import Cocoa
-class LogViewCell: NSTextField {
+class LogViewCell: NSTableCellView {
+ var text: String = "" {
+ didSet { textField?.stringValue = text }
+ }
+
init() {
super.init(frame: .zero)
- isSelectable = false
- isEditable = false
- isBordered = false
- backgroundColor = .clear
+
+ 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) {
@@ -17,19 +29,19 @@ class LogViewCell: NSTextField {
}
override func prepareForReuse() {
- stringValue = ""
- preferredMaxLayoutWidth = 0
+ textField?.stringValue = ""
}
}
class LogViewTimestampCell: LogViewCell {
override init() {
super.init()
- maximumNumberOfLines = 1
- lineBreakMode = .byClipping
- preferredMaxLayoutWidth = 0
- setContentCompressionResistancePriority(.defaultHigh, for: .vertical)
- setContentHuggingPriority(.defaultLow, for: .vertical)
+ if let textField = textField {
+ textField.maximumNumberOfLines = 1
+ textField.lineBreakMode = .byClipping
+ textField.setContentCompressionResistancePriority(.defaultHigh, for: .vertical)
+ textField.setContentHuggingPriority(.defaultLow, for: .vertical)
+ }
}
required init?(coder: NSCoder) {
@@ -40,10 +52,12 @@ class LogViewTimestampCell: LogViewCell {
class LogViewMessageCell: LogViewCell {
override init() {
super.init()
- maximumNumberOfLines = 0
- lineBreakMode = .byWordWrapping
- setContentCompressionResistancePriority(.required, for: .vertical)
- setContentHuggingPriority(.required, for: .vertical)
+ if let textField = textField {
+ textField.maximumNumberOfLines = 0
+ textField.lineBreakMode = .byWordWrapping
+ textField.setContentCompressionResistancePriority(.required, for: .vertical)
+ textField.setContentHuggingPriority(.required, for: .vertical)
+ }
}
required init?(coder: NSCoder) {
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/LogViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/LogViewController.swift
index 088d161d..6666c226 100644
--- a/WireGuard/WireGuard/UI/macOS/ViewController/LogViewController.swift
+++ b/WireGuard/WireGuard/UI/macOS/ViewController/LogViewController.swift
@@ -146,7 +146,8 @@ class LogViewController: NSViewController {
])
NSLayoutConstraint.activate([
- containerView.widthAnchor.constraint(equalToConstant: 640),
+ containerView.widthAnchor.constraint(greaterThanOrEqualToConstant: 640),
+ containerView.widthAnchor.constraint(lessThanOrEqualToConstant: 1200),
containerView.heightAnchor.constraint(greaterThanOrEqualToConstant: 240)
])
@@ -250,12 +251,11 @@ extension LogViewController: NSTableViewDelegate {
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
if LogColumn.time.isRepresenting(tableColumn: tableColumn) {
let cell: LogViewTimestampCell = tableView.dequeueReusableCell()
- cell.stringValue = logEntries[row].timestamp
+ cell.text = logEntries[row].timestamp
return cell
} else if LogColumn.logMessage.isRepresenting(tableColumn: tableColumn) {
let cell: LogViewMessageCell = tableView.dequeueReusableCell()
- cell.stringValue = logEntries[row].message
- cell.preferredMaxLayoutWidth = tableColumn?.width ?? 0
+ cell.text = logEntries[row].message
return cell
} else {
fatalError()