Remove no-longer-used RSSingleLineView and RSSingleLineRenderer.
This commit is contained in:
parent
f11604df48
commit
6d46b44e22
@ -165,7 +165,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
|
|||||||
|
|
||||||
func applicationDidResignActive(_ notification: Notification) {
|
func applicationDidResignActive(_ notification: Notification) {
|
||||||
|
|
||||||
RSSingleLineRenderer.emptyCache()
|
|
||||||
RSMultiLineRenderer.emptyCache()
|
RSMultiLineRenderer.emptyCache()
|
||||||
TimelineCellData.emptyCache()
|
TimelineCellData.emptyCache()
|
||||||
timelineEmptyCaches()
|
timelineEmptyCaches()
|
||||||
|
@ -109,7 +109,6 @@ private extension TimelineCellLayout {
|
|||||||
|
|
||||||
let font = attributedString.attribute(NSAttributedStringKey.font, at: 0, effectiveRange: nil) as! NSFont
|
let font = attributedString.attribute(NSAttributedStringKey.font, at: 0, effectiveRange: nil) as! NSFont
|
||||||
let textFieldSize = SingleLineTextFieldSizer.size(for: attributedString.string, font: font)
|
let textFieldSize = SingleLineTextFieldSizer.size(for: attributedString.string, font: font)
|
||||||
// let renderer = RSSingleLineRenderer(attributedTitle: attributedString)
|
|
||||||
var r = NSZeroRect
|
var r = NSZeroRect
|
||||||
r.size = textFieldSize
|
r.size = textFieldSize
|
||||||
r.origin.y = NSMaxY(rectAbove) + topMargin
|
r.origin.y = NSMaxY(rectAbove) + topMargin
|
||||||
|
@ -135,7 +135,6 @@ class TimelineViewController: NSViewController, UndoableCommandRunner {
|
|||||||
private func fontSizeDidChange() {
|
private func fontSizeDidChange() {
|
||||||
|
|
||||||
TimelineCellData.emptyCache()
|
TimelineCellData.emptyCache()
|
||||||
RSSingleLineRenderer.emptyCache()
|
|
||||||
RSMultiLineRenderer.emptyCache()
|
RSMultiLineRenderer.emptyCache()
|
||||||
|
|
||||||
cellAppearance = TimelineCellAppearance(theme: appDelegate.currentTheme, showAvatar: false, fontSize: fontSize)
|
cellAppearance = TimelineCellAppearance(theme: appDelegate.currentTheme, showAvatar: false, fontSize: fontSize)
|
||||||
|
@ -12,10 +12,6 @@
|
|||||||
8439D9FF1C8937C800E5E4B4 /* RSTextDrawing.h in Headers */ = {isa = PBXBuildFile; fileRef = 8439D9FE1C8937C800E5E4B4 /* RSTextDrawing.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
8439D9FF1C8937C800E5E4B4 /* RSTextDrawing.h in Headers */ = {isa = PBXBuildFile; fileRef = 8439D9FE1C8937C800E5E4B4 /* RSTextDrawing.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
8439DA061C8937C800E5E4B4 /* RSTextDrawing.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8439D9FB1C8937C800E5E4B4 /* RSTextDrawing.framework */; };
|
8439DA061C8937C800E5E4B4 /* RSTextDrawing.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8439D9FB1C8937C800E5E4B4 /* RSTextDrawing.framework */; };
|
||||||
8439DA0B1C8937C800E5E4B4 /* RSTextDrawingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8439DA0A1C8937C800E5E4B4 /* RSTextDrawingTests.m */; };
|
8439DA0B1C8937C800E5E4B4 /* RSTextDrawingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8439DA0A1C8937C800E5E4B4 /* RSTextDrawingTests.m */; };
|
||||||
846416401C8938210064C661 /* RSSingleLineRenderer.h in Headers */ = {isa = PBXBuildFile; fileRef = 8464163E1C8938210064C661 /* RSSingleLineRenderer.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
|
||||||
846416411C8938210064C661 /* RSSingleLineRenderer.m in Sources */ = {isa = PBXBuildFile; fileRef = 8464163F1C8938210064C661 /* RSSingleLineRenderer.m */; };
|
|
||||||
84B717761CF9629000FF029D /* RSSingleLineView.h in Headers */ = {isa = PBXBuildFile; fileRef = 84B717741CF9629000FF029D /* RSSingleLineView.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
|
||||||
84B717771CF9629000FF029D /* RSSingleLineView.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B717751CF9629000FF029D /* RSSingleLineView.m */; };
|
|
||||||
84B7177B1CF9665100FF029D /* RSMultiLineView.h in Headers */ = {isa = PBXBuildFile; fileRef = 84B717791CF9665100FF029D /* RSMultiLineView.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
84B7177B1CF9665100FF029D /* RSMultiLineView.h in Headers */ = {isa = PBXBuildFile; fileRef = 84B717791CF9665100FF029D /* RSMultiLineView.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
84B7177C1CF9665100FF029D /* RSMultiLineView.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B7177A1CF9665100FF029D /* RSMultiLineView.m */; };
|
84B7177C1CF9665100FF029D /* RSMultiLineView.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B7177A1CF9665100FF029D /* RSMultiLineView.m */; };
|
||||||
84B7177D1CF9834700FF029D /* RSMultiLineRenderer.m in Sources */ = {isa = PBXBuildFile; fileRef = 846416431C8938470064C661 /* RSMultiLineRenderer.m */; };
|
84B7177D1CF9834700FF029D /* RSMultiLineRenderer.m in Sources */ = {isa = PBXBuildFile; fileRef = 846416431C8938470064C661 /* RSMultiLineRenderer.m */; };
|
||||||
@ -43,12 +39,8 @@
|
|||||||
8439DA051C8937C800E5E4B4 /* RSTextDrawingTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RSTextDrawingTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
8439DA051C8937C800E5E4B4 /* RSTextDrawingTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RSTextDrawingTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
8439DA0A1C8937C800E5E4B4 /* RSTextDrawingTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RSTextDrawingTests.m; sourceTree = "<group>"; };
|
8439DA0A1C8937C800E5E4B4 /* RSTextDrawingTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RSTextDrawingTests.m; sourceTree = "<group>"; };
|
||||||
8439DA0C1C8937C800E5E4B4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
8439DA0C1C8937C800E5E4B4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||||
8464163E1C8938210064C661 /* RSSingleLineRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RSSingleLineRenderer.h; path = RSTextDrawing/RSSingleLineRenderer.h; sourceTree = "<group>"; };
|
|
||||||
8464163F1C8938210064C661 /* RSSingleLineRenderer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RSSingleLineRenderer.m; path = RSTextDrawing/RSSingleLineRenderer.m; sourceTree = "<group>"; };
|
|
||||||
846416421C8938470064C661 /* RSMultiLineRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RSMultiLineRenderer.h; path = RSTextDrawing/RSMultiLineRenderer.h; sourceTree = "<group>"; };
|
846416421C8938470064C661 /* RSMultiLineRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RSMultiLineRenderer.h; path = RSTextDrawing/RSMultiLineRenderer.h; sourceTree = "<group>"; };
|
||||||
846416431C8938470064C661 /* RSMultiLineRenderer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RSMultiLineRenderer.m; path = RSTextDrawing/RSMultiLineRenderer.m; sourceTree = "<group>"; };
|
846416431C8938470064C661 /* RSMultiLineRenderer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RSMultiLineRenderer.m; path = RSTextDrawing/RSMultiLineRenderer.m; sourceTree = "<group>"; };
|
||||||
84B717741CF9629000FF029D /* RSSingleLineView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RSSingleLineView.h; path = RSTextDrawing/RSSingleLineView.h; sourceTree = "<group>"; };
|
|
||||||
84B717751CF9629000FF029D /* RSSingleLineView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RSSingleLineView.m; path = RSTextDrawing/RSSingleLineView.m; sourceTree = "<group>"; };
|
|
||||||
84B717791CF9665100FF029D /* RSMultiLineView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RSMultiLineView.h; path = RSTextDrawing/RSMultiLineView.h; sourceTree = "<group>"; };
|
84B717791CF9665100FF029D /* RSMultiLineView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RSMultiLineView.h; path = RSTextDrawing/RSMultiLineView.h; sourceTree = "<group>"; };
|
||||||
84B7177A1CF9665100FF029D /* RSMultiLineView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RSMultiLineView.m; path = RSTextDrawing/RSMultiLineView.m; sourceTree = "<group>"; };
|
84B7177A1CF9665100FF029D /* RSMultiLineView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RSMultiLineView.m; path = RSTextDrawing/RSMultiLineView.m; sourceTree = "<group>"; };
|
||||||
84BA010D1C8D20C60029943B /* RSTextRendererProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RSTextRendererProtocol.h; path = RSTextDrawing/RSTextRendererProtocol.h; sourceTree = "<group>"; };
|
84BA010D1C8D20C60029943B /* RSTextRendererProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RSTextRendererProtocol.h; path = RSTextDrawing/RSTextRendererProtocol.h; sourceTree = "<group>"; };
|
||||||
@ -84,13 +76,9 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
8439D9FE1C8937C800E5E4B4 /* RSTextDrawing.h */,
|
8439D9FE1C8937C800E5E4B4 /* RSTextDrawing.h */,
|
||||||
84B717741CF9629000FF029D /* RSSingleLineView.h */,
|
|
||||||
84B717751CF9629000FF029D /* RSSingleLineView.m */,
|
|
||||||
84B717791CF9665100FF029D /* RSMultiLineView.h */,
|
84B717791CF9665100FF029D /* RSMultiLineView.h */,
|
||||||
84B7177A1CF9665100FF029D /* RSMultiLineView.m */,
|
84B7177A1CF9665100FF029D /* RSMultiLineView.m */,
|
||||||
84BA010D1C8D20C60029943B /* RSTextRendererProtocol.h */,
|
84BA010D1C8D20C60029943B /* RSTextRendererProtocol.h */,
|
||||||
8464163E1C8938210064C661 /* RSSingleLineRenderer.h */,
|
|
||||||
8464163F1C8938210064C661 /* RSSingleLineRenderer.m */,
|
|
||||||
846416421C8938470064C661 /* RSMultiLineRenderer.h */,
|
846416421C8938470064C661 /* RSMultiLineRenderer.h */,
|
||||||
846416431C8938470064C661 /* RSMultiLineRenderer.m */,
|
846416431C8938470064C661 /* RSMultiLineRenderer.m */,
|
||||||
84193AB11CF4EEEB00EAC812 /* RSMultiLineRendererMeasurements.h */,
|
84193AB11CF4EEEB00EAC812 /* RSMultiLineRendererMeasurements.h */,
|
||||||
@ -141,12 +129,10 @@
|
|||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
8439D9FF1C8937C800E5E4B4 /* RSTextDrawing.h in Headers */,
|
8439D9FF1C8937C800E5E4B4 /* RSTextDrawing.h in Headers */,
|
||||||
84B717761CF9629000FF029D /* RSSingleLineView.h in Headers */,
|
|
||||||
84B7177E1CF9834A00FF029D /* RSMultiLineRenderer.h in Headers */,
|
84B7177E1CF9834A00FF029D /* RSMultiLineRenderer.h in Headers */,
|
||||||
84BA010F1C8D20C60029943B /* RSTextRendererProtocol.h in Headers */,
|
84BA010F1C8D20C60029943B /* RSTextRendererProtocol.h in Headers */,
|
||||||
84193AB31CF4EEEB00EAC812 /* RSMultiLineRendererMeasurements.h in Headers */,
|
84193AB31CF4EEEB00EAC812 /* RSMultiLineRendererMeasurements.h in Headers */,
|
||||||
84B7177B1CF9665100FF029D /* RSMultiLineView.h in Headers */,
|
84B7177B1CF9665100FF029D /* RSMultiLineView.h in Headers */,
|
||||||
846416401C8938210064C661 /* RSSingleLineRenderer.h in Headers */,
|
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
@ -249,9 +235,7 @@
|
|||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
84B717771CF9629000FF029D /* RSSingleLineView.m in Sources */,
|
|
||||||
84B7177C1CF9665100FF029D /* RSMultiLineView.m in Sources */,
|
84B7177C1CF9665100FF029D /* RSMultiLineView.m in Sources */,
|
||||||
846416411C8938210064C661 /* RSSingleLineRenderer.m in Sources */,
|
|
||||||
84B7177D1CF9834700FF029D /* RSMultiLineRenderer.m in Sources */,
|
84B7177D1CF9834700FF029D /* RSMultiLineRenderer.m in Sources */,
|
||||||
84193AB41CF4EEEB00EAC812 /* RSMultiLineRendererMeasurements.m in Sources */,
|
84193AB41CF4EEEB00EAC812 /* RSMultiLineRendererMeasurements.m in Sources */,
|
||||||
);
|
);
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
//
|
|
||||||
// SingleLineRenderer.h
|
|
||||||
// RSTextDrawing
|
|
||||||
//
|
|
||||||
// Created by Brent Simmons on 3/3/16.
|
|
||||||
// Copyright © 2016 Ranchero Software, LLC. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
@import AppKit;
|
|
||||||
#import <RSTextDrawing/RSTextRendererProtocol.h>
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
|
||||||
|
|
||||||
@interface RSSingleLineRenderer : NSObject <RSTextRenderer>
|
|
||||||
|
|
||||||
+ (instancetype)rendererWithAttributedTitle:(NSAttributedString *)title;
|
|
||||||
|
|
||||||
@property (nonatomic, readonly) NSSize size;
|
|
||||||
|
|
||||||
@property (nonatomic, strong) NSColor *backgroundColor; // Default is white.
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
|
@ -1,204 +0,0 @@
|
|||||||
//
|
|
||||||
// RSSingleLineRenderer.m
|
|
||||||
// RSTextDrawing
|
|
||||||
//
|
|
||||||
// Created by Brent Simmons on 3/3/16.
|
|
||||||
// Copyright © 2016 Ranchero Software, LLC. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "RSSingleLineRenderer.h"
|
|
||||||
|
|
||||||
static NSMutableDictionary *rendererCache = nil;
|
|
||||||
|
|
||||||
@interface RSSingleLineRenderer ()
|
|
||||||
|
|
||||||
@property (nonatomic, readonly) NSAttributedString *title;
|
|
||||||
@property (nonatomic) NSRect rect;
|
|
||||||
@property (nonatomic, readonly) CTFramesetterRef framesetter;
|
|
||||||
@property (nonatomic) CTFrameRef frameref;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
|
|
||||||
@implementation RSSingleLineRenderer
|
|
||||||
|
|
||||||
@synthesize size = _size;
|
|
||||||
|
|
||||||
#pragma mark - Class Methods
|
|
||||||
|
|
||||||
+ (void)initialize {
|
|
||||||
|
|
||||||
static dispatch_once_t onceToken;
|
|
||||||
dispatch_once(&onceToken, ^{
|
|
||||||
|
|
||||||
rendererCache = [NSMutableDictionary new];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
+ (instancetype)rendererWithAttributedTitle:(NSAttributedString *)title {
|
|
||||||
|
|
||||||
RSSingleLineRenderer *cachedRenderer = rendererCache[title];
|
|
||||||
if (cachedRenderer != nil) {
|
|
||||||
return cachedRenderer;
|
|
||||||
}
|
|
||||||
|
|
||||||
RSSingleLineRenderer *renderer = [[RSSingleLineRenderer alloc] initWithAttributedTitle:title];
|
|
||||||
rendererCache[title] = renderer;
|
|
||||||
return renderer;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
+ (void)emptyCache {
|
|
||||||
|
|
||||||
rendererCache = [NSMutableDictionary new];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - Init
|
|
||||||
|
|
||||||
- (instancetype)initWithAttributedTitle:(NSAttributedString *)title {
|
|
||||||
|
|
||||||
self = [super init];
|
|
||||||
if (self == nil) {
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
_title = title;
|
|
||||||
_framesetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)title);
|
|
||||||
_backgroundColor = NSColor.whiteColor;
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - Dealloc
|
|
||||||
|
|
||||||
- (void)dealloc {
|
|
||||||
|
|
||||||
if (_framesetter) {
|
|
||||||
CFRelease(_framesetter);
|
|
||||||
_framesetter = nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_frameref) {
|
|
||||||
CFRelease(_frameref);
|
|
||||||
_frameref = nil;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - Accessors
|
|
||||||
|
|
||||||
- (void)setRect:(NSRect)r {
|
|
||||||
|
|
||||||
r.origin.y = floor(r.origin.y);
|
|
||||||
r.origin.x = floor(r.origin.x);
|
|
||||||
r.size.height = floor(r.size.height);
|
|
||||||
if (r.size.height > self.size.height) {
|
|
||||||
r.size.height = self.size.height;
|
|
||||||
}
|
|
||||||
r.size.width = floor(r.size.width);
|
|
||||||
if (r.size.width > self.size.width) {
|
|
||||||
r.size.width = self.size.width;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!NSEqualRects(r, _rect)) {
|
|
||||||
_rect = r;
|
|
||||||
[self releaseFrameref];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)releaseFrameref {
|
|
||||||
|
|
||||||
if (_frameref) {
|
|
||||||
CFRelease(_frameref);
|
|
||||||
_frameref = nil;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (NSSize)size {
|
|
||||||
|
|
||||||
if (self.title.string.length < 1) {
|
|
||||||
return NSZeroSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NSEqualSizes(_size, NSZeroSize)) {
|
|
||||||
_size = [self calculatedSize];
|
|
||||||
}
|
|
||||||
return _size;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - Measurements
|
|
||||||
|
|
||||||
static const CGFloat kMaxWidth = 10000.0;
|
|
||||||
static const CGFloat kMaxHeight = 10000.0;
|
|
||||||
|
|
||||||
- (NSSize)calculatedSize {
|
|
||||||
|
|
||||||
NSSize size = NSZeroSize;
|
|
||||||
|
|
||||||
@autoreleasepool {
|
|
||||||
|
|
||||||
CGRect r = CGRectMake(0.0f, 0.0f, kMaxWidth, kMaxHeight);
|
|
||||||
CGPathRef path = CGPathCreateWithRect(r, NULL);
|
|
||||||
|
|
||||||
CTFrameRef frameref = CTFramesetterCreateFrame(self.framesetter, CFRangeMake(0, (CFIndex)(self.title.length)), path, NULL);
|
|
||||||
|
|
||||||
NSArray *lines = (__bridge NSArray *)CTFrameGetLines(frameref);
|
|
||||||
|
|
||||||
if (lines.count > 0) {
|
|
||||||
|
|
||||||
CTLineRef firstLine = (__bridge CTLineRef)lines[0];
|
|
||||||
CGRect firstLineRect = CTLineGetBoundsWithOptions(firstLine, 0);
|
|
||||||
CGFloat height = ceil(NSHeight(firstLineRect));
|
|
||||||
CGFloat width = ceil(NSWidth(firstLineRect));
|
|
||||||
size = NSMakeSize(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
CFRelease(path);
|
|
||||||
CFRelease(frameref);
|
|
||||||
}
|
|
||||||
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - Drawing
|
|
||||||
|
|
||||||
- (void)renderTextInRect:(CGRect)r {
|
|
||||||
|
|
||||||
self.rect = r;
|
|
||||||
|
|
||||||
CGContextRef context = [NSGraphicsContext currentContext].CGContext;
|
|
||||||
CGContextSaveGState(context);
|
|
||||||
|
|
||||||
CGContextSetFillColorWithColor(context, self.backgroundColor.CGColor);
|
|
||||||
CGContextFillRect(context, r);
|
|
||||||
|
|
||||||
CGContextSetShouldSmoothFonts(context, true);
|
|
||||||
|
|
||||||
CTFrameDraw(self.frameref, context);
|
|
||||||
|
|
||||||
CGContextRestoreGState(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (CTFrameRef)frameref {
|
|
||||||
|
|
||||||
if (_frameref) {
|
|
||||||
return _frameref;
|
|
||||||
}
|
|
||||||
|
|
||||||
CGPathRef path = CGPathCreateWithRect(self.rect, NULL);
|
|
||||||
|
|
||||||
_frameref = CTFramesetterCreateFrame(self.framesetter, CFRangeMake(0, (CFIndex)(self.title.length)), path, NULL);
|
|
||||||
|
|
||||||
CFRelease(path);
|
|
||||||
|
|
||||||
return _frameref;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
@ -1,22 +0,0 @@
|
|||||||
//
|
|
||||||
// RSSingleLineView.h
|
|
||||||
// RSTextDrawing
|
|
||||||
//
|
|
||||||
// Created by Brent Simmons on 5/27/16.
|
|
||||||
// Copyright © 2016 Ranchero Software, LLC. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
@import AppKit;
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
|
||||||
|
|
||||||
@interface RSSingleLineView : NSView
|
|
||||||
|
|
||||||
@property (nonatomic, strong) NSAttributedString *attributedStringValue;
|
|
||||||
|
|
||||||
@property (nonatomic) BOOL selected;
|
|
||||||
@property (nonatomic) BOOL emphasized;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
|
@ -1,158 +0,0 @@
|
|||||||
//
|
|
||||||
// RSSingleLineView.m
|
|
||||||
// RSTextDrawing
|
|
||||||
//
|
|
||||||
// Created by Brent Simmons on 5/27/16.
|
|
||||||
// Copyright © 2016 Ranchero Software, LLC. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
@import RSCore;
|
|
||||||
#import "RSSingleLineView.h"
|
|
||||||
#import "RSSingleLineRenderer.h"
|
|
||||||
|
|
||||||
@interface RSSingleLineView ()
|
|
||||||
|
|
||||||
@property (nonatomic) RSSingleLineRenderer *renderer;
|
|
||||||
@property (nonatomic) NSSize intrinsicSize;
|
|
||||||
@property (nonatomic) BOOL intrinsicSizeIsValid;
|
|
||||||
@property (nonatomic) RSSingleLineRenderer *selectedRenderer;
|
|
||||||
@property (nonatomic) NSAttributedString *selectedAttributedStringValue;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
static NSAttributedString *emptyAttributedString = nil;
|
|
||||||
|
|
||||||
@implementation RSSingleLineView
|
|
||||||
|
|
||||||
- (instancetype)initWithFrame:(NSRect)r {
|
|
||||||
|
|
||||||
self = [super initWithFrame:r];
|
|
||||||
if (!self) {
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
static dispatch_once_t onceToken;
|
|
||||||
dispatch_once(&onceToken, ^{
|
|
||||||
emptyAttributedString = [[NSAttributedString alloc] initWithString:@""];
|
|
||||||
});
|
|
||||||
|
|
||||||
_renderer = [RSSingleLineRenderer rendererWithAttributedTitle:emptyAttributedString];
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)setAttributedStringValue:(NSAttributedString *)attributedStringValue {
|
|
||||||
|
|
||||||
_attributedStringValue = attributedStringValue;
|
|
||||||
self.selectedAttributedStringValue = nil;
|
|
||||||
self.selectedRenderer = nil;
|
|
||||||
|
|
||||||
self.renderer = [RSSingleLineRenderer rendererWithAttributedTitle:attributedStringValue];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)setRenderer:(RSSingleLineRenderer *)renderer {
|
|
||||||
|
|
||||||
if (_renderer == renderer) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_renderer = renderer;
|
|
||||||
[self invalidateIntrinsicContentSize];
|
|
||||||
self.needsDisplay = YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (RSSingleLineRenderer *)selectedRenderer {
|
|
||||||
|
|
||||||
if (_selectedRenderer) {
|
|
||||||
return _selectedRenderer;
|
|
||||||
}
|
|
||||||
|
|
||||||
_selectedRenderer = [RSSingleLineRenderer rendererWithAttributedTitle:self.selectedAttributedStringValue];
|
|
||||||
_selectedRenderer.backgroundColor = NSColor.alternateSelectedControlColor;
|
|
||||||
return _selectedRenderer;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)setSelected:(BOOL)selected {
|
|
||||||
|
|
||||||
_selected = selected;
|
|
||||||
self.needsDisplay = YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)setEmphasized:(BOOL)emphasized {
|
|
||||||
|
|
||||||
_emphasized = emphasized;
|
|
||||||
self.needsDisplay = YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (NSAttributedString *)selectedAttributedStringValue {
|
|
||||||
|
|
||||||
if (!self.attributedStringValue) {
|
|
||||||
return emptyAttributedString;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSMutableAttributedString *s = [self.attributedStringValue mutableCopy];
|
|
||||||
[s addAttribute:NSForegroundColorAttributeName value:NSColor.alternateSelectedControlTextColor range:NSMakeRange(0, s.string.length)];
|
|
||||||
_selectedAttributedStringValue = s;
|
|
||||||
|
|
||||||
return _selectedAttributedStringValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)invalidateIntrinsicContentSize {
|
|
||||||
|
|
||||||
self.intrinsicSizeIsValid = NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (NSSize)intrinsicContentSize {
|
|
||||||
|
|
||||||
if (!self.intrinsicSizeIsValid) {
|
|
||||||
if (!self.attributedStringValue) {
|
|
||||||
self.intrinsicSize = NSZeroSize;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
self.intrinsicSize = ((RSSingleLineRenderer *)(self.renderer)).size;
|
|
||||||
}
|
|
||||||
self.intrinsicSizeIsValid = YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
return self.intrinsicSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSMenu *)menuForEvent:(NSEvent *)event {
|
|
||||||
|
|
||||||
NSTableView *tableView = [self rs_enclosingTableView];
|
|
||||||
if (tableView) {
|
|
||||||
return [tableView menuForEvent:event];
|
|
||||||
}
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)drawRect:(NSRect)r {
|
|
||||||
|
|
||||||
if (self.selected) {
|
|
||||||
|
|
||||||
if (self.emphasized) {
|
|
||||||
[self.selectedRenderer renderTextInRect:self.bounds];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
NSColor *savedBackgroundColor = self.renderer.backgroundColor;
|
|
||||||
self.renderer.backgroundColor = NSColor.secondarySelectedControlColor;
|
|
||||||
[self.renderer renderTextInRect:self.bounds];
|
|
||||||
self.renderer.backgroundColor = savedBackgroundColor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
[self.renderer renderTextInRect:self.bounds];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
@ -8,10 +8,8 @@
|
|||||||
|
|
||||||
@import AppKit;
|
@import AppKit;
|
||||||
|
|
||||||
#import <RSTextDrawing/RSSingleLineView.h>
|
|
||||||
#import <RSTextDrawing/RSMultiLineView.h>
|
#import <RSTextDrawing/RSMultiLineView.h>
|
||||||
|
|
||||||
#import <RSTextDrawing/RSSingleLineRenderer.h>
|
|
||||||
#import <RSTextDrawing/RSMultiLineRenderer.h>
|
#import <RSTextDrawing/RSMultiLineRenderer.h>
|
||||||
#import <RSTextDrawing/RSMultiLineRendererMeasurements.h>
|
#import <RSTextDrawing/RSMultiLineRendererMeasurements.h>
|
||||||
#import <RSTextDrawing/RSTextRendererProtocol.h>
|
#import <RSTextDrawing/RSTextRendererProtocol.h>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user