fix: change badge font size, position and precision (#5184)
This commit is contained in:
parent
b354337720
commit
b1f6fbc05d
|
@ -42,7 +42,7 @@ typedef NS_ENUM(NSInteger, ArrowDirection) {
|
|||
_fAttributes = [[NSMutableDictionary alloc] initWithCapacity:3];
|
||||
_fAttributes[NSForegroundColorAttributeName] = NSColor.whiteColor;
|
||||
_fAttributes[NSShadowAttributeName] = stringShadow;
|
||||
_fAttributes[NSFontAttributeName] = [NSFont boldSystemFontOfSize:23.0];
|
||||
_fAttributes[NSFontAttributeName] = [NSFont boldSystemFontOfSize:26.0];
|
||||
|
||||
// DownloadBadge and UploadBadge should have the same size
|
||||
NSSize badgeSize = [NSImage imageNamed:@"DownloadBadge"].size;
|
||||
|
@ -81,7 +81,8 @@ typedef NS_ENUM(NSInteger, ArrowDirection) {
|
|||
if (download)
|
||||
{
|
||||
NSImage* downloadBadge = [NSImage imageNamed:@"DownloadBadge"];
|
||||
[self badge:downloadBadge arrow:ArrowDirectionDown string:[NSString stringForSpeedAbbrev:self.fDownloadRate] atHeight:bottom];
|
||||
[self badge:downloadBadge arrow:ArrowDirectionDown string:[NSString stringForSpeedAbbrevCompact:self.fDownloadRate]
|
||||
atHeight:bottom];
|
||||
|
||||
if (upload)
|
||||
{
|
||||
|
@ -91,7 +92,7 @@ typedef NS_ENUM(NSInteger, ArrowDirection) {
|
|||
if (upload)
|
||||
{
|
||||
[self badge:[NSImage imageNamed:@"UploadBadge"] arrow:ArrowDirectionUp
|
||||
string:[NSString stringForSpeedAbbrev:self.fUploadRate]
|
||||
string:[NSString stringForSpeedAbbrevCompact:self.fUploadRate]
|
||||
atHeight:bottom];
|
||||
}
|
||||
}
|
||||
|
@ -105,8 +106,8 @@ typedef NS_ENUM(NSInteger, ArrowDirection) {
|
|||
//string is in center of image
|
||||
NSSize stringSize = [string sizeWithAttributes:self.fAttributes];
|
||||
NSRect stringRect;
|
||||
stringRect.origin.x = NSMidX(badgeRect) - stringSize.width * 0.5;
|
||||
stringRect.origin.y = NSMidY(badgeRect) - stringSize.height * 0.5 + 1.0; //adjust for shadow
|
||||
stringRect.origin.x = NSMidX(badgeRect) - stringSize.width * 0.5 + kArrowInset.width; // adjust for arrow
|
||||
stringRect.origin.y = NSMidY(badgeRect) - stringSize.height * 0.5 + 1.0; // adjust for shadow
|
||||
stringRect.size = stringSize;
|
||||
[string drawInRect:stringRect withAttributes:self.fAttributes];
|
||||
|
||||
|
|
|
@ -12,8 +12,12 @@
|
|||
+ (NSString*)stringForFileSize:(uint64_t)size;
|
||||
+ (NSString*)stringForFilePartialSize:(uint64_t)partialSize fullSize:(uint64_t)fullSize;
|
||||
|
||||
// 4 significant digits
|
||||
+ (NSString*)stringForSpeed:(CGFloat)speed;
|
||||
// 4 significant digits
|
||||
+ (NSString*)stringForSpeedAbbrev:(CGFloat)speed;
|
||||
// 3 significant digits
|
||||
+ (NSString*)stringForSpeedAbbrevCompact:(CGFloat)speed;
|
||||
+ (NSString*)stringForRatio:(CGFloat)ratio;
|
||||
|
||||
+ (NSString*)percentString:(CGFloat)progress longDecimals:(BOOL)longDecimals;
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
@interface NSString (Private)
|
||||
|
||||
+ (NSString*)stringForSpeed:(CGFloat)speed kb:(NSString*)kb mb:(NSString*)mb gb:(NSString*)gb;
|
||||
+ (NSString*)stringForSpeedCompact:(CGFloat)speed kb:(NSString*)kb mb:(NSString*)mb gb:(NSString*)gb;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -73,6 +74,11 @@
|
|||
return [self stringForSpeed:speed kb:@"K" mb:@"M" gb:@"G"];
|
||||
}
|
||||
|
||||
+ (NSString*)stringForSpeedAbbrevCompact:(CGFloat)speed
|
||||
{
|
||||
return [self stringForSpeedCompact:speed kb:@"K" mb:@"M" gb:@"G"];
|
||||
}
|
||||
|
||||
+ (NSString*)stringForRatio:(CGFloat)ratio
|
||||
{
|
||||
//N/A is different than libtransmission's
|
||||
|
@ -188,4 +194,46 @@
|
|||
}
|
||||
}
|
||||
|
||||
+ (NSString*)stringForSpeedCompact:(CGFloat)speed kb:(NSString*)kb mb:(NSString*)mb gb:(NSString*)gb
|
||||
{
|
||||
if (speed < 99.95) // 0.0 KB/s to 99.9 KB/s
|
||||
{
|
||||
return [NSString localizedStringWithFormat:@"%.1f %@", speed, kb];
|
||||
}
|
||||
if (speed < 999.95) // 100 KB/s to 999 KB/s
|
||||
{
|
||||
return [NSString localizedStringWithFormat:@"%.0f %@", speed, kb];
|
||||
}
|
||||
|
||||
speed /= 1000.0;
|
||||
|
||||
if (speed < 9.95) // 1.00 MB/s to 9.99 MB/s
|
||||
{
|
||||
return [NSString localizedStringWithFormat:@"%.2f %@", speed, mb];
|
||||
}
|
||||
if (speed < 99.95) // 10.0 MB/s to 99.9 MB/s
|
||||
{
|
||||
return [NSString localizedStringWithFormat:@"%.1f %@", speed, mb];
|
||||
}
|
||||
if (speed < 999.95) // 100 MB/s to 999 MB/s
|
||||
{
|
||||
return [NSString localizedStringWithFormat:@"%.0f %@", speed, mb];
|
||||
}
|
||||
|
||||
speed /= 1000.0;
|
||||
|
||||
if (speed < 9.95) // 1.00 GB/s to 9.99 GB/s
|
||||
{
|
||||
return [NSString localizedStringWithFormat:@"%.2f %@", speed, gb];
|
||||
}
|
||||
if (speed < 99.95) // 10.0 GB/s to 99.9 GB/s
|
||||
{
|
||||
return [NSString localizedStringWithFormat:@"%.1f %@", speed, gb];
|
||||
}
|
||||
else // insane speeds
|
||||
{
|
||||
return [NSString localizedStringWithFormat:@"%.0f %@", speed, gb];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue