110 lines
3.8 KiB
Swift
110 lines
3.8 KiB
Swift
//
|
|
// KillSwitchHelpViewController.swift
|
|
// PrivadoVPN
|
|
//
|
|
// Created by Juraldinio on 3/10/21.
|
|
// Copyright © 2021 Privado LLC. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import AppKit
|
|
|
|
final class KillSwitchHelpViewController: NSViewController {
|
|
|
|
private enum Constants {
|
|
static let width: CGFloat = 300.0
|
|
static let height: CGFloat = 100.0
|
|
static let leading: CGFloat = 5.0
|
|
static let top: CGFloat = 10.0
|
|
|
|
static let between: CGFloat = 4.0
|
|
static let bottom: CGFloat = 6.0
|
|
|
|
static let textColor = NSColor(calibratedRed: 0.4721604586, green: 0.5212603211, blue: 0.7244773507, alpha: 1)
|
|
static let backgroundColor = NSColor(red: 21, green: 25, blue: 53)
|
|
}
|
|
|
|
private let helpTitle: String
|
|
private let helpDescription: String
|
|
|
|
// MARK: - Init
|
|
|
|
init(title: String, description: String) {
|
|
|
|
self.helpTitle = title
|
|
self.helpDescription = description
|
|
|
|
super.init(nibName: nil, bundle: nil)
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
// MARK: - LifeCycle
|
|
|
|
override func loadView() {
|
|
let view = NSView(frame: CGRect(x: 0, y: 0, width: Constants.width, height: Constants.height))
|
|
view.autoresizesSubviews = true
|
|
view.translatesAutoresizingMaskIntoConstraints = false
|
|
view.wantsLayer = true
|
|
view.layer?.backgroundColor = Constants.backgroundColor.cgColor
|
|
self.view = view
|
|
}
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
self.setupView()
|
|
}
|
|
|
|
// MARK: - Private
|
|
|
|
private func setupView() {
|
|
|
|
NSLayoutConstraint.activate([
|
|
self.view.widthAnchor.constraint(equalToConstant: Constants.width),
|
|
self.view.heightAnchor.constraint(equalToConstant: Constants.height)
|
|
])
|
|
|
|
let titleField = NSTextField(frame: .zero)
|
|
titleField.translatesAutoresizingMaskIntoConstraints = false
|
|
titleField.isBezeled = false
|
|
titleField.isEditable = false
|
|
titleField.drawsBackground = false
|
|
titleField.textColor = .white
|
|
if let font = titleField.font {
|
|
titleField.font = NSFont(name: font.fontName, size: 14)
|
|
}
|
|
|
|
self.view.addSubview(titleField)
|
|
NSLayoutConstraint.activate([
|
|
titleField.topAnchor.constraint(equalTo: self.view.topAnchor, constant: Constants.top),
|
|
titleField.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: Constants.leading),
|
|
titleField.trailingAnchor.constraint(equalTo: self.view.trailingAnchor)
|
|
])
|
|
|
|
let descriptionField = NSTextField(frame: .zero)
|
|
descriptionField.translatesAutoresizingMaskIntoConstraints = false
|
|
descriptionField.isBezeled = false
|
|
descriptionField.isEditable = false
|
|
descriptionField.drawsBackground = false
|
|
descriptionField.textColor = Constants.textColor
|
|
if let font = descriptionField.font {
|
|
descriptionField.font = NSFont(name: font.fontName, size: 12)
|
|
}
|
|
|
|
self.view.addSubview(descriptionField)
|
|
NSLayoutConstraint.activate([
|
|
descriptionField.topAnchor.constraint(equalTo: titleField.bottomAnchor, constant: Constants.between),
|
|
descriptionField.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: Constants.leading),
|
|
descriptionField.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: Constants.leading),
|
|
descriptionField.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: -Constants.bottom)
|
|
])
|
|
|
|
titleField.stringValue = self.helpTitle
|
|
descriptionField.stringValue = self.helpDescription
|
|
}
|
|
|
|
}
|