Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Replaces lots of images with newer/better versions

  • Loading branch information...
commit cebff4a5b5e48ea2553f57d607b062a8dd1e1baf 1 parent df4a3bc
@pieteromvlee pieteromvlee authored
View
29 BCCollectionView+Keyboard.m
@@ -45,7 +45,8 @@ - (void)insertText:(id)aString
- (void)moveLeft:(id)sender
{
NSUInteger index = lastSelectionIndex;
- if (index % [layoutManager numberOfItemsPerRow] != 0) {
+
+ if (index % [layoutManager numberOfItemsAtRow:index] != 0) {
[self deselectAllItems];
NSUInteger newIndex = index-1;
[self selectItemAtIndex:newIndex];
@@ -55,7 +56,7 @@ - (void)moveLeft:(id)sender
- (void)moveLeftAndModifySelection:(id)sender
{
- if (lastSelectionIndex % [layoutManager numberOfItemsPerRow] != 0) {
+ if (lastSelectionIndex % [layoutManager numberOfItemsAtRow:lastSelectionIndex] != 0) {
NSUInteger index = lastSelectionIndex-1;
if ([selectionIndexes containsIndex:index])
[self deselectItemAtIndex:lastSelectionIndex];
@@ -69,7 +70,7 @@ - (void)moveLeftAndModifySelection:(id)sender
- (void)moveRight:(id)sender
{
NSUInteger index = lastSelectionIndex;
- if (index % [layoutManager numberOfItemsPerRow] != [layoutManager numberOfItemsPerRow]-1) {
+ if (index % [layoutManager numberOfItemsAtRow:index] != [layoutManager numberOfItemsAtRow:index]-1) {
[self deselectAllItems];
NSUInteger newIndex = index+1;
[self selectItemAtIndex:newIndex];
@@ -79,7 +80,7 @@ - (void)moveRight:(id)sender
- (void)moveRightAndModifySelection:(id)sender
{
- if (lastSelectionIndex % [layoutManager numberOfItemsPerRow] != [layoutManager numberOfItemsPerRow]-1) {
+ if (lastSelectionIndex % [layoutManager numberOfItemsAtRow:lastSelectionIndex] != [layoutManager numberOfItemsAtRow:lastSelectionIndex]-1) {
NSUInteger index = lastSelectionIndex+1;
if ([selectionIndexes containsIndex:index])
[self deselectItemAtIndex:lastSelectionIndex];
@@ -93,9 +94,9 @@ - (void)moveRightAndModifySelection:(id)sender
- (void)moveUp:(id)sender
{
NSUInteger index = lastSelectionIndex;
- if (index > [layoutManager numberOfItemsPerRow]-1) {
+ if (index > [layoutManager numberOfItemsAtRow:index]-1) {
[self deselectAllItems];
- NSUInteger newIndex = index-[layoutManager numberOfItemsPerRow];
+ NSUInteger newIndex = index-[layoutManager numberOfItemsAtRow:index];
[self selectItemAtIndex:newIndex];
[self scrollRectToVisible:[layoutManager rectOfItemAtIndex:newIndex]];
}
@@ -103,9 +104,9 @@ - (void)moveUp:(id)sender
- (void)moveUpAndModifySelection:(id)sender
{
- if (lastSelectionIndex > [layoutManager numberOfItemsPerRow]-1) {
- NSUInteger index = lastSelectionIndex - [layoutManager numberOfItemsPerRow];
- NSRange range = NSMakeRange(index, [layoutManager numberOfItemsPerRow]);
+ if (lastSelectionIndex > [layoutManager numberOfItemsAtRow:lastSelectionIndex]-1) {
+ NSUInteger index = lastSelectionIndex - [layoutManager numberOfItemsAtRow:lastSelectionIndex];
+ NSRange range = NSMakeRange(index, [layoutManager numberOfItemsAtRow:lastSelectionIndex]);
if ([selectionIndexes containsIndex:index]) {
range.location++;
[self deselectItemsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:range]];
@@ -119,9 +120,9 @@ - (void)moveUpAndModifySelection:(id)sender
- (void)moveDown:(id)sender
{
NSUInteger index = lastSelectionIndex;
- if (index + [layoutManager numberOfItemsPerRow] < [contentArray count]) {
+ if (index + [layoutManager numberOfItemsAtRow:index] < [contentArray count]) {
[self deselectAllItems];
- NSUInteger newIndex = index + [layoutManager numberOfItemsPerRow];
+ NSUInteger newIndex = index + [layoutManager numberOfItemsAtRow:index];
[self selectItemAtIndex:newIndex];
[self scrollRectToVisible:[layoutManager rectOfItemAtIndex:newIndex]];
}
@@ -130,9 +131,9 @@ - (void)moveDown:(id)sender
- (void)moveDownAndModifySelection:(id)sender
{
NSUInteger index = lastSelectionIndex;
- if (index + [layoutManager numberOfItemsPerRow] < [contentArray count]) {
- NSUInteger index = lastSelectionIndex + [layoutManager numberOfItemsPerRow];
- NSRange range = NSMakeRange(lastSelectionIndex, [layoutManager numberOfItemsPerRow]);
+ if (index + [layoutManager numberOfItemsAtRow:index] < [contentArray count]) {
+ NSUInteger index = lastSelectionIndex + [layoutManager numberOfItemsAtRow:index];
+ NSRange range = NSMakeRange(lastSelectionIndex, [layoutManager numberOfItemsAtRow:index]);
if ([selectionIndexes containsIndex:index])
[self deselectItemsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:range]];
else {
View
11 BCCollectionView.m
@@ -428,8 +428,7 @@ - (void)softReloadVisibleViewControllers
- (void)resizeFrameToFitContents
{
NSRect frame = [self frame];
- frame.size.height = [self visibleRect].size.height;
- frame.size.height = MAX(frame.size.height, [layoutManager numberOfRows] * [self cellSize].height);
+ frame.size.height = MAX([self visibleRect].size.height, [layoutManager numberOfRows] * [self cellSize].height);
[self setFrame:frame];
}
@@ -441,6 +440,7 @@ - (void)reloadDataWithItems:(NSArray *)newContent emptyCaches:(BOOL)shouldEmptyC
return;
self.contentArray = newContent;
+ [layoutManager willReload];
[self resizeFrameToFitContents];
if (shouldEmptyCaches) {
@@ -480,8 +480,10 @@ - (void)scrollViewDidScroll:(NSNotification *)note
- (void)viewDidResize
{
+ [layoutManager willReload];
[self resizeFrameToFitContents];
dispatch_async(dispatch_get_main_queue(), ^{
+ [layoutManager willReload];
[self moveViewControllersToProperPosition];
[self addMissingViewControllersToView];
});
@@ -495,4 +497,9 @@ - (NSMenu *)menuForEvent:(NSEvent *)anEvent
return nil;
}
+- (BOOL)isOpaque
+{
+ return YES;
+}
+
@end
View
4 BCCollectionViewLayoutManager.h
@@ -7,12 +7,14 @@
@interface BCCollectionViewLayoutManager : NSObject
{
BCCollectionView *collectionView;
+ NSInteger numberOfRows;
}
- (id)initWithCollectionView:(BCCollectionView *)collectionView; //assigned
+- (void)willReload;
- (NSUInteger)numberOfRows;
-- (NSUInteger)numberOfItemsPerRow;
- (NSUInteger)numberOfItemsAtRow:(NSInteger)rowIndex;
+- (NSUInteger)rowOfItemAtIndex:(NSInteger)anIndex;
- (NSSize)cellSize;
- (NSUInteger)indexOfItemAtPointOrClosestGuess:(NSPoint)p;
View
58 BCCollectionViewLayoutManager.m
@@ -11,23 +11,35 @@ - (id)initWithCollectionView:(BCCollectionView *)aCollectionView
self = [super init];
if (self) {
collectionView = aCollectionView;
+ numberOfRows = -1;
}
return self;
}
-- (NSUInteger)numberOfRows
+- (void)willReload
{
- return MAX(1, ceil((float)[[collectionView contentArray] count]/(float)[self numberOfItemsPerRow]));
+ numberOfRows = -1;
}
-- (NSUInteger)numberOfItemsPerRow
+#pragma mark -
+#pragma mark Primitives
+
+- (NSUInteger)numberOfRows
{
- return MAX(1, NSWidth([collectionView frame])/[self cellSize].width);
+ if (numberOfRows == -1) {
+ NSInteger leftOver = [[collectionView contentArray] count];
+ numberOfRows = 0;
+ while (leftOver > 0) {
+ leftOver -= [self numberOfItemsAtRow:numberOfRows];
+ numberOfRows++;
+ }
+ }
+ return numberOfRows;
}
- (NSUInteger)numberOfItemsAtRow:(NSInteger)rowIndex
{
- return [self numberOfItemsPerRow];
+ return MAX(1, [collectionView frame].size.width/[self cellSize].width);
}
- (NSSize)cellSize
@@ -35,9 +47,27 @@ - (NSSize)cellSize
return [collectionView cellSize];
}
+
+- (NSUInteger)rowOfItemAtIndex:(NSInteger)anIndex
+{
+ NSInteger rowIndex = 0;
+ while (anIndex >= [self numberOfItemsAtRow:rowIndex]) {
+ anIndex -= [self numberOfItemsAtRow:rowIndex];
+ rowIndex++;
+ }
+ return rowIndex;
+}
+
- (NSUInteger)indexOfItemAtPointOrClosestGuess:(NSPoint)p
{
- NSUInteger index = (int)(p.y / [self cellSize].height) * [self numberOfItemsPerRow] + p.x / [self cellSize].width;
+ NSUInteger rowIndex = (int)p.y / [self cellSize].height;
+
+ NSInteger rowFirstIndex = 0;
+ for (NSInteger i=0; i<rowIndex; i++)
+ rowFirstIndex += [self numberOfItemsAtRow:i];
+
+ NSInteger gap = (NSWidth([collectionView visibleRect])-[self numberOfItemsAtRow:rowIndex]*[self cellSize].width)/([self numberOfItemsAtRow:rowIndex]-1);
+ NSUInteger index = rowFirstIndex + MIN([self numberOfItemsAtRow:rowIndex]-1, p.x / ([self cellSize].width+gap));
if (index >= [[collectionView contentArray] count])
return NSNotFound;
else
@@ -46,7 +76,9 @@ - (NSUInteger)indexOfItemAtPointOrClosestGuess:(NSPoint)p
- (NSUInteger)indexOfItemAtPoint:(NSPoint)p
{
- if (p.x > [self cellSize].width * [self numberOfItemsPerRow])
+ NSUInteger rowIndex = (int)p.y / [self cellSize].height;
+ NSInteger gap = (NSWidth([collectionView visibleRect])-[self numberOfItemsAtRow:rowIndex]*[self cellSize].width)/([self numberOfItemsAtRow:rowIndex]-1);
+ if (p.x > ([self cellSize].width+gap) * [self numberOfItemsAtRow:rowIndex])
return NSNotFound;
return [self indexOfItemAtPointOrClosestGuess:p];
@@ -67,9 +99,14 @@ - (NSUInteger)indexOfItemContentRectAtPoint:(NSPoint)p
- (NSRect)rectOfItemAtIndex:(NSUInteger)anIndex
{
NSSize cellSize = [self cellSize];
- NSUInteger rowIndex = anIndex / [self numberOfItemsPerRow];
- NSUInteger columnIndex = anIndex % [self numberOfItemsPerRow];
- NSInteger gap = (NSWidth([collectionView visibleRect])-[self numberOfItemsPerRow]*cellSize.width)/([self numberOfItemsPerRow]-1);
+
+ NSInteger rowIndex = 0;
+ NSInteger columnIndex = anIndex;
+ while (columnIndex >= [self numberOfItemsAtRow:rowIndex]) {
+ columnIndex -= [self numberOfItemsAtRow:rowIndex];
+ rowIndex++;
+ }
+ NSInteger gap = (NSWidth([collectionView visibleRect])-[self numberOfItemsAtRow:rowIndex]*cellSize.width)/([self numberOfItemsAtRow:rowIndex]-1);
return NSMakeRect(columnIndex*(cellSize.width+gap), rowIndex*cellSize.height, cellSize.width, cellSize.height);
}
@@ -82,5 +119,4 @@ - (NSRect)contentRectOfItemAtIndex:(NSUInteger)anIndex
} else
return rect;
}
-
@end
Please sign in to comment.
Something went wrong with that request. Please try again.