- adjust Mini widget sizes

This commit is contained in:
Serhiy Mytrovtsiy
2020-11-09 22:31:56 +01:00
parent 3ab1fb0156
commit 762afd1763
4 changed files with 22 additions and 17 deletions

View File

@@ -102,7 +102,7 @@ public class Mini: Widget, CALayerDelegate {
case .systemAccent: valueColor = NSColor.controlAccentColor
case .utilization: valueColor = self.value.usageColor()
case .pressure: valueColor = self.pressureLevel.pressureColor()
case .monochrome: valueColor = NSColor.labelColor
case .monochrome: valueColor = NSColor.textColor
default: valueColor = colorFromString("\(self.colorState.self)")
}
@@ -134,8 +134,8 @@ public class Mini: Widget, CALayerDelegate {
self.labelLayer?.isHidden = !self.labelState
if var frame = self.valueLayer?.frame {
frame.origin = CGPoint(x: origin.x, y: origin.y)
frame.size = CGSize(width: width - (Constants.Widget.margin*2), height: valueSize)
frame.origin = CGPoint(x: origin.x, y: origin.y-1)
frame.size = CGSize(width: width - (Constants.Widget.margin*2), height: valueSize+1)
self.valueLayer?.frame = frame
}
self.valueLayer?.fontSize = valueSize
@@ -160,13 +160,12 @@ public class Mini: Widget, CALayerDelegate {
label.frame = CGRect(x: origin.x, y: 11, width: self.width - (Constants.Widget.margin*2), height: 8)
label.string = self.title
label.alignmentMode = .left
label.isHidden = true
label.foregroundColor = NSColor.labelColor.cgColor
label.isHidden = !self.labelState
let value = CAText(fontSize: valueSize)
value.frame = CGRect(x: origin.x, y: origin.y, width: self.width - (Constants.Widget.margin*2), height: valueSize)
value.font = NSFont.systemFont(ofSize: valueSize, weight: .semibold)
value.frame = CGRect(x: origin.x, y: origin.y-1, width: self.width - (Constants.Widget.margin*2), height: valueSize+1)
value.font = NSFont.systemFont(ofSize: valueSize, weight: .medium)
value.string = "\(Int(self.value.rounded(toPlaces: 2) * 100))%"
value.fontSize = valueSize
value.alignmentMode = alignment
@@ -188,14 +187,9 @@ public class Mini: Widget, CALayerDelegate {
DispatchQueue.main.async(execute: {
self.value = value
CATransaction.begin()
CATransaction.setDisableActions(true)
CATransaction.setValue(kCFBooleanTrue, forKey: kCATransactionDisableActions)
CATransaction.setAnimationDuration(0)
self.valueLayer?.string = "\(Int(self.value.rounded(toPlaces: 2) * 100))%"
CATransaction.commit()
CATransaction.disableAnimations {
self.valueLayer?.string = "\(Int(self.value.rounded(toPlaces: 2) * 100))%"
}
self.needsDisplay = true
})
}

View File

@@ -15,7 +15,7 @@
<key>Preview</key>
<dict>
<key>Value</key>
<string>0.08</string>
<string>0.12</string>
</dict>
<key>Unsupported colors</key>
<array>

View File

@@ -490,3 +490,14 @@ public extension NSColor {
return String(format:"#%06x", rgb)
}
}
public extension CATransaction {
static func disableAnimations(_ closure: () -> Void) {
CATransaction.begin()
CATransaction.setDisableActions(true)
CATransaction.setValue(kCFBooleanTrue, forKey: kCATransactionDisableActions)
CATransaction.setAnimationDuration(0)
closure()
CATransaction.commit()
}
}

View File

@@ -159,7 +159,7 @@ public struct Units {
}
public class LabelField: NSTextField {
public init(frame: NSRect, _ label: String) {
public init(frame: NSRect, _ label: String = "") {
super.init(frame: frame)
self.isEditable = false
@@ -181,7 +181,7 @@ public class LabelField: NSTextField {
}
public class ValueField: NSTextField {
public init(frame: NSRect, _ value: String) {
public init(frame: NSRect, _ value: String = "") {
super.init(frame: frame)
self.isEditable = false