mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-15 00:34:08 +09:00
clean mini widget
- make Colorize works in Mini (text) widget - now Colorize properly works (line chart/bar chart) - main color is system color accent - fix box visibility in dark mode - fix colors in chart
This commit is contained in:
@@ -135,7 +135,7 @@ public class BarChart: Widget {
|
||||
|
||||
let box = NSBezierPath(roundedRect: NSRect(x: x, y: 0, width: width - x - Constants.Widget.margin, height: self.frame.size.height), xRadius: 2, yRadius: 2)
|
||||
if self.boxState {
|
||||
NSColor.black.set()
|
||||
(isDarkMode ? NSColor.white : NSColor.black).set()
|
||||
box.stroke()
|
||||
box.fill()
|
||||
chartPadding = 1
|
||||
@@ -153,7 +153,11 @@ public class BarChart: Widget {
|
||||
let partitonHeight = maxPartitionHeight * CGFloat(partitionValue)
|
||||
let partition = NSBezierPath(rect: NSRect(x: x, y: chartPadding, width: partitionWidth, height: partitonHeight))
|
||||
|
||||
partitionValue.usageColor().setFill()
|
||||
if self.colorState {
|
||||
partitionValue.usageColor().setFill()
|
||||
} else {
|
||||
NSColor.controlAccentColor.set()
|
||||
}
|
||||
partition.fill()
|
||||
partition.close()
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ public class LineChart: Widget {
|
||||
|
||||
var color = isDarkMode ? NSColor.white : NSColor.black
|
||||
if self.colorState {
|
||||
color = self.value.textUsageColor(color: self.colorState)
|
||||
color = self.value.percentageColor(color: self.colorState)
|
||||
}
|
||||
|
||||
let stringAttributes = [
|
||||
@@ -132,7 +132,7 @@ public class LineChart: Widget {
|
||||
|
||||
let box = NSBezierPath(roundedRect: NSRect(x: x, y: 0, width: boxWidth, height: boxHeight), xRadius: boxRadius, yRadius: boxRadius)
|
||||
if self.boxState {
|
||||
NSColor.black.set()
|
||||
(isDarkMode ? NSColor.white : NSColor.black).set()
|
||||
box.stroke()
|
||||
box.fill()
|
||||
self.chart.transparent = false
|
||||
@@ -182,7 +182,7 @@ public class LineChart: Widget {
|
||||
|
||||
view.addSubview(ToggleTitleRow(
|
||||
frame: NSRect(x: 0, y: (rowHeight + Constants.Settings.margin) * 0, width: view.frame.width, height: rowHeight),
|
||||
title: "Colorize",
|
||||
title: "Colorize value",
|
||||
action: #selector(toggleColor),
|
||||
state: self.colorState
|
||||
))
|
||||
|
||||
@@ -13,9 +13,6 @@ import Cocoa
|
||||
import StatsKit
|
||||
|
||||
public class Mini: Widget {
|
||||
private var valueView: NSTextField = NSTextField()
|
||||
private var labelView: NSTextField = NSTextField()
|
||||
|
||||
public var colorState: Bool = false
|
||||
public var labelState: Bool = true
|
||||
|
||||
@@ -92,7 +89,7 @@ public class Mini: Widget {
|
||||
|
||||
let stringAttributes = [
|
||||
NSAttributedString.Key.font: NSFont.systemFont(ofSize: valueSize, weight: .regular),
|
||||
NSAttributedString.Key.foregroundColor: isDarkMode ? NSColor.white : NSColor.textColor,
|
||||
NSAttributedString.Key.foregroundColor: self.value.percentageColor(color: self.colorState),
|
||||
NSAttributedString.Key.paragraphStyle: style
|
||||
]
|
||||
let rect = CGRect(x: x, y: y, width: width - (Constants.Widget.margin*2), height: valueSize)
|
||||
@@ -138,7 +135,6 @@ public class Mini: Widget {
|
||||
state = sender is NSButton ? (sender as! NSButton).state: nil
|
||||
}
|
||||
self.colorState = state! == .on ? true : false
|
||||
self.valueView.textColor = value.textUsageColor(color: self.colorState)
|
||||
self.store?.pointee.set(key: "\(self.title)_\(self.type.rawValue)_color", value: self.colorState)
|
||||
self.display()
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
<dict>
|
||||
<key>Value</key>
|
||||
<string>0.36,0.28,0.32,0.26</string>
|
||||
<key>Color</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
|
||||
@@ -131,7 +131,7 @@ internal class DiskView: NSView {
|
||||
let width: CGFloat = (view.frame.width * percentage) / 1
|
||||
self.usedBarSpace = NSView(frame: NSRect(x: 0, y: 0, width: width, height: view.frame.height))
|
||||
self.usedBarSpace?.wantsLayer = true
|
||||
self.usedBarSpace?.layer?.backgroundColor = NSColor(red: (26/255.0), green: (126/255.0), blue: (252/255.0), alpha: 1).cgColor
|
||||
self.usedBarSpace?.layer?.backgroundColor = NSColor.controlAccentColor.cgColor
|
||||
|
||||
view.addSubview(self.usedBarSpace!)
|
||||
self.mainView.addSubview(view)
|
||||
|
||||
@@ -40,11 +40,10 @@ public class LineChartView: NSView {
|
||||
return
|
||||
}
|
||||
|
||||
var lineColor: NSColor = NSColor(red: (26/255.0), green: (126/255.0), blue: (252/255.0), alpha: 1.0)
|
||||
var gradientColor: NSColor = NSColor(red: (26/255.0), green: (126/255.0), blue: (252/255.0), alpha: 0.5)
|
||||
let lineColor: NSColor = NSColor.controlAccentColor
|
||||
var gradientColor: NSColor = NSColor.controlAccentColor.withAlphaComponent(0.5)
|
||||
if !self.transparent {
|
||||
lineColor = NSColor(hexString: "#5c91f4")
|
||||
gradientColor = NSColor(hexString: "#5c91f4")
|
||||
gradientColor = NSColor.controlAccentColor.withAlphaComponent(0.8)
|
||||
}
|
||||
|
||||
let context = NSGraphicsContext.current!.cgContext
|
||||
|
||||
@@ -167,14 +167,10 @@ public extension Double {
|
||||
return (self * divisor).rounded() / divisor
|
||||
}
|
||||
|
||||
func usageColor(reversed: Bool = false, color: NSColor = NSColor(hexString: "#5c91f4")) -> NSColor {
|
||||
var firstColor = color
|
||||
if UserDefaults.standard.object(forKey: "color") != nil {
|
||||
firstColor = NSColor(hexString: UserDefaults.standard.string(forKey: "color")!)
|
||||
}
|
||||
|
||||
let secondColor: NSColor = NSColor.systemOrange
|
||||
let thirdColor: NSColor = NSColor.systemRed
|
||||
func usageColor(reversed: Bool = false) -> NSColor {
|
||||
let firstColor = NSColor(hexString: "#5c91f4")
|
||||
let secondColor: NSColor = NSColor.orange
|
||||
let thirdColor: NSColor = NSColor.red
|
||||
|
||||
if reversed {
|
||||
switch self {
|
||||
@@ -197,11 +193,19 @@ public extension Double {
|
||||
}
|
||||
}
|
||||
|
||||
func textUsageColor(color: Bool) -> NSColor {
|
||||
func percentageColor(color: Bool) -> NSColor {
|
||||
if !color {
|
||||
return NSColor.textColor
|
||||
}
|
||||
return usageColor(color: NSColor.textColor)
|
||||
|
||||
switch self {
|
||||
case 0.6...0.8:
|
||||
return NSColor.systemOrange
|
||||
case 0.8...1:
|
||||
return NSColor.systemRed
|
||||
default:
|
||||
return NSColor.systemGreen
|
||||
}
|
||||
}
|
||||
|
||||
func batteryColor(color: Bool = false) -> NSColor {
|
||||
|
||||
Reference in New Issue
Block a user