feat: added a header with title and settings button to the portals (#1467)

This commit is contained in:
Serhiy Mytrovtsiy
2023-05-19 18:13:06 +02:00
parent eb4f7b6784
commit 5a974e38cf
7 changed files with 77 additions and 20 deletions

View File

@@ -18,7 +18,7 @@ public struct Popup_c_s {
public let spacing: CGFloat = 2
public let headerHeight: CGFloat = 42
public let separatorHeight: CGFloat = 30
public let portalHeight: CGFloat = 100
public let portalHeight: CGFloat = 120
}
public struct Settings_c_s {

View File

@@ -14,3 +14,52 @@ import Cocoa
public protocol Portal_p: NSView {
var name: String { get }
}
public class PortalHeader: NSStackView {
private let name: String
public init(_ name: String) {
self.name = name
super.init(frame: NSRect.zero)
self.heightAnchor.constraint(equalToConstant: 20).isActive = true
let title = NSTextField()
title.isEditable = false
title.isSelectable = false
title.isBezeled = false
title.wantsLayer = true
title.textColor = .textColor
title.backgroundColor = .clear
title.canDrawSubviewsIntoLayer = true
title.alignment = .center
title.font = NSFont.systemFont(ofSize: 12, weight: .regular)
title.stringValue = name
let settings = NSButton()
settings.heightAnchor.constraint(equalToConstant: 18).isActive = true
settings.bezelStyle = .regularSquare
settings.translatesAutoresizingMaskIntoConstraints = false
settings.imageScaling = .scaleProportionallyDown
settings.image = Bundle(for: type(of: self)).image(forResource: "settings")!
settings.contentTintColor = .lightGray
settings.isBordered = false
settings.action = #selector(self.openSettings)
settings.target = self
settings.toolTip = localizedString("Open module settings")
settings.focusRingType = .none
self.addArrangedSubview(title)
self.addArrangedSubview(NSView())
self.addArrangedSubview(settings)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@objc private func openSettings(_ sender: Any) {
self.window?.setIsVisible(false)
NotificationCenter.default.post(name: .toggleSettings, object: nil, userInfo: ["module": self.name])
}
}

View File

@@ -36,13 +36,14 @@ internal class Portal: NSStackView, Portal_p {
self.orientation = .vertical
self.distribution = .fillEqually
self.spacing = Constants.Popup.spacing*2
self.edgeInsets = NSEdgeInsets(
top: Constants.Popup.margins,
left: Constants.Popup.margins,
bottom: Constants.Popup.margins,
right: Constants.Popup.margins
top: Constants.Popup.spacing*2,
left: Constants.Popup.spacing*2,
bottom: Constants.Popup.spacing*2,
right: Constants.Popup.spacing*2
)
self.spacing = 0
self.addArrangedSubview(PortalHeader(name))
let box: NSStackView = NSStackView()
box.heightAnchor.constraint(equalToConstant: 13).isActive = true

View File

@@ -63,6 +63,7 @@ public class Portal: NSStackView, Portal_p {
bottom: Constants.Popup.spacing*2,
right: Constants.Popup.spacing*2
)
self.addArrangedSubview(PortalHeader(name))
let circle = PieChartView(frame: NSRect.zero, segments: [], drawValue: true)
circle.toolTip = localizedString("CPU usage")

View File

@@ -26,14 +26,16 @@ internal class Portal: NSStackView, Portal_p {
self.layer?.backgroundColor = NSColor.windowBackgroundColor.cgColor
self.layer?.cornerRadius = 3
self.orientation = .horizontal
self.orientation = .vertical
self.distribution = .fillEqually
self.spacing = Constants.Popup.spacing*2
self.edgeInsets = NSEdgeInsets(
top: Constants.Popup.margins,
left: Constants.Popup.margins,
bottom: Constants.Popup.margins,
right: Constants.Popup.margins
top: Constants.Popup.spacing*2,
left: Constants.Popup.spacing*2,
bottom: Constants.Popup.spacing*2,
right: Constants.Popup.spacing*2
)
self.addArrangedSubview(PortalHeader(name))
self.circle = PieChartView(frame: NSRect.zero, segments: [], drawValue: true)
self.circle!.toolTip = localizedString("Disk usage")

View File

@@ -28,14 +28,16 @@ public class Portal: NSStackView, Portal_p {
self.layer?.backgroundColor = NSColor.windowBackgroundColor.cgColor
self.layer?.cornerRadius = 3
self.orientation = .horizontal
self.orientation = .vertical
self.distribution = .fillEqually
self.spacing = Constants.Popup.spacing*2
self.edgeInsets = NSEdgeInsets(
top: Constants.Popup.margins,
left: Constants.Popup.margins,
top: Constants.Popup.spacing*2,
left: Constants.Popup.spacing*2,
bottom: 0,
right: Constants.Popup.margins
right: Constants.Popup.spacing*2
)
self.addArrangedSubview(PortalHeader(name))
self.circle = HalfCircleGraphView()
self.circle!.toolTip = localizedString("GPU usage")

View File

@@ -62,14 +62,16 @@ public class Portal: NSStackView, Portal_p {
self.layer?.backgroundColor = NSColor.windowBackgroundColor.cgColor
self.layer?.cornerRadius = 3
self.orientation = .horizontal
self.orientation = .vertical
self.distribution = .fillEqually
self.spacing = Constants.Popup.spacing*2
self.edgeInsets = NSEdgeInsets(
top: Constants.Popup.margins,
left: Constants.Popup.margins,
bottom: Constants.Popup.margins,
right: Constants.Popup.margins
top: Constants.Popup.spacing*2,
left: Constants.Popup.spacing*2,
bottom: Constants.Popup.spacing*2,
right: Constants.Popup.spacing*2
)
self.addArrangedSubview(PortalHeader(name))
self.circle = PieChartView(frame: NSRect.zero, segments: [], drawValue: true)
self.circle!.toolTip = localizedString("Memory usage")