From 0f98312d150bfcbcfd90267462fdaf88d8f82517 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Sun, 17 Mar 2019 16:38:07 +0530 Subject: macOS: Tunnel detail: Make the Activate button part of the list view Signed-off-by: Roopesh Chander --- WireGuard/WireGuard/UI/macOS/View/ButtonRow.swift | 67 +++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 WireGuard/WireGuard/UI/macOS/View/ButtonRow.swift (limited to 'WireGuard/WireGuard/UI/macOS/View/ButtonRow.swift') diff --git a/WireGuard/WireGuard/UI/macOS/View/ButtonRow.swift b/WireGuard/WireGuard/UI/macOS/View/ButtonRow.swift new file mode 100644 index 0000000..4d15f5e --- /dev/null +++ b/WireGuard/WireGuard/UI/macOS/View/ButtonRow.swift @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: MIT +// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved. + +import Cocoa + +class ButtonRow: NSView { + let button: NSButton = { + let button = NSButton() + button.title = "" + button.setButtonType(.momentaryPushIn) + button.bezelStyle = .rounded + return button + }() + + var buttonTitle: String { + get { return button.title } + set(value) { button.title = value } + } + + var isButtonEnabled: Bool { + get { return button.isEnabled } + set(value) { button.isEnabled = value } + } + + var buttonToolTip: String { + get { return button.toolTip ?? "" } + set(value) { button.toolTip = value } + } + + var onButtonClicked: (() -> Void)? + var observationToken: AnyObject? + + override var intrinsicContentSize: NSSize { + return NSSize(width: NSView.noIntrinsicMetric, height: button.intrinsicContentSize.height) + } + + init() { + super.init(frame: CGRect.zero) + + button.target = self + button.action = #selector(buttonClicked) + + addSubview(button) + button.translatesAutoresizingMaskIntoConstraints = false + + NSLayoutConstraint.activate([ + button.centerYAnchor.constraint(equalTo: self.centerYAnchor), + button.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 155), + button.widthAnchor.constraint(greaterThanOrEqualToConstant: 100) + ]) + } + + required init?(coder decoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + @objc func buttonClicked() { + onButtonClicked?() + } + + override func prepareForReuse() { + buttonTitle = "" + buttonToolTip = "" + onButtonClicked = nil + observationToken = nil + } +} -- cgit v1.2.3-59-g8ed1b