fix: hardcode BadgeView font size (#5168)

This commit is contained in:
Cœur
2023-03-08 11:16:06 +08:00
committed by GitHub
parent 20071149c3
commit 60ef92ee99
2 changed files with 11 additions and 16 deletions

View File

@@ -42,27 +42,15 @@ typedef NS_ENUM(NSInteger, ArrowDirection) {
_fAttributes = [[NSMutableDictionary alloc] initWithCapacity:3];
_fAttributes[NSForegroundColorAttributeName] = NSColor.whiteColor;
_fAttributes[NSShadowAttributeName] = stringShadow;
_fAttributes[NSFontAttributeName] = [NSFont boldSystemFontOfSize:23.0];
// DownloadBadge and UploadBadge should have the same size
NSSize badgeSize = [NSImage imageNamed:@"DownloadBadge"].size;
// DownArrowTemplate and UpArrowTemplate should have the same size
CGFloat arrowWidthHeightRatio = kWhiteDownArrow.size.width / kWhiteDownArrow.size.height;
// Make sure text fits on the badge.
// In macOS Ventura, this will end up calculating a boldSystemFontOfSize of 21.
NSString* maxString = [NSString stringForSpeedAbbrev:888.8]; // "888.8 K" localized
CGFloat fontSize = 26.0;
NSSize stringSize;
CGFloat arrowHeight;
do
{
fontSize -= 1.0;
_fAttributes[NSFontAttributeName] = [NSFont boldSystemFontOfSize:fontSize];
stringSize = [maxString sizeWithAttributes:_fAttributes];
// arrow height equal to font capital letter height + shadow
arrowHeight = [_fAttributes[NSFontAttributeName] capHeight] + 4;
} while (badgeSize.width < stringSize.width + 2 * arrowHeight * arrowWidthHeightRatio +
arrowHeight); // text is centered + surrounded by the size of two arrows + arrow spacing (" ▼ 888.8 K ▽ ")
// arrow height equal to font capital letter height + shadow
CGFloat arrowHeight = [_fAttributes[NSFontAttributeName] capHeight] + 4;
kArrowInset = { badgeSize.height * 0.2, badgeSize.height * 0.1 };
kArrowSize = { arrowHeight * arrowWidthHeightRatio, arrowHeight };

View File

@@ -175,9 +175,16 @@
{
return [NSString localizedStringWithFormat:@"%.1f %@", speed, mb];
}
speed /= 1000.0;
if (speed < 99.995) // 1.00 GB/s to 99.99 GB/s
{
return [NSString localizedStringWithFormat:@"%.2f %@", speed, gb];
}
else // insane speeds
{
return [NSString localizedStringWithFormat:@"%.2f %@", speed / 1000.0, gb];
return [NSString localizedStringWithFormat:@"%.1f %@", speed, gb];
}
}