Skip to content

Commit

Permalink
macosx: Further extract collection view item size calculation to own …
Browse files Browse the repository at this point in the history
…method

Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra authored and fkuehne committed Dec 25, 2022
1 parent 926f07f commit d2de90c
Showing 1 changed file with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -721,26 +721,30 @@ - (NSSize)collectionView:(NSCollectionView *)collectionView
{
if (collectionViewLayout == _collectionViewFlowLayout &&
collectionView == _collectionView) {
return [self adjustedCollectionViewItemSize];
}

static const CGFloat maxItemWidth = 280;
static const CGFloat minItemWidth = 180;
return NSZeroSize;
}

static uint numItemsInRow = 5;
- (NSSize)adjustedCollectionViewItemSize
{
static const CGFloat maxItemWidth = 280;
static const CGFloat minItemWidth = 180;

NSSize itemSize = [self collectionViewItemSizeForNumberOfItemsInRow:numItemsInRow];
while (itemSize.width > maxItemWidth) {
++numItemsInRow;
itemSize = [self collectionViewItemSizeForNumberOfItemsInRow:numItemsInRow];
}
while (itemSize.width < minItemWidth) {
--numItemsInRow;
itemSize = [self collectionViewItemSizeForNumberOfItemsInRow:numItemsInRow];
}
static uint numItemsInRow = 5;

return itemSize;
NSSize itemSize = [self collectionViewItemSizeForNumberOfItemsInRow:numItemsInRow];
while (itemSize.width > maxItemWidth) {
++numItemsInRow;
itemSize = [self collectionViewItemSizeForNumberOfItemsInRow:numItemsInRow];
}
while (itemSize.width < minItemWidth) {
--numItemsInRow;
itemSize = [self collectionViewItemSizeForNumberOfItemsInRow:numItemsInRow];
}

return NSZeroSize;
return itemSize;
}

- (NSSize)collectionViewItemSizeForNumberOfItemsInRow:(uint)numItemsInRow
Expand Down

0 comments on commit d2de90c

Please sign in to comment.