mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: added details to the CPU portal view
This commit is contained in:
@@ -261,6 +261,7 @@ public class LabelField: NSTextField {
|
||||
self.alignment = .natural
|
||||
self.font = NSFont.systemFont(ofSize: 12, weight: .regular)
|
||||
|
||||
self.cell?.truncatesLastVisibleLine = true
|
||||
self.cell?.usesSingleLineMode = true
|
||||
}
|
||||
|
||||
@@ -374,6 +375,37 @@ public func popupWithColorRow(_ view: NSView, color: NSColor, n: CGFloat, title:
|
||||
return (colorView, labelView, valueView)
|
||||
}
|
||||
|
||||
public func portalWithColorRow(_ v: NSStackView, color: NSColor, title: String) -> (NSView, ValueField) {
|
||||
let view: NSStackView = NSStackView()
|
||||
view.orientation = .horizontal
|
||||
view.distribution = .fillProportionally
|
||||
view.spacing = 1
|
||||
|
||||
let colorView: NSView = NSView()
|
||||
colorView.widthAnchor.constraint(equalToConstant: 5).isActive = true
|
||||
colorView.wantsLayer = true
|
||||
colorView.layer?.backgroundColor = color.cgColor
|
||||
colorView.layer?.cornerRadius = 2
|
||||
|
||||
let labelView: LabelField = LabelField(title)
|
||||
labelView.font = NSFont.systemFont(ofSize: 11, weight: .regular)
|
||||
|
||||
let valueView: ValueField = ValueField()
|
||||
valueView.font = NSFont.systemFont(ofSize: 12, weight: .regular)
|
||||
valueView.widthAnchor.constraint(equalToConstant: 40).isActive = true
|
||||
|
||||
view.addArrangedSubview(colorView)
|
||||
view.addArrangedSubview(labelView)
|
||||
view.addArrangedSubview(NSView())
|
||||
view.addArrangedSubview(valueView)
|
||||
|
||||
v.addArrangedSubview(view)
|
||||
|
||||
view.widthAnchor.constraint(equalTo: v.widthAnchor).isActive = true
|
||||
|
||||
return (colorView, valueView)
|
||||
}
|
||||
|
||||
public extension Array where Element: Equatable {
|
||||
func allEqual() -> Bool {
|
||||
if let firstElem = first {
|
||||
|
||||
@@ -15,6 +15,50 @@ public protocol Portal_p: NSView {
|
||||
var name: String { get }
|
||||
}
|
||||
|
||||
open class PortalWrapper: NSStackView, Portal_p {
|
||||
public var name: String
|
||||
|
||||
private let header: PortalHeader
|
||||
|
||||
public init(_ type: ModuleType, height: CGFloat = Constants.Popup.portalHeight) {
|
||||
self.name = type.rawValue
|
||||
self.header = PortalHeader(type.rawValue)
|
||||
|
||||
super.init(frame: NSRect(x: 0, y: 0, width: Constants.Popup.width, height: height))
|
||||
|
||||
self.wantsLayer = true
|
||||
self.layer?.backgroundColor = NSColor.windowBackgroundColor.cgColor
|
||||
self.layer?.cornerRadius = 3
|
||||
|
||||
self.orientation = .vertical
|
||||
self.distribution = .fillEqually
|
||||
self.spacing = Constants.Popup.spacing*2
|
||||
self.edgeInsets = NSEdgeInsets(
|
||||
top: Constants.Popup.spacing*2,
|
||||
left: Constants.Popup.spacing*2,
|
||||
bottom: Constants.Popup.spacing*2,
|
||||
right: Constants.Popup.spacing*2
|
||||
)
|
||||
self.addArrangedSubview(self.header)
|
||||
|
||||
self.load()
|
||||
|
||||
self.heightAnchor.constraint(equalToConstant: Constants.Popup.portalHeight).isActive = true
|
||||
}
|
||||
|
||||
required public init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
public override func updateLayer() {
|
||||
self.layer?.backgroundColor = NSColor.windowBackgroundColor.cgColor
|
||||
}
|
||||
|
||||
open func load() {
|
||||
self.addArrangedSubview(NSView())
|
||||
}
|
||||
}
|
||||
|
||||
public class PortalHeader: NSStackView {
|
||||
private let name: String
|
||||
|
||||
|
||||
@@ -829,7 +829,7 @@ public class TachometerGraphView: NSView {
|
||||
public class BarChartView: NSView {
|
||||
private var values: [ColorValue] = []
|
||||
|
||||
public init(frame: NSRect, num: Int) {
|
||||
public init(frame: NSRect = NSRect.zero, num: Int) {
|
||||
super.init(frame: frame)
|
||||
self.values = Array(repeating: ColorValue(0, color: .controlAccentColor), count: num)
|
||||
}
|
||||
@@ -858,17 +858,28 @@ public class BarChartView: NSView {
|
||||
let value = self.values[i]
|
||||
let color = value.color ?? .controlAccentColor
|
||||
let activeBlockNum = Int(round(value.value*Double(blocks)))
|
||||
let h = value.value*partitionSize.height
|
||||
|
||||
var y: CGFloat = spacing
|
||||
for b in 0..<blocks {
|
||||
if dirtyRect.height < 30 && h != 0 {
|
||||
let block = NSBezierPath(
|
||||
roundedRect: NSRect(x: x+spacing, y: y, width: blockSize.width, height: blockSize.height),
|
||||
roundedRect: NSRect(x: x+spacing, y: 1, width: partitionSize.width-(spacing*2), height: value.value*partitionSize.height),
|
||||
xRadius: 1, yRadius: 1
|
||||
)
|
||||
(activeBlockNum <= b ? NSColor.controlBackgroundColor.withAlphaComponent(0.4) : color).setFill()
|
||||
color.setFill()
|
||||
block.fill()
|
||||
block.close()
|
||||
y += blockSize.height + 1
|
||||
} else {
|
||||
var y: CGFloat = spacing
|
||||
for b in 0..<blocks {
|
||||
let block = NSBezierPath(
|
||||
roundedRect: NSRect(x: x+spacing, y: y, width: blockSize.width, height: blockSize.height),
|
||||
xRadius: 1, yRadius: 1
|
||||
)
|
||||
(activeBlockNum <= b ? NSColor.controlBackgroundColor.withAlphaComponent(0.4) : color).setFill()
|
||||
block.fill()
|
||||
block.close()
|
||||
y += blockSize.height + 1
|
||||
}
|
||||
}
|
||||
|
||||
x += partitionSize.width + spacing
|
||||
|
||||
Reference in New Issue
Block a user