2019-03-10 11:02:26 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-12-04 11:15:29 +00:00
|
|
|
// Copyright © 2018-2020 WireGuard LLC. All Rights Reserved.
|
2019-03-10 11:02:26 +00:00
|
|
|
|
|
|
|
import Cocoa
|
|
|
|
|
|
|
|
class ButtonedDetailViewController: NSViewController {
|
|
|
|
|
|
|
|
var onButtonClicked: (() -> Void)?
|
|
|
|
|
|
|
|
let button: NSButton = {
|
|
|
|
let button = NSButton()
|
|
|
|
button.title = ""
|
|
|
|
button.setButtonType(.momentaryPushIn)
|
|
|
|
button.bezelStyle = .rounded
|
|
|
|
return button
|
|
|
|
}()
|
|
|
|
|
|
|
|
init() {
|
|
|
|
super.init(nibName: nil, bundle: nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
override func loadView() {
|
|
|
|
let view = NSView()
|
|
|
|
|
|
|
|
button.target = self
|
|
|
|
button.action = #selector(buttonClicked)
|
|
|
|
|
|
|
|
view.addSubview(button)
|
|
|
|
button.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
|
|
|
|
button.centerYAnchor.constraint(equalTo: view.centerYAnchor)
|
|
|
|
])
|
2019-03-18 08:17:40 +00:00
|
|
|
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
view.widthAnchor.constraint(greaterThanOrEqualToConstant: 320),
|
|
|
|
view.heightAnchor.constraint(greaterThanOrEqualToConstant: 120)
|
|
|
|
])
|
|
|
|
|
2019-03-10 11:02:26 +00:00
|
|
|
self.view = view
|
|
|
|
}
|
|
|
|
|
|
|
|
func setButtonTitle(_ title: String) {
|
|
|
|
button.title = title
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc func buttonClicked() {
|
|
|
|
onButtonClicked?()
|
|
|
|
}
|
|
|
|
}
|