Improved Model
Added Keyboard Selection Support Added Mouse Selection Support Added Keyboard Editing Support Corrected Some Bugs Abstracted the Layout System further Added Functions Button (test)
This commit is contained in:
@@ -7,6 +7,9 @@
|
||||
//
|
||||
|
||||
#import "MPLayout.h"
|
||||
#import "MPRangePath.h"
|
||||
|
||||
#import "NSIndexPath+MPAdditions.h"
|
||||
|
||||
@interface MPLayout ()
|
||||
|
||||
@@ -18,7 +21,7 @@
|
||||
|
||||
@implementation MPLayout {
|
||||
NSMutableArray *_cache;
|
||||
NSSize _cachedSize;
|
||||
NSRect _cachedBounds;
|
||||
}
|
||||
|
||||
#pragma mark Creation Methods
|
||||
@@ -27,13 +30,14 @@
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_cache = [[NSMutableArray alloc] init];
|
||||
_cachedSize = NSZeroSize;
|
||||
_cachedBounds = NSZeroRect;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithPath:(NSIndexPath *)path
|
||||
parent:(MPLayout *)parent
|
||||
- (instancetype)initWithElementAtPath:(NSIndexPath *)path
|
||||
inRootExpression:(MPExpression *)rootExpression
|
||||
parent:(MPLayout *)parent
|
||||
{
|
||||
self = [self init];
|
||||
if (self) {
|
||||
@@ -42,10 +46,37 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma Text System Objects
|
||||
- (MPExpressionStorage *)expressionStorage
|
||||
#pragma mark Properties
|
||||
- (NSFont *)font
|
||||
{
|
||||
return self.parent.expressionStorage;
|
||||
return self.usesSmallSize ? self.smallFont : self.normalFont;
|
||||
}
|
||||
|
||||
- (CGFloat)fontSize
|
||||
{
|
||||
return self.usesSmallSize ? self.smallFontSize : self.normalFontSize;
|
||||
}
|
||||
|
||||
- (NSFont *)normalFont
|
||||
{
|
||||
return [NSFont fontWithName:@"CMU Serif"
|
||||
size:self.fontSize];
|
||||
}
|
||||
|
||||
- (CGFloat)normalFontSize
|
||||
{
|
||||
return 18.0;
|
||||
}
|
||||
|
||||
- (NSFont *)smallFont
|
||||
{
|
||||
return [NSFont fontWithName:@"CMU Serif"
|
||||
size:self.smallFontSize];
|
||||
}
|
||||
|
||||
- (CGFloat)smallFontSize
|
||||
{
|
||||
return 12.0;
|
||||
}
|
||||
|
||||
#pragma mark Cache Tree
|
||||
@@ -92,22 +123,42 @@
|
||||
|
||||
- (void)invalidate
|
||||
{
|
||||
_cachedSize = NSZeroSize;
|
||||
_cachedBounds = NSZeroRect;
|
||||
[self.parent invalidate];
|
||||
}
|
||||
|
||||
#pragma mark Calculation and Drawing Methods
|
||||
- (NSSize)size
|
||||
- (NSRect)bounds
|
||||
{
|
||||
if (NSEqualSizes(_cachedSize, NSZeroSize)) {
|
||||
_cachedSize = [self generateSize];
|
||||
if (NSEqualRects(_cachedBounds, NSZeroRect)) {
|
||||
_cachedBounds = [self generateBounds];
|
||||
}
|
||||
return _cachedSize;
|
||||
return _cachedBounds;
|
||||
}
|
||||
|
||||
- (NSRect)boundingRectForRangePath:(MPRangePath *)rangePath
|
||||
{
|
||||
if (rangePath.location.length == 1) {
|
||||
return [self boundingRectForRange:rangePath.rangeAtLastIndex];
|
||||
}
|
||||
NSUInteger nextIndex = [rangePath.location indexAtPosition:0];
|
||||
NSIndexPath *newLocation = [rangePath.location indexPathByRemovingFirstIndex];
|
||||
MPRangePath *newRangePath = [[MPRangePath alloc] initWithLocation:newLocation length:rangePath.length];
|
||||
NSRect bounds = [[self childLayoutAtIndex:nextIndex] boundingRectForRangePath:newRangePath];
|
||||
NSPoint offset = [self offsetOfChildLayoutAtIndex:nextIndex];
|
||||
bounds.origin = NSMakePoint(bounds.origin.x + offset.x, bounds.origin.y + offset.y);
|
||||
return bounds;
|
||||
}
|
||||
|
||||
- (void)drawAtPoint:(NSPoint)point
|
||||
{
|
||||
|
||||
NSAffineTransform *transform = [NSAffineTransform transform];
|
||||
[transform translateXBy:point.x
|
||||
yBy:point.y];
|
||||
[transform concat];
|
||||
[self draw];
|
||||
[transform invert];
|
||||
[transform concat];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -119,14 +170,24 @@
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSSize)sizeForChildAtIndex:(NSUInteger)index
|
||||
- (NSRect)generateBounds
|
||||
{
|
||||
return NSZeroSize;
|
||||
return NSZeroRect;
|
||||
}
|
||||
|
||||
- (NSSize)generateSize
|
||||
- (NSRect)boundingRectForRange:(NSRange)range
|
||||
{
|
||||
return NSZeroSize;
|
||||
return NSZeroRect;
|
||||
}
|
||||
|
||||
- (NSPoint)offsetOfChildLayoutAtIndex:(NSUInteger)index
|
||||
{
|
||||
return NSZeroPoint;
|
||||
}
|
||||
|
||||
- (void)draw
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user