Archived
1

Internal Redesign:

- Combined MPExpression and MPMutableExpression
- Abstracted children of MPExpression into MPExpressionElement protocol
- Abstracted most of MPExpressionLayout and MPFunctionLayout into common superclass MPLayout
This commit is contained in:
Kim Wittenburg
2014-08-11 13:57:48 +02:00
parent 740c3fd80a
commit 60760b8b3d
31 changed files with 1222 additions and 1343 deletions

View File

@@ -2,14 +2,13 @@
// MPFunctionLayout.m
// MathPad
//
// Created by Kim Wittenburg on 22.04.14.
// Created by Kim Wittenburg on 07.08.14.
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
//
#import "MPFunctionLayout.h"
#import "MPExpressionLayout.h"
#import "MPExpressionStorage.h"
#import "MPFunction.h"
#import "MPExpressionLayout.h"
#import "MPSumFunction.h"
#import "MPSumFunctionLayout.h"
@@ -17,114 +16,43 @@
@implementation MPFunctionLayout
#pragma mark Creation Methods
+ (instancetype)functionLayoutForFunctionAtIndexPath:(NSIndexPath *)functionPath
parent:(MPExpressionLayout *)parent
+ (MPFunctionLayout *)functionLayoutForFunctionAtIndexPath:(NSIndexPath *)path
parent:(MPExpressionLayout *)parent
{
MPFunction *function = [parent.expressionStorage symbolAtIndexPath:functionPath];
MPFunction *function = [parent.expressionStorage elementAtIndexPath:path];
Class class = [function class];
if (class == [MPSumFunction class]) {
return [[MPSumFunctionLayout alloc] initWithFunctionPath:functionPath parent:parent];
return [[MPSumFunctionLayout alloc] initWithPath:path parent:parent];
}
return nil;
}
- (id)initWithFunctionPath:(NSIndexPath *)functionPath
parent:(MPExpressionLayout *)parent
{
self = [super init];
if (self) {
_functionPath = functionPath;
_parent = parent;
_childCache = [[NSMutableArray alloc] init];
}
return self;
return [[self alloc] initWithPath:path parent:parent];
}
#pragma mark Properties
- (MPExpressionStorage *)expressionStorage
{
return self.parent.expressionStorage;
}
- (MPFunction *)function
{
return [self.expressionStorage symbolAtIndexPath:self.functionPath];
}
- (NSLayoutManager *)layoutManager
{
return self.expressionStorage.layoutManager;
}
- (NSTextContainer *)textContainer
{
return self.expressionStorage.textContainer;
}
- (NSTextStorage *)textStorage
{
return self.expressionStorage.textStorage;
return [self.expressionStorage elementAtIndexPath:self.path];
}
#pragma mark Cache Methods
- (void)invalidate
- (MPLayout *)childLayoutAtIndex:(NSUInteger)index
{
_valid = NO;
[self.parent invalidate];
return [self cachableObjectForIndex:index generator:^id{
NSIndexPath *childPath = [self.path indexPathByAddingIndex:index];
MPExpressionLayout *layout = [[MPExpressionLayout alloc] initWithPath:childPath
parent:self];
return layout;
}];
}
- (void)editedChildAtIndex:(NSUInteger)index
- (NSSize)sizeForChildAtIndex:(NSUInteger)index
{
if ([self hasCacheForChildAtIndex:index]) {
_childCache[index] = [NSNull null];
}
[self invalidate];
MPLayout *childLayout = [self childLayoutAtIndex:index];
return [childLayout size];
}
- (BOOL)hasCacheForChildAtIndex:(NSUInteger)index
{
if (index >= _childCache.count) {
return NO;
}
return _childCache[index] != [NSNull null];
}
- (MPExpressionLayout *)expressionLayoutForChildAtIndex:(NSUInteger)index
{
if ([self hasCacheForChildAtIndex:index]) {
return _childCache[index];
}
while (index >= _childCache.count) {
[_childCache addObject:[NSNull null]];
}
MPExpressionLayout *expressionLayout = [[MPExpressionLayout alloc] initWithExpressionPath:[self.functionPath indexPathByAddingIndex:index] parent:self];
_childCache[index] = expressionLayout;
return expressionLayout;
}
#pragma mark Size Calculation Methods
- (NSSize)sizeOfFunction
{
if (!_valid) {
_cachedSize = [self calculateSize];
_valid = YES;
}
return _cachedSize;
}
- (NSSize)calculateSize
{
return NSMakeSize(0, 0);
}
#pragma mark Drawing Methods
- (void)drawFunctionAtPoint:(NSPoint)point
- (NSBezierPath *)generateBezierPath
{
return [NSBezierPath bezierPath];
}
@end