aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/macOS/View/KeyValueRow.swift
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-01-07 13:04:50 +0530
committerRoopesh Chander <roop@roopc.net>2019-01-14 14:52:33 +0530
commitf7b2f73015b51d939d38ed5284f40cd46c73237f (patch)
tree31f9f8cb939107aae21215dd6b7a572e447ef239 /WireGuard/WireGuard/UI/macOS/View/KeyValueRow.swift
parentmacOS: On adding the first tunnel, select it (diff)
downloadwireguard-apple-f7b2f73015b51d939d38ed5284f40cd46c73237f.tar.xz
wireguard-apple-f7b2f73015b51d939d38ed5284f40cd46c73237f.zip
macOS: Rename *Cell to *Row
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/UI/macOS/View/KeyValueRow.swift')
-rw-r--r--WireGuard/WireGuard/UI/macOS/View/KeyValueRow.swift76
1 files changed, 76 insertions, 0 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/View/KeyValueRow.swift b/WireGuard/WireGuard/UI/macOS/View/KeyValueRow.swift
new file mode 100644
index 00000000..4e9fa7d3
--- /dev/null
+++ b/WireGuard/WireGuard/UI/macOS/View/KeyValueRow.swift
@@ -0,0 +1,76 @@
+// SPDX-License-Identifier: MIT
+// Copyright © 2018 WireGuard LLC. All Rights Reserved.
+
+import Cocoa
+
+class KeyValueRow: NSView {
+ let keyLabel: NSTextField = {
+ let keyLabel = NSTextField()
+ keyLabel.isEditable = false
+ keyLabel.isSelectable = false
+ keyLabel.isBordered = false
+ keyLabel.alignment = .right
+ keyLabel.maximumNumberOfLines = 1
+ keyLabel.lineBreakMode = .byTruncatingTail
+ keyLabel.backgroundColor = .clear
+ return keyLabel
+ }()
+
+ let valueLabel: NSTextField = {
+ let valueLabel = NSTextField()
+ valueLabel.isEditable = false
+ valueLabel.isSelectable = true
+ valueLabel.isBordered = false
+ valueLabel.maximumNumberOfLines = 1
+ valueLabel.lineBreakMode = .byTruncatingTail
+ valueLabel.backgroundColor = .clear
+ return valueLabel
+ }()
+
+ var key: String {
+ get { return keyLabel.stringValue }
+ set(value) { keyLabel.stringValue = value }
+ }
+ var value: String {
+ get { return valueLabel.stringValue }
+ set(value) { valueLabel.stringValue = value }
+ }
+ var isKeyInBold: Bool {
+ get { return keyLabel.font == NSFont.boldSystemFont(ofSize: 0) }
+ set(value) {
+ if value {
+ keyLabel.font = NSFont.boldSystemFont(ofSize: 0)
+ } else {
+ keyLabel.font = NSFont.systemFont(ofSize: 0)
+ }
+ }
+ }
+
+ init() {
+ super.init(frame: CGRect.zero)
+
+ addSubview(keyLabel)
+ addSubview(valueLabel)
+ keyLabel.translatesAutoresizingMaskIntoConstraints = false
+ valueLabel.translatesAutoresizingMaskIntoConstraints = false
+
+ NSLayoutConstraint.activate([
+ 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),
+ keyLabel.widthAnchor.constraint(equalToConstant: 120)
+ ])
+ }
+
+ required init?(coder decoder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
+ }
+
+ override func prepareForReuse() {
+ key = ""
+ value = ""
+ isKeyInBold = false
+ }
+}