aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/macOS/View/ControlRow.swift
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-03-06 15:30:42 +0530
committerJason A. Donenfeld <Jason@zx2c4.com>2019-03-18 06:46:55 +0100
commitfff75adfe1ada43a3b5ec9212f6220f192b25790 (patch)
treeee7ce9ca7073342a1364f3abf86f9dff264169f9 /WireGuard/WireGuard/UI/macOS/View/ControlRow.swift
parenton-demand: iOS: Tunnel detail: Show SSID info (diff)
downloadwireguard-apple-fff75adfe1ada43a3b5ec9212f6220f192b25790.tar.xz
wireguard-apple-fff75adfe1ada43a3b5ec9212f6220f192b25790.zip
on-demand: macOS: Support SSIDs in on demand activation
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/UI/macOS/View/ControlRow.swift')
-rw-r--r--WireGuard/WireGuard/UI/macOS/View/ControlRow.swift61
1 files changed, 61 insertions, 0 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/View/ControlRow.swift b/WireGuard/WireGuard/UI/macOS/View/ControlRow.swift
new file mode 100644
index 0000000..7759073
--- /dev/null
+++ b/WireGuard/WireGuard/UI/macOS/View/ControlRow.swift
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: MIT
+// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
+
+import Cocoa
+
+class ControlRow: 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
+ }()
+
+ var key: String {
+ get { return keyLabel.stringValue }
+ set(value) { keyLabel.stringValue = value }
+ }
+
+ override var intrinsicContentSize: NSSize {
+ let height = max(keyLabel.intrinsicContentSize.height, controlView.intrinsicContentSize.height)
+ return NSSize(width: NSView.noIntrinsicMetric, height: height)
+ }
+
+ let controlView: NSView
+
+ init(controlView: NSView) {
+ self.controlView = controlView
+ super.init(frame: CGRect.zero)
+
+ addSubview(keyLabel)
+ addSubview(controlView)
+ keyLabel.translatesAutoresizingMaskIntoConstraints = false
+ controlView.translatesAutoresizingMaskIntoConstraints = false
+
+ NSLayoutConstraint.activate([
+ keyLabel.centerYAnchor.constraint(equalTo: self.centerYAnchor),
+ self.leadingAnchor.constraint(equalTo: keyLabel.leadingAnchor),
+ keyLabel.trailingAnchor.constraint(equalTo: controlView.leadingAnchor, constant: -5)
+ ])
+
+ keyLabel.setContentCompressionResistancePriority(.defaultHigh + 2, for: .horizontal)
+ keyLabel.setContentHuggingPriority(.defaultHigh, for: .horizontal)
+
+ let widthConstraint = keyLabel.widthAnchor.constraint(equalToConstant: 150)
+ widthConstraint.priority = .defaultHigh + 1
+ widthConstraint.isActive = true
+ }
+
+ required init?(coder decoder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
+ }
+
+ override func prepareForReuse() {
+ key = ""
+ }
+}