aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-03-16 19:28:54 +0530
committerRoopesh Chander <roop@roopc.net>2019-03-17 02:27:46 +0530
commit3e05da4486d0dd7215d69ef32338d1bbb6f9f249 (patch)
tree34773038ee7cb30f029061a352a0167f8fc8e8b4
parentwireguard-go-bridge: update deps (diff)
downloadwireguard-apple-3e05da4486d0dd7215d69ef32338d1bbb6f9f249.tar.xz
wireguard-apple-3e05da4486d0dd7215d69ef32338d1bbb6f9f249.zip
macOS: KeyValueImageRow class
Signed-off-by: Roopesh Chander <roop@roopc.net>
-rw-r--r--WireGuard/WireGuard/UI/macOS/View/KeyValueRow.swift48
1 files changed, 44 insertions, 4 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/View/KeyValueRow.swift b/WireGuard/WireGuard/UI/macOS/View/KeyValueRow.swift
index 7c32d768..3d3f2577 100644
--- a/WireGuard/WireGuard/UI/macOS/View/KeyValueRow.swift
+++ b/WireGuard/WireGuard/UI/macOS/View/KeyValueRow.swift
@@ -24,6 +24,8 @@ class EditableKeyValueRow: NSView {
return valueLabel
}()
+ let valueImageView: NSImageView?
+
var key: String {
get { return keyLabel.stringValue }
set(value) { keyLabel.stringValue = value }
@@ -42,13 +44,24 @@ class EditableKeyValueRow: NSView {
}
}
}
+ var valueImage: NSImage? {
+ get { return valueImageView?.image }
+ set(value) { valueImageView?.image = value }
+ }
+
+ var observationToken: AnyObject?
override var intrinsicContentSize: NSSize {
let height = max(keyLabel.intrinsicContentSize.height, valueLabel.intrinsicContentSize.height)
return NSSize(width: NSView.noIntrinsicMetric, height: height)
}
- init() {
+ convenience init() {
+ self.init(hasValueImage: false)
+ }
+
+ fileprivate init(hasValueImage: Bool) {
+ valueImageView = hasValueImage ? NSImageView() : nil
super.init(frame: CGRect.zero)
addSubview(keyLabel)
@@ -60,10 +73,24 @@ class EditableKeyValueRow: NSView {
keyLabel.centerYAnchor.constraint(equalTo: self.centerYAnchor),
keyLabel.firstBaselineAnchor.constraint(equalTo: valueLabel.firstBaselineAnchor),
self.leadingAnchor.constraint(equalTo: keyLabel.leadingAnchor),
- keyLabel.trailingAnchor.constraint(equalTo: valueLabel.leadingAnchor, constant: -5),
valueLabel.trailingAnchor.constraint(equalTo: self.trailingAnchor)
])
+ let spacing: CGFloat = 5
+ if let valueImageView = valueImageView {
+ addSubview(valueImageView)
+ valueImageView.translatesAutoresizingMaskIntoConstraints = false
+ NSLayoutConstraint.activate([
+ valueImageView.centerYAnchor.constraint(equalTo: self.centerYAnchor),
+ valueImageView.leadingAnchor.constraint(equalTo: keyLabel.trailingAnchor, constant: spacing),
+ valueLabel.leadingAnchor.constraint(equalTo: valueImageView.trailingAnchor)
+ ])
+ } else {
+ NSLayoutConstraint.activate([
+ valueLabel.leadingAnchor.constraint(equalTo: keyLabel.trailingAnchor, constant: spacing)
+ ])
+ }
+
keyLabel.setContentCompressionResistancePriority(.defaultHigh + 2, for: .horizontal)
keyLabel.setContentHuggingPriority(.defaultHigh, for: .horizontal)
valueLabel.setContentHuggingPriority(.defaultLow, for: .horizontal)
@@ -85,8 +112,21 @@ class EditableKeyValueRow: NSView {
}
class KeyValueRow: EditableKeyValueRow {
- override init() {
- super.init()
+ init() {
+ super.init(hasValueImage: false)
+ valueLabel.isEditable = false
+ valueLabel.isBordered = false
+ valueLabel.backgroundColor = .clear
+ }
+
+ required init?(coder decoder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
+ }
+}
+
+class KeyValueImageRow: EditableKeyValueRow {
+ init() {
+ super.init(hasValueImage: true)
valueLabel.isEditable = false
valueLabel.isBordered = false
valueLabel.backgroundColor = .clear