-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrid.h
More file actions
59 lines (45 loc) · 2.26 KB
/
Copy pathGrid.h
File metadata and controls
59 lines (45 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// Grid.h
//
// CS193p Fall 2013
// Copyright (c) 2013 Stanford University.
// All rights reserved.
//
#import <Foundation/Foundation.h>
#import "UIKit/UIKit.h"
// To use Grid, simply alloc/init one, then
// decide what aspect ratio you want the things in the grid to have (cellAspectRatio)
// and how much space you want the grid to take up in total (size)
// then specify what is the minimum number of cells in the grid you require (minimumNumberOfCells)
//
// After you set those three things above, then you can find out where each cell is either by ...
// ... its center (centerOfCellAtRow:inColumn:)
// ... or its frame (frameOfCellAtRow:inColumn:)
//
// You can also find out how many rows (rowCount) or columns (columnCount) are in the grid
// and how big each cell is (they will all be the same size)
//
// inputsAreValid will tell you whether your 3 inputs are okay
//
// Setting minimum cell widths and heights is completely optional ({min,max}Cell{Width,Height})
@interface Grid : NSObject
// required inputs (zero is not a valid value for any of these)
@property (nonatomic) CGSize size; // overall available space to put grid into
@property (nonatomic) CGFloat cellAspectRatio; // width divided by height (of each cell)
@property (nonatomic) NSUInteger minimumNumberOfCells;
// optional inputs (non-positive values are ignored)
@property (nonatomic) CGFloat minCellWidth;
@property (nonatomic) CGFloat maxCellWidth; // ignored if less than minCellWidth
@property (nonatomic) CGFloat minCellHeight;
@property (nonatomic) CGFloat maxCellHeight; // ignored if less than minCellHeight
// calculated outputs (value of NO or 0 or CGSizeZero means "invalid inputs")
@property (nonatomic, readonly) BOOL inputsAreValid; // cells will fit into requested size
@property (nonatomic, readonly) CGSize cellSize; // will be made as large as possible
@property (nonatomic, readonly) NSUInteger rowCount;
@property (nonatomic, readonly) NSUInteger columnCount;
// origin row and column are zero
- (CGPoint)centerOfCellAtRow:(NSUInteger)row inColumn:(NSUInteger)column;
- (CGRect)frameOfCellAtRow:(NSUInteger)row inColumn:(NSUInteger)column;
//Override default init
- (instancetype)initWithMinimumNumberOfCells:(NSInteger)minimumNumberOfCells;
@end