cc-pets 1.3.2 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/Sources/CCPets/PetView.m +13 -13
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/Sources/CCPets/PetView.m
CHANGED
|
@@ -10,7 +10,7 @@ static const CGFloat PetDragThreshold = 3.0;
|
|
|
10
10
|
static const CGFloat PetMenuRowWidth = 194.0;
|
|
11
11
|
static const CGFloat PetSubmenuRowWidth = 134.0;
|
|
12
12
|
// 与“系统通知”里文案到开关的间距共用,素材名称到删除按钮也保持一致。
|
|
13
|
-
static const CGFloat PetMenuControlGap =
|
|
13
|
+
static const CGFloat PetMenuControlGap = 8.0;
|
|
14
14
|
static const NSInteger PetMenuCheckViewTag = 1001;
|
|
15
15
|
static const NSInteger PetMenuDeleteButtonTag = 1002;
|
|
16
16
|
|
|
@@ -441,34 +441,34 @@ static const NSInteger PetMenuDeleteButtonTag = 1002;
|
|
|
441
441
|
}
|
|
442
442
|
}
|
|
443
443
|
}
|
|
444
|
-
- (NSString *)displayNameForPetName:(NSString *)name {
|
|
444
|
+
- (NSString *)displayNameForPetName:(NSString *)name font:(NSFont *)font maxWidth:(CGFloat)maxWidth {
|
|
445
445
|
if (![name isKindOfClass:NSString.class]) return @"";
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
446
|
+
NSDictionary<NSAttributedStringKey, id> *attributes = @{NSFontAttributeName: font};
|
|
447
|
+
if ([name sizeWithAttributes:attributes].width <= maxWidth) return name;
|
|
448
|
+
|
|
449
|
+
NSString *suffix = @"...";
|
|
450
|
+
NSMutableString *prefix = [NSMutableString string];
|
|
449
451
|
[name enumerateSubstringsInRange:NSMakeRange(0, name.length)
|
|
450
452
|
options:NSStringEnumerationByComposedCharacterSequences
|
|
451
453
|
usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
+
NSString *candidate = [NSString stringWithFormat:@"%@%@%@", prefix, substring, suffix];
|
|
455
|
+
if ([candidate sizeWithAttributes:attributes].width > maxWidth) {
|
|
454
456
|
*stop = YES;
|
|
455
457
|
return;
|
|
456
458
|
}
|
|
457
|
-
|
|
458
|
-
end = NSMaxRange(substringRange);
|
|
459
|
+
[prefix appendString:substring];
|
|
459
460
|
}];
|
|
460
|
-
|
|
461
|
-
return [[name substringToIndex:end] stringByAppendingString:@"..."];
|
|
461
|
+
return [prefix stringByAppendingString:suffix];
|
|
462
462
|
}
|
|
463
463
|
- (NSMenuItem *)addPetOption:(NSDictionary *)pet toMenu:(NSMenu *)menu {
|
|
464
464
|
NSString *petID = [pet[@"id"] isKindOfClass:NSString.class] ? pet[@"id"] : @"";
|
|
465
465
|
NSString *name = [pet[@"name"] isKindOfClass:NSString.class] ? pet[@"name"] : @"";
|
|
466
|
-
NSString *displayName = [self displayNameForPetName:name];
|
|
467
466
|
BOOL selected = [petID isEqualToString:self.currentPetID];
|
|
468
467
|
BOOL deletable = [petID hasPrefix:@"external:"];
|
|
469
468
|
|
|
470
469
|
NSFont *font = [NSFont menuFontOfSize:13];
|
|
471
|
-
CGFloat nameWidth = ceil([@"
|
|
470
|
+
CGFloat nameWidth = ceil([@"桌宠素材名..." sizeWithAttributes:@{NSFontAttributeName: font}].width);
|
|
471
|
+
NSString *displayName = [self displayNameForPetName:name font:font maxWidth:nameWidth];
|
|
472
472
|
const CGFloat checkWidth = 14;
|
|
473
473
|
const CGFloat leadingInset = 6;
|
|
474
474
|
const CGFloat nameX = leadingInset + checkWidth;
|