Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/catlan/AQGridView into edit…
Browse files Browse the repository at this point in the history
…ing-support

* 'master' of git://github.com/catlan/AQGridView:
  add editing support
  add indexForCell
  FIX: gridView isn't scrollable when the number of items fits into its view area
  FIX: gridView isn't scrollable when the number of items fits in the viewable area
  add selectionGlowShadowRadius property
  • Loading branch information
AlanQuatermain committed Jan 13, 2011
2 parents 502793c + f64a8f6 commit ad02112
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Classes/AQGridView.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ typedef enum {

- (CGRect) gridView: (AQGridView *) gridView adjustCellFrame: (CGRect) cellFrame withinGridCellFrame: (CGRect) gridCellFrame;

// Editing
- (void)gridView:(AQGridView *)aGridView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndex:(NSUInteger)index;

@end

extern NSString * const AQGridViewSelectionDidChangeNotification;
Expand Down Expand Up @@ -151,6 +154,8 @@ extern NSString * const AQGridViewSelectionDidChangeNotification;

unsigned dataSourceGridCellSize:1;

unsigned int isEditing:1;

unsigned __RESERVED__:1;
} _flags;
}
Expand Down Expand Up @@ -236,6 +241,11 @@ extern NSString * const AQGridViewSelectionDidChangeNotification;

@property (nonatomic, readonly) BOOL isAnimatingUpdates;

// Editing

@property(nonatomic,getter=isEditing) BOOL editing; // default is NO. setting is not animated.
- (void)setEditing:(BOOL)editing animated:(BOOL)animated;

@end

@protocol AQGridViewDataSource <NSObject>
Expand Down
21 changes: 21 additions & 0 deletions Classes/AQGridView.m
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,16 @@ - (void) setBounds: (CGRect) bounds
[self handleGridViewBoundsChanged: oldBounds toNewBounds: bounds];
}

- (BOOL) isEditing
{
return ( _flags.isEditing == 1 );
}

- (void) setEditing: (BOOL) value
{
[self setEditing:value animated:NO];
}

#pragma mark -
#pragma mark Data Management

Expand Down Expand Up @@ -993,6 +1003,16 @@ - (void) moveItemAtIndex: (NSUInteger) index toIndex: (NSUInteger) newIndex with
[self endUpdateAnimations];
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
_flags.isEditing = (editing ? 1 : 0);

NSArray *visibleCells = [self visibleCells];
for (AQGridViewCell *aCell in visibleCells) {
[aCell setEditing:editing animated:animated];
}
}

#pragma mark -
#pragma mark Selection

Expand Down Expand Up @@ -2036,6 +2056,7 @@ - (AQGridViewCell *) createPreparedCellForIndex: (NSUInteger) index usingGridDat
[UIView setAnimationsEnabled: NO];
AQGridViewCell * cell = [_dataSource gridView: self cellForItemAtIndex: index];
cell.separatorStyle = _flags.separatorStyle;
cell.editing = self.editing;
cell.displayIndex = index;

cell.frame = [self fixCellFrame: cell.frame forGridRect: [gridData cellRectAtIndex: index]];
Expand Down
8 changes: 7 additions & 1 deletion Classes/AQGridViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ typedef enum {
unsigned int highlighted:1;
unsigned int becomingHighlighted:1;
unsigned int setShadowPath:1;
unsigned int editing:1;
unsigned int hiddenForAnimation:1;
unsigned int __RESERVED__:15;
unsigned int __RESERVED__:14;
} _cellFlags;
}

Expand Down Expand Up @@ -115,4 +116,9 @@ typedef enum {
- (void) setSelected: (BOOL) selected animated: (BOOL) animated;
- (void) setHighlighted: (BOOL) highlighted animated: (BOOL) animated;

// Editing

@property(nonatomic,getter=isEditing) BOOL editing; // show appropriate edit controls (+/- & reorder). By default -setEditing: calls setEditing:animated: with NO for animated.
- (void)setEditing:(BOOL)editing animated:(BOOL)animated;

@end
15 changes: 15 additions & 0 deletions Classes/AQGridViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,21 @@ - (void) prepareForReuse
_cellFlags.setShadowPath = 0;
}

- (BOOL) isEditing
{
return ( _cellFlags.editing == 1 );
}

- (void) setEditing: (BOOL) value
{
[self setEditing:value animated:NO];
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
_cellFlags.editing = (editing ? 1 : 0);
}

@end

@implementation AQGridViewCell (AQGridViewCellPrivate)
Expand Down

0 comments on commit ad02112

Please sign in to comment.