<commit_before>//
//  ColumnFlowLayout.swift
//  AlliCrab
//
//  Copyright © 2019 <NAME>. All rights reserved.
//

import os
import UIKit

class ColumnFlowLayout: UICollectionViewFlowLayout {
    
    @IBInspectable var minimumColumnWidth: CGFloat = 0.0
    
    override func prepare() {
        super.prepare()
        
        guard let collectionView = collectionView else {
            return
        }
        
        let availableWidth = collectionView.bounds.inset(by: collectionView.layoutMargins).size.width
        let effectiveMinimumWidth = minimumColumnWidth <= 0 ? availableWidth : min(minimumColumnWidth, availableWidth)
        let columnCount = (availableWidth / effectiveMinimumWidth).rounded(.down)
        let cellWidth = ((availableWidth - minimumInteritemSpacing * (columnCount - 1)) / columnCount).rounded(.down)
        
        os_log("Total width %2f, calculated column count %0f with width %0f.  Current item size: %@", type: .debug, availableWidth, columnCount, cellWidth, itemSize.debugDescription)
        
        itemSize = CGSize(width: cellWidth, height: itemSize.height)
    }
    
}
<commit_msg>Consider sectionInsetReference when determining inset size<commit_after>//
//  ColumnFlowLayout.swift
//  AlliCrab
//
//  Copyright © 2019 <NAME>. All rights reserved.
//

import os
import UIKit

class ColumnFlowLayout: UICollectionViewFlowLayout {
    
    @IBInspectable var minimumColumnWidth: CGFloat = 0.0
    
    override func prepare() {
        super.prepare()
        
        guard let collectionView = collectionView else {
            return
        }
        
        let edgeInsets: UIEdgeInsets
        if #available(iOS 11.0, *) {
            switch sectionInsetReference {
            case .fromContentInset:
                edgeInsets = collectionView.contentInset
            case .fromLayoutMargins:
                edgeInsets = collectionView.layoutMargins
            case .fromSafeArea:
                edgeInsets = collectionView.safeAreaInsets
            }
        } else {
            edgeInsets = collectionView.layoutMargins
        }
        
        let availableWidth = collectionView.bounds.inset(by: edgeInsets).inset(by: sectionInset).size.width
        let effectiveMinimumWidth = minimumColumnWidth <= 0 ? availableWidth : min(minimumColumnWidth, availableWidth)
        let columnCount = (availableWidth / effectiveMinimumWidth).rounded(.down)
        let cellWidth = ((availableWidth - minimumInteritemSpacing * (columnCount - 1)) / columnCount).rounded(.down)
        
        os_log("Total width %.2f, calculated column count %.0f with width %.0f.  Current item size: %@", type: .debug, availableWidth, columnCount, cellWidth, itemSize.debugDescription)
        
        itemSize = CGSize(width: cellWidth, height: itemSize.height)
    }
    
}

{'fraction_non_alphanumeric': 0.08617021276595745, 'fraction_numerical': 0.008865248226950355, 'mean_word_length': 2.5395232120451694, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4023536', 'n_tokens_mistral': 783, 'n_tokens_neox': 739, 'n_words': 185}