Some small corrections
Added example expression (hardcoded for development) Added example change for expressions (hardcoded for development)
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13C64" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13C1021" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/>
|
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@@ -31,6 +31,17 @@
|
|||||||
<rect key="frame" x="20" y="20" width="467" height="96"/>
|
<rect key="frame" x="20" y="20" width="467" height="96"/>
|
||||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||||
</customView>
|
</customView>
|
||||||
|
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="IMg-L0-qdu">
|
||||||
|
<rect key="frame" x="405" y="-7" width="88" height="32"/>
|
||||||
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||||
|
<buttonCell key="cell" type="push" title="Change" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Xxz-j2-fsI">
|
||||||
|
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||||
|
<font key="font" metaFont="system"/>
|
||||||
|
</buttonCell>
|
||||||
|
<connections>
|
||||||
|
<action selector="changeExpression:" target="-2" id="k8U-3Y-8Ch"/>
|
||||||
|
</connections>
|
||||||
|
</button>
|
||||||
</subviews>
|
</subviews>
|
||||||
<constraints>
|
<constraints>
|
||||||
<constraint firstItem="lcd-Ip-jjR" firstAttribute="top" secondItem="fqc-IQ-ceJ" secondAttribute="bottom" constant="8" symbolic="YES" id="GTC-QI-4wc"/>
|
<constraint firstItem="lcd-Ip-jjR" firstAttribute="top" secondItem="fqc-IQ-ceJ" secondAttribute="bottom" constant="8" symbolic="YES" id="GTC-QI-4wc"/>
|
||||||
|
|||||||
@@ -13,4 +13,6 @@
|
|||||||
@property (weak) IBOutlet MPExpressionView *termExpressionView;
|
@property (weak) IBOutlet MPExpressionView *termExpressionView;
|
||||||
@property (weak) IBOutlet MPExpressionView *resultExpressionView;
|
@property (weak) IBOutlet MPExpressionView *resultExpressionView;
|
||||||
|
|
||||||
|
- (IBAction)changeExpression:(id)sender;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -58,4 +58,10 @@
|
|||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark Actions
|
||||||
|
|
||||||
|
- (IBAction)changeExpression:(id)sender {
|
||||||
|
[self.resultExpressionView.expressionStorage insertString:@"abc" atIndex:6];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
@class MPExpressionLayout, MPFunctionLayout, MPExpressionStorage, MPExpression;
|
@class MPExpressionLayout, MPFunctionLayout, MPExpressionStorage, MPExpressionView, MPExpression;
|
||||||
|
|
||||||
@interface MPExpressionLayout : NSObject {
|
@interface MPExpressionLayout : NSObject {
|
||||||
BOOL _valid;
|
BOOL _valid;
|
||||||
@@ -30,6 +30,8 @@
|
|||||||
@property (readonly, nonatomic, weak) MPExpressionStorage *expressionStorage;
|
@property (readonly, nonatomic, weak) MPExpressionStorage *expressionStorage;
|
||||||
@property (readonly, nonatomic, strong) NSIndexPath *expressionPath;
|
@property (readonly, nonatomic, strong) NSIndexPath *expressionPath;
|
||||||
|
|
||||||
|
@property (nonatomic, weak) MPExpressionView *expressionView;
|
||||||
|
|
||||||
- (MPExpression *)expression; // Convenience
|
- (MPExpression *)expression; // Convenience
|
||||||
- (NSLayoutManager *)layoutManager;
|
- (NSLayoutManager *)layoutManager;
|
||||||
- (NSTextContainer *)textContainer;
|
- (NSTextContainer *)textContainer;
|
||||||
@@ -38,7 +40,7 @@
|
|||||||
#pragma mark Cache Methods
|
#pragma mark Cache Methods
|
||||||
|
|
||||||
- (void)invalidate;
|
- (void)invalidate;
|
||||||
- (void)expressionEditedInRange:(NSRange)range
|
- (void)editedExpressionInRange:(NSRange)range
|
||||||
replacementLength:(NSUInteger)length;
|
replacementLength:(NSUInteger)length;
|
||||||
|
|
||||||
- (BOOL)hasCacheForSymbolAtIndex:(NSUInteger)index;
|
- (BOOL)hasCacheForSymbolAtIndex:(NSUInteger)index;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#import "MPExpressionStorage.h"
|
#import "MPExpressionStorage.h"
|
||||||
#import "MPFunctionLayout.h"
|
#import "MPFunctionLayout.h"
|
||||||
#import "MPModel.h"
|
#import "MPModel.h"
|
||||||
|
#import "MPExpressionView.h"
|
||||||
|
|
||||||
@implementation MPExpressionLayout
|
@implementation MPExpressionLayout
|
||||||
|
|
||||||
@@ -71,15 +72,20 @@
|
|||||||
|
|
||||||
#pragma mark Cache Methods
|
#pragma mark Cache Methods
|
||||||
|
|
||||||
|
// TODO: Return nil from caching with illegal index
|
||||||
|
|
||||||
- (void)invalidate
|
- (void)invalidate
|
||||||
{
|
{
|
||||||
_valid = NO;
|
_valid = NO;
|
||||||
[self.parent invalidate];
|
[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]];
|
[_symbolCache addObject:[NSNull null]];
|
||||||
}
|
}
|
||||||
NSMutableArray *newPlaceholders = [[NSMutableArray alloc] initWithCapacity:length];
|
NSMutableArray *newPlaceholders = [[NSMutableArray alloc] initWithCapacity:length];
|
||||||
@@ -101,7 +107,11 @@
|
|||||||
- (MPFunctionLayout *)functionLayoutForFunctionAtIndex:(NSUInteger)index;
|
- (MPFunctionLayout *)functionLayoutForFunctionAtIndex:(NSUInteger)index;
|
||||||
{
|
{
|
||||||
if ([self hasCacheForSymbolAtIndex: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];
|
MPFunctionLayout *layout = [MPFunctionLayout functionLayoutForFunctionAtIndexPath:[self.expressionPath indexPathByAddingIndex:index] parent:self];
|
||||||
while (index >= _symbolCache.count) {
|
while (index >= _symbolCache.count) {
|
||||||
@@ -177,6 +187,8 @@
|
|||||||
atPoint:(NSPoint)point
|
atPoint:(NSPoint)point
|
||||||
{
|
{
|
||||||
id symbol = [self.expression symbolAtIndex:index];
|
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]) {
|
if ([symbol isString]) {
|
||||||
[self.textStorage setString:symbol];
|
[self.textStorage setString:symbol];
|
||||||
NSRange glyphRange = [self.layoutManager glyphRangeForTextContainer:self.textContainer];
|
NSRange glyphRange = [self.layoutManager glyphRangeForTextContainer:self.textContainer];
|
||||||
@@ -184,6 +196,7 @@
|
|||||||
atPoint:point];
|
atPoint:point];
|
||||||
} else {
|
} else {
|
||||||
MPFunctionLayout *layout = [self functionLayoutForFunctionAtIndex:index];
|
MPFunctionLayout *layout = [self functionLayoutForFunctionAtIndex:index];
|
||||||
|
NSLog(@"layout: %@, index: %ld", layout, index);
|
||||||
[layout drawFunctionAtPoint:point];
|
[layout drawFunctionAtPoint:point];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
#import "MPExpressionStorage.h"
|
#import "MPExpressionStorage.h"
|
||||||
#import "MPExpressionLayout.h"
|
#import "MPExpressionLayout.h"
|
||||||
|
#import "MPFunctionLayout.h"
|
||||||
|
#import "MPRangePath.h"
|
||||||
|
|
||||||
@interface MPExpressionStorage ()
|
@interface MPExpressionStorage ()
|
||||||
@property (nonatomic, strong) NSLayoutManager *layoutManager;
|
@property (nonatomic, strong) NSLayoutManager *layoutManager;
|
||||||
@@ -57,4 +59,24 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)symbolsChangedInRangePath:(MPRangePath *)rangePath replacementLength:(NSUInteger)length
|
||||||
|
{
|
||||||
|
if (rangePath.location.length == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
id current = self.expressionLayout;
|
||||||
|
for (NSUInteger position = 1; position < rangePath.location.length-1; position++) {
|
||||||
|
if ([current isKindOfClass:[MPExpressionLayout class]]) {
|
||||||
|
current = [(MPExpressionLayout *)current functionLayoutForFunctionAtIndex:position];
|
||||||
|
} else {
|
||||||
|
current = [(MPFunctionLayout *)current expressionLayoutForChildAtIndex:position];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ([current isKindOfClass:[MPExpressionLayout class]]) {
|
||||||
|
[(MPExpressionLayout *)current editedExpressionInRange:rangePath.rangeAtLastIndex replacementLength:length];
|
||||||
|
} else {
|
||||||
|
[(MPFunctionLayout *)current editedChildAtIndex:[rangePath.location indexAtPosition:rangePath.location.length-1]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#pragma mark Properties
|
#pragma mark Properties
|
||||||
|
|
||||||
@property (readonly, nonatomic, copy) MPExpressionStorage *expressionStorage;
|
@property (readonly, nonatomic, strong) MPExpressionStorage *expressionStorage;
|
||||||
- (MPExpressionLayout *)expressionLayout; // Convenience Method
|
- (MPExpressionLayout *)expressionLayout; // Convenience Method
|
||||||
|
|
||||||
@property (nonatomic, getter = isEditable) BOOL editable;
|
@property (nonatomic, getter = isEditable) BOOL editable;
|
||||||
|
|||||||
@@ -14,9 +14,6 @@
|
|||||||
|
|
||||||
#import "MPSumFunction.h"
|
#import "MPSumFunction.h"
|
||||||
|
|
||||||
@interface MPExpressionView ()
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation MPExpressionView
|
@implementation MPExpressionView
|
||||||
|
|
||||||
#pragma mark Creation Methods
|
#pragma mark Creation Methods
|
||||||
@@ -50,12 +47,20 @@
|
|||||||
|
|
||||||
- (void)initializeObjects
|
- (void)initializeObjects
|
||||||
{
|
{
|
||||||
MPExpressionStorage *expressionStorage = [[MPExpressionStorage alloc] initWithSymbols:@[@"12345", [[MPSumFunction alloc] init]]];
|
MPExpressionStorage *expressionStorage = [[MPExpressionStorage alloc] initWithSymbols:@[@"12 345", [[MPSumFunction alloc] init], [[MPSumFunction alloc] init]]];
|
||||||
_expressionStorage = expressionStorage;
|
_expressionStorage = expressionStorage;
|
||||||
|
[self.expressionLayout setExpressionView:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark Properties
|
#pragma mark Properties
|
||||||
|
|
||||||
|
- (void)setExpressionStorage:(MPExpressionStorage *)expressionStorage
|
||||||
|
{
|
||||||
|
[_expressionStorage.expressionLayout setExpressionView:nil];
|
||||||
|
_expressionStorage = expressionStorage;
|
||||||
|
[_expressionStorage.expressionLayout setExpressionView:self];
|
||||||
|
}
|
||||||
|
|
||||||
- (MPExpressionLayout *)expressionLayout
|
- (MPExpressionLayout *)expressionLayout
|
||||||
{
|
{
|
||||||
return self.expressionStorage.expressionLayout;
|
return self.expressionStorage.expressionLayout;
|
||||||
|
|||||||
Reference in New Issue
Block a user