macOS: Log view: Allow resizing horizontally
Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
4cb783c447
commit
4cb775c72f
|
@ -3,13 +3,25 @@
|
||||||
|
|
||||||
import Cocoa
|
import Cocoa
|
||||||
|
|
||||||
class LogViewCell: NSTextField {
|
class LogViewCell: NSTableCellView {
|
||||||
|
var text: String = "" {
|
||||||
|
didSet { textField?.stringValue = text }
|
||||||
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
super.init(frame: .zero)
|
super.init(frame: .zero)
|
||||||
isSelectable = false
|
|
||||||
isEditable = false
|
let textField = NSTextField(wrappingLabelWithString: "")
|
||||||
isBordered = false
|
addSubview(textField)
|
||||||
backgroundColor = .clear
|
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) {
|
required init?(coder: NSCoder) {
|
||||||
|
@ -17,19 +29,19 @@ class LogViewCell: NSTextField {
|
||||||
}
|
}
|
||||||
|
|
||||||
override func prepareForReuse() {
|
override func prepareForReuse() {
|
||||||
stringValue = ""
|
textField?.stringValue = ""
|
||||||
preferredMaxLayoutWidth = 0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class LogViewTimestampCell: LogViewCell {
|
class LogViewTimestampCell: LogViewCell {
|
||||||
override init() {
|
override init() {
|
||||||
super.init()
|
super.init()
|
||||||
maximumNumberOfLines = 1
|
if let textField = textField {
|
||||||
lineBreakMode = .byClipping
|
textField.maximumNumberOfLines = 1
|
||||||
preferredMaxLayoutWidth = 0
|
textField.lineBreakMode = .byClipping
|
||||||
setContentCompressionResistancePriority(.defaultHigh, for: .vertical)
|
textField.setContentCompressionResistancePriority(.defaultHigh, for: .vertical)
|
||||||
setContentHuggingPriority(.defaultLow, for: .vertical)
|
textField.setContentHuggingPriority(.defaultLow, for: .vertical)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder: NSCoder) {
|
||||||
|
@ -40,10 +52,12 @@ class LogViewTimestampCell: LogViewCell {
|
||||||
class LogViewMessageCell: LogViewCell {
|
class LogViewMessageCell: LogViewCell {
|
||||||
override init() {
|
override init() {
|
||||||
super.init()
|
super.init()
|
||||||
maximumNumberOfLines = 0
|
if let textField = textField {
|
||||||
lineBreakMode = .byWordWrapping
|
textField.maximumNumberOfLines = 0
|
||||||
setContentCompressionResistancePriority(.required, for: .vertical)
|
textField.lineBreakMode = .byWordWrapping
|
||||||
setContentHuggingPriority(.required, for: .vertical)
|
textField.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
|
textField.setContentHuggingPriority(.required, for: .vertical)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder: NSCoder) {
|
||||||
|
|
|
@ -146,7 +146,8 @@ class LogViewController: NSViewController {
|
||||||
])
|
])
|
||||||
|
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
containerView.widthAnchor.constraint(equalToConstant: 640),
|
containerView.widthAnchor.constraint(greaterThanOrEqualToConstant: 640),
|
||||||
|
containerView.widthAnchor.constraint(lessThanOrEqualToConstant: 1200),
|
||||||
containerView.heightAnchor.constraint(greaterThanOrEqualToConstant: 240)
|
containerView.heightAnchor.constraint(greaterThanOrEqualToConstant: 240)
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@ -250,12 +251,11 @@ extension LogViewController: NSTableViewDelegate {
|
||||||
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
|
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
|
||||||
if LogColumn.time.isRepresenting(tableColumn: tableColumn) {
|
if LogColumn.time.isRepresenting(tableColumn: tableColumn) {
|
||||||
let cell: LogViewTimestampCell = tableView.dequeueReusableCell()
|
let cell: LogViewTimestampCell = tableView.dequeueReusableCell()
|
||||||
cell.stringValue = logEntries[row].timestamp
|
cell.text = logEntries[row].timestamp
|
||||||
return cell
|
return cell
|
||||||
} else if LogColumn.logMessage.isRepresenting(tableColumn: tableColumn) {
|
} else if LogColumn.logMessage.isRepresenting(tableColumn: tableColumn) {
|
||||||
let cell: LogViewMessageCell = tableView.dequeueReusableCell()
|
let cell: LogViewMessageCell = tableView.dequeueReusableCell()
|
||||||
cell.stringValue = logEntries[row].message
|
cell.text = logEntries[row].message
|
||||||
cell.preferredMaxLayoutWidth = tableColumn?.width ?? 0
|
|
||||||
return cell
|
return cell
|
||||||
} else {
|
} else {
|
||||||
fatalError()
|
fatalError()
|
||||||
|
|
Loading…
Reference in New Issue