Archived
1
This repository has been archived on 2022-08-08. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
mathpad/MathPad/MPFunctionLayout.m
2014-08-22 00:54:13 +02:00

90 lines
2.4 KiB
Objective-C

//
// MPFunctionLayout.m
// MathPad
//
// Created by Kim Wittenburg on 07.08.14.
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
//
#import "MPFunctionLayout.h"
#import "MPFunction.h"
#import "MPExpressionLayout.h"
#import "MPSumFunction.h"
#import "MPSumFunctionLayout.h"
@implementation MPFunctionLayout
#pragma mark Creation Methods
+ (MPFunctionLayout *)functionLayoutForFunctionAtIndexPath:(NSIndexPath *)path
parent:(MPExpressionLayout *)parent
{
MPFunction *function = [parent.expressionStorage elementAtIndexPath:path];
Class class = [function class];
if (class == [MPSumFunction class]) {
return [[MPSumFunctionLayout alloc] initWithPath:path parent:parent];
}
return [[self alloc] initWithPath:path parent:parent];
}
- (instancetype)initWithPath:(NSIndexPath *)path
parent:(MPLayout *)parent
{
self = [super initWithPath:path
parent:parent];
if (self) {
_function = [parent.expressionStorage elementAtIndexPath:path];
}
return self;
}
#pragma mark Properties
//- (MPFunction *)function
//{
// return [self.expressionStorage elementAtIndexPath:self.path];
//}
#pragma mark Cache Methods
- (CTLineRef)lineForPrivateCacheIndex:(NSUInteger)index
generator:(CTLineRef (^)())generator
{
NSUInteger actualIndex = self.function.numberOfChildren + index;
id (^actualGenerator)() = ^{
CTLineRef line = generator();
return CFBridgingRelease(line);
};
id lineObject = [self cachableObjectForIndex:actualIndex
generator:actualGenerator];
return (__bridge CTLineRef)(lineObject);
}
- (MPLayout *)childLayoutAtIndex:(NSUInteger)index
{
return [self cachableObjectForIndex:index generator:^id{
NSIndexPath *childPath = [self.function.indexPath indexPathByAddingIndex:index];
MPExpressionLayout *layout = [[MPExpressionLayout alloc] initWithPath:childPath
parent:self];
return layout;
}];
}
#pragma mark Size and Drawing Methods
- (NSSize)sizeForChildAtIndex:(NSUInteger)index
{
MPLayout *childLayout = [self childLayoutAtIndex:index];
return [childLayout size];
}
- (NSSize)generateSize
{
return NSZeroSize;
}
- (void)drawAtPoint:(NSPoint)point
{
}
@end