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/MPPowerFunctionLayout.m
Kim Wittenburg 82259f87e2 Model Redesign: Added Reference Frames
Added Inverse Functions
UI Redesign
Cleaned Code
2014-10-07 20:25:54 +02:00

69 lines
1.8 KiB
Objective-C

//
// MPPowerFunctionLayout.m
// MathPad
//
// Created by Kim Wittenburg on 30.09.14.
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
//
#import "MPPowerFunctionLayout.h"
#define kMPEmptyBoxHeight (CTFontGetDescent((CTFontRef)self.font) + CTFontGetAscent((CTFontRef)self.font) + CTFontGetLeading((CTFontRef)self.font))
#define kMPEmptyBoxYOrigin (-(CTFontGetDescent((CTFontRef)self.font) + CTFontGetLeading((CTFontRef)self.font)))
#define kPowerFunctionExponentXOffset 1
#define kPowerFunctionTrailingOffset 2
@implementation MPPowerFunctionLayout
- (NSRect)baseBounds
{
if (NSEqualRects(_baseBounds, NSZeroRect)) {
return NSMakeRect(0, kMPEmptyBoxYOrigin, 0, kMPEmptyBoxHeight);
}
return _baseBounds;
}
- (MPPowerFunction *)powerFunction
{
return (MPPowerFunction *)self.function;
}
- (NSIndexSet *)indexesOfRemainingChildren
{
return [NSIndexSet indexSetWithIndex:0];
}
- (NSPoint)offsetOfChildLayoutAtIndex:(NSUInteger)index
{
CGFloat y = self.baseBounds.size.height / 2;
return NSMakePoint(kPowerFunctionExponentXOffset, y);
}
- (BOOL)childAtIndexUsesSmallSize:(NSUInteger)index
{
return YES;
}
- (NSIndexPath *)indexPathForLocalMousePoint:(NSPoint)point
{
return [[NSIndexPath indexPathWithIndex:0] indexPathByAddingIndex:0];
}
- (NSRect)generateBounds
{
NSRect exponentBounds = [self childLayoutAtIndex:0].bounds;
CGFloat y = self.baseBounds.origin.y;
CGFloat height = -y + [self offsetOfChildLayoutAtIndex:0].y + exponentBounds.size.height + exponentBounds.origin.y;
CGFloat width = kPowerFunctionExponentXOffset + exponentBounds.size.width + kPowerFunctionTrailingOffset;
return NSMakeRect(0, y, width, height);
}
- (void)draw
{
MPLayout *exponentLayout = [self childLayoutAtIndex:0];
[exponentLayout drawAtPoint:[self offsetOfChildLayoutAtIndex:0]];
}
@end