summaryrefslogtreecommitdiffstats
path: root/macosx/HBAttributedStringAdditions.m
diff options
context:
space:
mode:
authorDamiano Galassi <[email protected]>2019-07-20 10:14:44 +0200
committerDamiano Galassi <[email protected]>2019-07-20 10:14:44 +0200
commit988752d2bce5814044f0db63a952d7e3b29f7ff1 (patch)
tree8c67c89e60279045c2160584ba626f26b9a61a6f /macosx/HBAttributedStringAdditions.m
parent61db67faf4bb26ce72cc22884e77269c038678c6 (diff)
MacGui: add a NSString extension to create monospaced strings.
Diffstat (limited to 'macosx/HBAttributedStringAdditions.m')
-rw-r--r--macosx/HBAttributedStringAdditions.m25
1 files changed, 25 insertions, 0 deletions
diff --git a/macosx/HBAttributedStringAdditions.m b/macosx/HBAttributedStringAdditions.m
index 12b9c8b4f..e20129c6b 100644
--- a/macosx/HBAttributedStringAdditions.m
+++ b/macosx/HBAttributedStringAdditions.m
@@ -6,6 +6,9 @@
#import "HBAttributedStringAdditions.h"
+static NSDictionary *_monospacedAttr = nil;
+static NSDictionary *_normalMonospacedAttr = nil;
+
@implementation NSMutableAttributedString (HBAttributedStringAdditions)
- (void)appendString:(NSString *)aString withAttributes:(NSDictionary *)aDictionary
@@ -16,3 +19,25 @@
}
@end
+
+@implementation NSString (HBAttributedStringAdditions)
+
+- (NSAttributedString *)HB_monospacedString
+{
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ _normalMonospacedAttr = @{NSFontAttributeName: [NSFont monospacedDigitSystemFontOfSize:15 weight:NSFontWeightRegular]};
+ });
+ return [[NSAttributedString alloc] initWithString:self attributes:_normalMonospacedAttr];
+}
+
+- (NSAttributedString *)HB_smallMonospacedString
+{
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ _monospacedAttr = @{NSFontAttributeName: [NSFont monospacedDigitSystemFontOfSize:[NSFont smallSystemFontSize] weight:NSFontWeightRegular]};
+ });
+ return [[NSAttributedString alloc] initWithString:self attributes:_monospacedAttr];
+}
+
+@end