mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-11 17:38:38 +00:00
* font baseline like in original touchbar, styled battery widget (time showing as superscript)
This commit is contained in:
parent
d1a577868b
commit
8031108fc9
@ -110,7 +110,7 @@ extension NSButton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set (newTitle) {
|
set (newTitle) {
|
||||||
let attrTitle = NSMutableAttributedString(string: newTitle as String, attributes: [NSAttributedStringKey.foregroundColor: NSColor.white, NSAttributedStringKey.font: NSFont.systemFont(ofSize: 15, weight: .regular)])
|
let attrTitle = NSMutableAttributedString(string: newTitle as String, attributes: [NSAttributedStringKey.foregroundColor: NSColor.white, NSAttributedStringKey.font: NSFont.systemFont(ofSize: 15, weight: .regular), NSAttributedStringKey.baselineOffset: 1])
|
||||||
attrTitle.setAlignment(.center, range: NSRange(location: 0, length: newTitle.count))
|
attrTitle.setAlignment(.center, range: NSRange(location: 0, length: newTitle.count))
|
||||||
|
|
||||||
self.attributedTitle = attrTitle
|
self.attributedTitle = attrTitle
|
||||||
|
|||||||
@ -108,13 +108,11 @@ class BatteryInfo: NSObject {
|
|||||||
|
|
||||||
func getFormattedTime(time: Int) -> String {
|
func getFormattedTime(time: Int) -> String {
|
||||||
if (time > 0) {
|
if (time > 0) {
|
||||||
let timeFormatted = NSString(format: " (%d:%02d)", time / 60, time % 60) as String
|
let timeFormatted = NSString(format: " %d:%02d", time / 60, time % 60) as String
|
||||||
return timeFormatted
|
return timeFormatted
|
||||||
} else if (time == 0) {
|
|
||||||
return ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return " (?)"
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
public func updateInfo() {
|
public func updateInfo() {
|
||||||
@ -122,27 +120,26 @@ class BatteryInfo: NSObject {
|
|||||||
self.getPSInfo()
|
self.getPSInfo()
|
||||||
|
|
||||||
if ACPower == "AC Power" {
|
if ACPower == "AC Power" {
|
||||||
title += "⚡️"
|
if current < 100 {
|
||||||
|
title += "⚡️"
|
||||||
|
}
|
||||||
timeRemaining = getFormattedTime(time: timeToFull)
|
timeRemaining = getFormattedTime(time: timeToFull)
|
||||||
} else {
|
} else {
|
||||||
timeRemaining = getFormattedTime(time: timeToEmpty)
|
timeRemaining = getFormattedTime(time: timeToEmpty)
|
||||||
}
|
}
|
||||||
|
|
||||||
title += String(current) + "%" + timeRemaining
|
title += String(current) + "%"
|
||||||
button?.title = title
|
|
||||||
|
|
||||||
if current < 10 && ACPower != "AC Power" {
|
var color = NSColor.white
|
||||||
let pstyle = NSMutableParagraphStyle()
|
if current <= 10 && ACPower != "AC Power" {
|
||||||
pstyle.alignment = .center
|
color = NSColor.red
|
||||||
|
|
||||||
button?.attributedTitle = NSMutableAttributedString(
|
|
||||||
string: title,
|
|
||||||
attributes: [
|
|
||||||
NSAttributedStringKey.foregroundColor: NSColor.red,
|
|
||||||
NSAttributedStringKey.paragraphStyle: pstyle,
|
|
||||||
NSAttributedStringKey.font: NSFont.systemFont(ofSize: 16)
|
|
||||||
])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let newTitle = NSMutableAttributedString(string: title as String, attributes: [NSAttributedStringKey.foregroundColor: color, NSAttributedStringKey.font: button?.attributedTitle.attribute(NSAttributedStringKey.font, at: 0, effectiveRange: nil), NSAttributedStringKey.baselineOffset: 1])
|
||||||
|
let newTitleSecond = NSMutableAttributedString(string: timeRemaining as String, attributes: [NSAttributedStringKey.foregroundColor: color, NSAttributedStringKey.font: NSFont.systemFont(ofSize: 8, weight: .regular), NSAttributedStringKey.baselineOffset: 7])
|
||||||
|
newTitle.append(newTitleSecond)
|
||||||
|
newTitle.setAlignment(.center, range: NSRange(location: 0, length: title.count))
|
||||||
|
button?.attributedTitle = newTitle
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user