OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/clean/chrome/browser/ui/tab_grid/tab_grid_collection_view_layout.h" |
| 6 |
| 7 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 8 #error "This file requires ARC support." |
| 9 #endif |
| 10 |
| 11 namespace { |
| 12 const CGFloat kMinTabWidth = 200.0f; |
| 13 const CGFloat kMaxTabWidth = 250.0f; |
| 14 const CGFloat kInterTabSpacing = 20.0f; |
| 15 const UIEdgeInsets kSectionInset = {20.0f, 20.0f, 20.0f, 20.0f}; |
| 16 } |
| 17 |
| 18 @implementation TabGridCollectionViewLayout |
| 19 |
| 20 #pragma mark - UICollectionViewLayout |
| 21 |
| 22 // This is called whenever the layout is invalidated, including during rotation. |
| 23 - (void)prepareLayout { |
| 24 [super prepareLayout]; |
| 25 [self updateLayoutWithBounds:[[self collectionView] bounds].size]; |
| 26 } |
| 27 |
| 28 #pragma mark - Private |
| 29 |
| 30 // This sets the appropriate itemSize given the bounds of the collection view. |
| 31 - (void)updateLayoutWithBounds:(CGSize)boundsSize { |
| 32 int columns = static_cast<int>(floor(boundsSize.width - kInterTabSpacing) / |
| 33 (kMinTabWidth + kInterTabSpacing)); |
| 34 CGFloat tabWidth = |
| 35 (boundsSize.width - kInterTabSpacing * (columns + 1)) / columns; |
| 36 while (columns < 2 || tabWidth > kMaxTabWidth) { |
| 37 columns++; |
| 38 tabWidth = (boundsSize.width - kInterTabSpacing * (columns + 1)) / columns; |
| 39 } |
| 40 self.itemSize = CGSizeMake(tabWidth, tabWidth); |
| 41 self.sectionInset = kSectionInset; |
| 42 self.minimumLineSpacing = kInterTabSpacing; |
| 43 self.minimumInteritemSpacing = kInterTabSpacing; |
| 44 } |
| 45 |
| 46 @end |
OLD | NEW |