1
0
mirror of https://github.com/Toxblh/MTMR.git synced 2026-01-11 09:28:38 +00:00

* font baseline like in original touchbar, styled battery widget (time showing as superscript)

This commit is contained in:
ad 2018-04-27 18:46:29 +03:00
parent d1a577868b
commit 8031108fc9
2 changed files with 16 additions and 19 deletions

View File

@ -110,7 +110,7 @@ extension NSButton {
}
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))
self.attributedTitle = attrTitle

View File

@ -108,13 +108,11 @@ class BatteryInfo: NSObject {
func getFormattedTime(time: Int) -> String {
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
} else if (time == 0) {
return ""
}
return " (?)"
return ""
}
public func updateInfo() {
@ -122,27 +120,26 @@ class BatteryInfo: NSObject {
self.getPSInfo()
if ACPower == "AC Power" {
title += "⚡️"
if current < 100 {
title += "⚡️"
}
timeRemaining = getFormattedTime(time: timeToFull)
} else {
timeRemaining = getFormattedTime(time: timeToEmpty)
}
title += String(current) + "%" + timeRemaining
button?.title = title
title += String(current) + "%"
if current < 10 && ACPower != "AC Power" {
let pstyle = NSMutableParagraphStyle()
pstyle.alignment = .center
button?.attributedTitle = NSMutableAttributedString(
string: title,
attributes: [
NSAttributedStringKey.foregroundColor: NSColor.red,
NSAttributedStringKey.paragraphStyle: pstyle,
NSAttributedStringKey.font: NSFont.systemFont(ofSize: 16)
])
var color = NSColor.white
if current <= 10 && ACPower != "AC Power" {
color = NSColor.red
}
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
}
}