mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: added a header with title and settings button to the portals (#1467)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user