Archived
1

Some small corrections

Added example expression (hardcoded for development)
Added example change for expressions (hardcoded for development)
This commit is contained in:
Kim Wittenburg
2014-05-18 01:10:50 +02:00
parent 982b70d7fb
commit 740c3fd80a
8 changed files with 72 additions and 11 deletions

View File

@@ -10,6 +10,7 @@
#import "MPExpressionStorage.h"
#import "MPFunctionLayout.h"
#import "MPModel.h"
#import "MPExpressionView.h"
@implementation MPExpressionLayout
@@ -71,15 +72,20 @@
#pragma mark Cache Methods
// TODO: Return nil from caching with illegal index
- (void)invalidate
{
_valid = NO;
[self.parent invalidate];
[self.expressionView setNeedsDisplay:YES];
}
- (void)expressionEditedInRange:(NSRange)range replacementLength:(NSUInteger)length
- (void)editedExpressionInRange:(NSRange)range replacementLength:(NSUInteger)length
{
while (_symbolCache.count < self.expression.numberOfSymbols) {
// TODO: New symbols may also be inserted in the middle or at the beginning
NSInteger changeInLength = length - range.length;
while (_symbolCache.count < (self.expression.numberOfSymbols + changeInLength)) {
[_symbolCache addObject:[NSNull null]];
}
NSMutableArray *newPlaceholders = [[NSMutableArray alloc] initWithCapacity:length];
@@ -101,7 +107,11 @@
- (MPFunctionLayout *)functionLayoutForFunctionAtIndex:(NSUInteger)index;
{
if ([self hasCacheForSymbolAtIndex:index]) {
return _symbolCache[index];
id cacheObject = _symbolCache[index];
if ([cacheObject isKindOfClass:[NSValue class]]) {
return nil;
}
return cacheObject;
}
MPFunctionLayout *layout = [MPFunctionLayout functionLayoutForFunctionAtIndexPath:[self.expressionPath indexPathByAddingIndex:index] parent:self];
while (index >= _symbolCache.count) {
@@ -177,6 +187,8 @@
atPoint:(NSPoint)point
{
id symbol = [self.expression symbolAtIndex:index];
// point.x = point.y = 0;
NSLog(@"draw Symbol: %@ at Point: (x: %f, y: %f)", symbol, point.x, point.y);
if ([symbol isString]) {
[self.textStorage setString:symbol];
NSRange glyphRange = [self.layoutManager glyphRangeForTextContainer:self.textContainer];
@@ -184,6 +196,7 @@
atPoint:point];
} else {
MPFunctionLayout *layout = [self functionLayoutForFunctionAtIndex:index];
NSLog(@"layout: %@, index: %ld", layout, index);
[layout drawFunctionAtPoint:point];
}
}