mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-15 00:34:08 +09:00
fix: fixed circles charts in the new version of Cocoa
This commit is contained in:
@@ -204,29 +204,30 @@ internal class Popup: PopupWrapper {
|
||||
private func initDashboard() -> NSView {
|
||||
let view: NSView = NSView(frame: NSRect(x: 0, y: 0, width: self.frame.width, height: self.dashboardHeight))
|
||||
|
||||
let container: NSView = NSView(frame: NSRect(x: 0, y: 10, width: view.frame.width, height: self.dashboardHeight-20))
|
||||
self.circle = PieChartView(frame: NSRect(
|
||||
x: (container.frame.width - container.frame.height)/2,
|
||||
y: 0,
|
||||
width: container.frame.height,
|
||||
height: container.frame.height
|
||||
), segments: [], drawValue: true)
|
||||
self.circle!.toolTip = localizedString("CPU usage")
|
||||
container.addSubview(self.circle!)
|
||||
let usageSize = self.dashboardHeight-20
|
||||
let usageX = (view.frame.width - usageSize)/2
|
||||
|
||||
let centralWidth: CGFloat = self.dashboardHeight-20
|
||||
let sideWidth: CGFloat = (view.frame.width - centralWidth - (Constants.Popup.margins*2))/2
|
||||
self.temperatureCircle = HalfCircleGraphView(frame: NSRect(x: (sideWidth - 60)/2, y: 10, width: 60, height: 50))
|
||||
let usage = NSView(frame: NSRect(x: usageX, y: (view.frame.height - usageSize)/2, width: usageSize, height: usageSize))
|
||||
let temperature = NSView(frame: NSRect(x: (usageX - 50)/2, y: (view.frame.height - 50)/2 - 3, width: 50, height: 50))
|
||||
let frequency = NSView(frame: NSRect(x: (usageX+usageSize) + (usageX - 50)/2, y: (view.frame.height - 50)/2 - 3, width: 50, height: 50))
|
||||
|
||||
self.circle = PieChartView(frame: NSRect(x: 0, y: 0, width: usage.frame.width, height: usage.frame.height), segments: [], drawValue: true)
|
||||
self.circle!.toolTip = localizedString("CPU usage")
|
||||
usage.addSubview(self.circle!)
|
||||
|
||||
self.temperatureCircle = HalfCircleGraphView(frame: NSRect(x: 0, y: 0, width: temperature.frame.width, height: temperature.frame.height))
|
||||
self.temperatureCircle!.toolTip = localizedString("CPU temperature")
|
||||
(self.temperatureCircle! as NSView).isHidden = true
|
||||
temperature.addSubview(self.temperatureCircle!)
|
||||
|
||||
self.frequencyCircle = HalfCircleGraphView(frame: NSRect(x: view.frame.width - 60 - Constants.Popup.margins*2, y: 10, width: 60, height: 50))
|
||||
self.frequencyCircle = HalfCircleGraphView(frame: NSRect(x: 0, y: 0, width: frequency.frame.width, height: frequency.frame.height))
|
||||
self.frequencyCircle!.toolTip = localizedString("CPU frequency")
|
||||
(self.frequencyCircle! as NSView).isHidden = true
|
||||
frequency.addSubview(self.frequencyCircle!)
|
||||
|
||||
view.addSubview(self.temperatureCircle!)
|
||||
view.addSubview(container)
|
||||
view.addSubview(self.frequencyCircle!)
|
||||
view.addSubview(temperature)
|
||||
view.addSubview(usage)
|
||||
view.addSubview(frequency)
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ internal class Popup: PopupWrapper {
|
||||
|
||||
private func recalculateHeight() {
|
||||
let h = self.arrangedSubviews.map({ $0.bounds.height + self.spacing }).reduce(0, +) - self.spacing
|
||||
if self.frame.size.height != h {
|
||||
if self.frame.size.height != h && h >= 0 {
|
||||
self.setFrameSize(NSSize(width: self.frame.width, height: h))
|
||||
self.sizeCallback?(self.frame.size)
|
||||
}
|
||||
@@ -181,9 +181,7 @@ private class GPUView: NSStackView {
|
||||
}
|
||||
|
||||
private func addStats(id: String, _ val: Double? = nil) {
|
||||
guard let value = val else {
|
||||
return
|
||||
}
|
||||
guard let value = val else { return }
|
||||
|
||||
var circle: HalfCircleGraphView
|
||||
var chart: LineChartView
|
||||
@@ -196,7 +194,7 @@ private class GPUView: NSStackView {
|
||||
circle.toolTip = localizedString("GPU \(id)")
|
||||
if let row = self.circleRow {
|
||||
row.setFrameSize(NSSize(width: row.frame.width, height: self.circleSize + 20))
|
||||
row.edgeInsets = NSEdgeInsets(top: 10, left: 0, bottom: 0, right: 0)
|
||||
row.edgeInsets = NSEdgeInsets(top: 10, left: 10, bottom: 0, right: 10)
|
||||
row.heightAnchor.constraint(equalToConstant: row.bounds.height).isActive = true
|
||||
row.addArrangedSubview(circle)
|
||||
}
|
||||
|
||||
@@ -419,8 +419,8 @@ public class PressureView: NSView {
|
||||
|
||||
public override func draw(_ rect: CGRect) {
|
||||
let arcWidth: CGFloat = 7.0
|
||||
let centerPoint = CGPoint(x: rect.midX, y: rect.midY)
|
||||
let radius = (min(rect.width, rect.height) - arcWidth) / 2
|
||||
let centerPoint = CGPoint(x: self.frame.width/2, y: self.frame.height/2)
|
||||
let radius = (min(self.frame.width, self.frame.height) - arcWidth) / 2
|
||||
|
||||
guard let context = NSGraphicsContext.current?.cgContext else { return }
|
||||
context.setShouldAntialias(true)
|
||||
@@ -433,7 +433,7 @@ public class PressureView: NSView {
|
||||
var previousAngle = startAngle
|
||||
|
||||
context.saveGState()
|
||||
context.translateBy(x: rect.width, y: 0)
|
||||
context.translateBy(x: self.frame.width, y: 0)
|
||||
context.scaleBy(x: -1, y: 1)
|
||||
|
||||
for segment in self.segments {
|
||||
|
||||
@@ -107,7 +107,7 @@ internal class Popup: PopupWrapper {
|
||||
if let fan = f as? Fan {
|
||||
let view = FanView(fan, width: self.frame.width) { [weak self] in
|
||||
let h = container.arrangedSubviews.map({ $0.bounds.height + container.spacing }).reduce(0, +) - container.spacing
|
||||
if container.frame.size.height != h {
|
||||
if container.frame.size.height != h && h >= 0 {
|
||||
container.setFrameSize(NSSize(width: container.frame.width, height: h))
|
||||
}
|
||||
self?.recalculateHeight()
|
||||
|
||||
Reference in New Issue
Block a user