mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-29 02:39:13 +00:00
fix(menubar): round Capacity Dock metrics to whole points to stop perpetual relayout
At any scale except 100% the dock's dimensions were fractional (85% of 88 is 74.8), so SwiftUI's fitted content never agreed with the pixel-aligned panel frame and the hosting view re-laid itself out at display cadence forever: 5 to 7 percent idle CPU and hundreds of wakeups a second once quota data existed, on every release since the dock shipped. Measured on the same machine: 60% and 85% scale held 5 to 6 percent for an hour; 100% scale idled at 0.1 to 0.2 percent. Rounding every scaled metric to a whole point makes all scales behave like 100%.
This commit is contained in:
parent
f4e9ece5bc
commit
1a74f0d3ac
1 changed files with 23 additions and 14 deletions
|
|
@ -27,20 +27,29 @@ enum CapacityDockMetrics {
|
|||
private static let basePercentageTextSize: CGFloat = 17
|
||||
private static let baseDetailWidth: CGFloat = 350
|
||||
|
||||
static func railWidth(scale: CGFloat) -> CGFloat { baseRailWidth * scale }
|
||||
static func horizontalRailWidth(scale: CGFloat) -> CGFloat { baseHorizontalRailWidth * scale }
|
||||
static func edgeFlareWidth(scale: CGFloat) -> CGFloat { baseEdgeFlareWidth * scale }
|
||||
static func edgeShoulderDepth(scale: CGFloat) -> CGFloat { baseEdgeShoulderDepth * scale }
|
||||
static func rowHeight(scale: CGFloat) -> CGFloat { baseRowHeight * scale }
|
||||
static func rowSpacing(scale: CGFloat) -> CGFloat { baseRowSpacing * scale }
|
||||
static func railAlongPad(scale: CGFloat) -> CGFloat { baseRailAlongPad * scale }
|
||||
static func railCrossPad(scale: CGFloat) -> CGFloat { baseRailCrossPad * scale }
|
||||
static func ringSize(scale: CGFloat) -> CGFloat { baseRingSize * scale }
|
||||
static func ringStrokeWidth(scale: CGFloat) -> CGFloat { baseRingStrokeWidth * scale }
|
||||
static func ringLabelSpacing(scale: CGFloat) -> CGFloat { baseRingLabelSpacing * scale }
|
||||
static func providerIconSize(scale: CGFloat) -> CGFloat { baseProviderIconSize * scale }
|
||||
static func percentageTextSize(scale: CGFloat) -> CGFloat { basePercentageTextSize * scale }
|
||||
static func detailWidth(scale: CGFloat) -> CGFloat { baseDetailWidth * scale }
|
||||
/// Every dock dimension lands on a whole point. Fractional sizes (85%
|
||||
/// of 88 is 74.8) made SwiftUI's fitted content disagree with the
|
||||
/// pixel-aligned panel frame on every layout pass, so the hosting view
|
||||
/// re-laid itself out at display cadence forever: 5 to 7 percent idle CPU
|
||||
/// at any scale except 100%.
|
||||
private static func points(_ base: CGFloat, _ scale: CGFloat) -> CGFloat {
|
||||
max(1, (base * scale).rounded())
|
||||
}
|
||||
|
||||
static func railWidth(scale: CGFloat) -> CGFloat { points(baseRailWidth, scale) }
|
||||
static func horizontalRailWidth(scale: CGFloat) -> CGFloat { points(baseHorizontalRailWidth, scale) }
|
||||
static func edgeFlareWidth(scale: CGFloat) -> CGFloat { points(baseEdgeFlareWidth, scale) }
|
||||
static func edgeShoulderDepth(scale: CGFloat) -> CGFloat { points(baseEdgeShoulderDepth, scale) }
|
||||
static func rowHeight(scale: CGFloat) -> CGFloat { points(baseRowHeight, scale) }
|
||||
static func rowSpacing(scale: CGFloat) -> CGFloat { points(baseRowSpacing, scale) }
|
||||
static func railAlongPad(scale: CGFloat) -> CGFloat { points(baseRailAlongPad, scale) }
|
||||
static func railCrossPad(scale: CGFloat) -> CGFloat { points(baseRailCrossPad, scale) }
|
||||
static func ringSize(scale: CGFloat) -> CGFloat { points(baseRingSize, scale) }
|
||||
static func ringStrokeWidth(scale: CGFloat) -> CGFloat { points(baseRingStrokeWidth, scale) }
|
||||
static func ringLabelSpacing(scale: CGFloat) -> CGFloat { points(baseRingLabelSpacing, scale) }
|
||||
static func providerIconSize(scale: CGFloat) -> CGFloat { points(baseProviderIconSize, scale) }
|
||||
static func percentageTextSize(scale: CGFloat) -> CGFloat { points(basePercentageTextSize, scale) }
|
||||
static func detailWidth(scale: CGFloat) -> CGFloat { points(baseDetailWidth, scale) }
|
||||
|
||||
static func railHeight(providerCount: Int, alongPad: CGFloat, scale: CGFloat) -> CGFloat {
|
||||
let count = max(providerCount, 1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue