<commit_before>//
//  PileView.swift
//  BFWControls
//
//  Created by <NAME> on 25/11/16.
//  Copyright © 2016 BareFeetWare. Free to use and modify, without warranty.
//

import UIKit

@IBDesignable class PileView: UIView {
    
    // MARK: - Variables
    
    @IBInspectable var gapWidth: CGFloat = 0.0 { didSet { setNeedsLayout() }}
    @IBInspectable var gapHeight: CGFloat = 0.0 { didSet { setNeedsLayout() }}
    
    private var subviewCount: CGFloat {
        return CGFloat(subviews.count)
    }
    
    private var subviewMaxWidth: CGFloat {
        return (bounds.size.width - (subviewCount - 1) * gapWidth) / subviewCount
    }
    
    // TODO: Dynamic
    var subviewHeight: CGFloat = 44.0
    
    var isHorizontal: Bool {
        let isHorizontal = subviews.reduce(true) { (doesFit, subview) in
            return doesFit && subview.sizeThatFits(bounds.size).width <= subviewMaxWidth
        }
        return isHorizontal
    }
    
    private var subviewWidth: CGFloat {
        return isHorizontal ? subviewMaxWidth : bounds.width
    }
    
    // MARK: - UIView
    
    override func intrinsicContentSize() -> CGSize {
        return CGSize(width: UIViewNoIntrinsicMetric,
                      height: isHorizontal
                        ? subviewHeight
                        : subviewCount * subviewHeight + (subviewCount - 1) * gapHeight)
    }
    
    override func layoutSubviews() {
        for (index, subview) in subviews.enumerate() {
            let origin = isHorizontal
                ? CGPoint(x: (subviewWidth + gapWidth) * CGFloat(index),
                          y: 0.0)
                : CGPoint(x: 0.0,
                          y: (subviewHeight + gapHeight) * CGFloat(index))
            subview.frame = CGRect(origin: origin,
                                   size: CGSize(width: subviewWidth,
                                                height: subviewHeight))
        }
    }
    <commit_msg>PileView: updates intrinsicContentSize when resized (eg rotated)<commit_after>//
//  PileView.swift
//  BFWControls
//
//  Created by <NAME> on 25/11/16.
//  Copyright © 2016 BareFeetWare. Free to use and modify, without warranty.
//

import UIKit

@IBDesignable class PileView: UIView {
    
    // MARK: - Variables
    
    @IBInspectable var gapWidth: CGFloat = 0.0 { didSet { setNeedsLayout() }}
    @IBInspectable var gapHeight: CGFloat = 0.0 { didSet { setNeedsLayout() }}
    
    private var subviewCount: CGFloat {
        return CGFloat(subviews.count)
    }
    
    private var subviewMaxWidth: CGFloat {
        return (bounds.size.width - (subviewCount - 1) * gapWidth) / subviewCount
    }
    
    // TODO: Dynamic
    var subviewHeight: CGFloat = 44.0
    
    var isHorizontal: Bool {
        let isHorizontal = subviews.reduce(true) { (doesFit, subview) in
            return doesFit && subview.sizeThatFits(bounds.size).width <= subviewMaxWidth
        }
        return isHorizontal
    }
    
    private var subviewWidth: CGFloat {
        return isHorizontal ? subviewMaxWidth : bounds.width
    }
    
    // MARK: - UIView
    
    override func intrinsicContentSize() -> CGSize {
        return CGSize(width: UIViewNoIntrinsicMetric,
                      height: isHorizontal
                        ? subviewHeight
                        : subviewCount * subviewHeight + (subviewCount - 1) * gapHeight)
    }
    
    override func layoutSubviews() {
        invalidateIntrinsicContentSize()
        for (index, subview) in subviews.enumerate() {
            let origin = isHorizontal
                ? CGPoint(x: (subviewWidth + gapWidth) * CGFloat(index),
                          y: 0.0)
                : CGPoint(x: 0.0,
                          y: (subviewHeight + gapHeight) * CGFloat(index))
            subview.frame = CGRect(origin: origin,
                                   size: CGSize(width: subviewWidth,
                                                height: subviewHeight))
        }
    }
    
{'fraction_non_alphanumeric': 0.0913870806209314, 'fraction_numerical': 0.011517275913870806, 'mean_word_length': 1.7438186813186813, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6531954', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1142, 'n_words': 275}