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/MPFractionFunctionLayout.m
Kim Wittenburg 91e7dbe9f2 Cleaned Code
2014-10-21 15:06:57 +02:00

88 lines
2.5 KiB
Objective-C

//
// MPFractionFunctionLayout.m
// MathPad
//
// Created by Kim Wittenburg on 07.10.14.
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
//
#import "MPFractionFunctionLayout.h"
#import "MPExpressionLayout.h"
#define kFractionFunctionLineWidth 1.0
#define kFractionFunctionHorizontalInset 2.0
#define kFractionFunctionNominatorOffset 0
#define kFractionFunctionDenominatorOffset 0
#define MPFractionMiddle (CTFontGetCapHeight((CTFontRef)self.font) / 2)
@implementation MPFractionFunctionLayout
- (MPFractionFunction *)fractionFunction
{
return (MPFractionFunction *)self.function;
}
- (NSUInteger)indexOfChildBelowChildAtIndex:(NSUInteger)index
{
return 1;
}
- (NSUInteger)indexOfChildAboveChildAtIndex:(NSUInteger)index
{
return 0;
}
- (NSIndexSet *)indexesOfRemainingChildren
{
return [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)];
}
- (NSPoint)offsetOfChildLayoutAtIndex:(NSUInteger)index
{
if (index == 0) {
NSRect nominatorBounds = [self childLayoutAtIndex:0].bounds;
CGFloat y = MPFractionMiddle + kFractionFunctionLineWidth / 2 - nominatorBounds.origin.y;
return NSMakePoint(kFractionFunctionHorizontalInset, y);
} else {
NSRect denominatorBounds = [self childLayoutAtIndex:1].bounds;
CGFloat y = MPFractionMiddle - kFractionFunctionLineWidth / 2;
y -= denominatorBounds.size.height + denominatorBounds.origin.y;
return NSMakePoint(kFractionFunctionHorizontalInset, y);
}
}
- (BOOL)childAtIndexUsesSmallSize:(NSUInteger)index
{
return YES;
}
- (NSIndexPath *)indexPathForLocalMousePoint:(NSPoint)point
{
if (point.x < self.bounds.size.width / 2) {
return [NSIndexPath indexPathWithIndex:0];
} else {
return [NSIndexPath indexPathWithIndex:1];
}
}
- (NSRect)generateBounds
{
NSRect nominatorBounds = [self childLayoutAtIndex:0].bounds;
NSRect denominatorBounds = [self childLayoutAtIndex:1].bounds;
NSRect bounds;
bounds.origin.x = 0;
bounds.origin.y = MPFractionMiddle - kFractionFunctionLineWidth / 2 - denominatorBounds.size.height;
bounds.size.width = MAX(nominatorBounds.size.width, denominatorBounds.size.width) + 2 * kFractionFunctionHorizontalInset;
bounds.size.height = nominatorBounds.size.height + denominatorBounds.size.height + kFractionFunctionLineWidth;
return bounds;
}
- (void)draw
{
CGFloat y = MPFractionMiddle - kFractionFunctionLineWidth / 2;
NSRectFill(NSMakeRect(0, y, self.bounds.size.width, kFractionFunctionLineWidth));
}
@end