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
Kim Wittenburg 4a3ea0cede 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)
2014-08-31 15:41:17 +02:00

87 lines
2.8 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
inRootExpression:(MPExpression *)rootExpression
parent:(MPExpressionLayout *)parent
{
MPFunction *function = [rootExpression elementAtIndexPath:path];
Class class = [function class];
if (class == [MPSumFunction class]) {
return [[MPSumFunctionLayout alloc] initWithElementAtPath:path
inRootExpression:rootExpression
parent:parent];
}
return [[self alloc] initWithElementAtPath:path
inRootExpression:rootExpression
parent:parent];
}
- (instancetype)initWithElementAtPath:(NSIndexPath *)path
inRootExpression:(MPExpression *)rootExpression
parent:(MPLayout *)parent
{
self = [super initWithElementAtPath:path
inRootExpression:rootExpression
parent:parent];
if (self) {
_function = [rootExpression elementAtIndexPath:path];
}
return self;
}
#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] initWithElementAtPath:childPath
inRootExpression:self.function.rootExpression
parent:self];
layout.flipped = self.flipped;
layout.usesSmallSize = (index == 0 || index == 1) ? YES : self.usesSmallSize;
return layout;
}];
}
#pragma mark Size and Drawing Methods
- (NSRect)generateBounds
{
return NSZeroRect;
}
- (void)draw
{
}
@end