<commit_before>//
// Copyright (c) 2016-2017 wag it GmbH.
// License: MIT
//

import Foundation
import UIKit

/**
    Lays the wrapped element out so it matches its parent's size.
 */
public struct BayaMatchParentLayout: BayaLayout {
    public var layoutMargins: UIEdgeInsets
    public var frame: CGRect

    private var element: BayaLayoutable
    private let matchParent: (width: Bool, height: Bool)

    init(
        element: BayaLayoutable,
        matchParent: (width: Bool, height: Bool),
        layoutMargins: UIEdgeInsets = UIEdgeInsets.zero) {
        self.element = element
        self.matchParent = matchParent
        self.layoutMargins = layoutMargins
        self.frame = CGRect()
    }

    mutating public func layoutWith(frame: CGRect) {
        self.frame = frame
        element.subtractMarginsAndLayoutWith(frame: frame)
    }

    public mutating func sizeThatFits(_ size: CGSize) -> CGSize {
        if matchParent.width && matchParent.height {
            return size
        }
        let fit = element.sizeThatFitsWithMargins(size)
        return CGSize(
            width: matchParent.width ? size.width : fit.width + element.horizontalMargins,
            height: matchParent.height ? size.height : fit.height + element.verticalMargins)
    }
}

public extension BayaLayoutable {
    func layoutMatchingParent(
        width: Bool,
        height: Bool,
        layoutMargins: UIEdgeInsets = UIEdgeInsets.zero)
            -> BayaMatchParentLayout {
        return BayaMatchParentLayout(
            element: self,
            matchParent: (width: width, height: height),
            layoutMargins: layoutMargins)
    }
}
<commit_msg>(impr) rewrite match parent layout for new modes<commit_after>//
// Copyright (c) 2016-2017 wag it GmbH.
// License: MIT
//

import Foundation
import UIKit

/**
    Wraps a Layoutable in order to modify its measures modes.
 */
public struct BayaMatchParentLayout: BayaLayout {
    public var layoutMargins: UIEdgeInsets {
        return element.layoutMargins
    }
    public var frame: CGRect {
        return element.frame;
    }
    public var measureModes: BayaMeasureModes = defaultMeasureModes

    private var element: BayaLayoutable

    init(
        element: BayaLayoutable,
        measureModes: BayaMeasureModes) {
        self.element = element
        self.measureModes = measureModes
    }

    mutating public func layoutWith(frame: CGRect) {
        element.layoutWith(frame: frame)
    }

    public mutating func sizeThatFits(_ size: CGSize) -> CGSize {
        return element.sizeThatFits(size)
    }
}

public extension BayaLayoutable {
    func layoutMatchingParentWidth() -> BayaLayout {
        return BayaMatchParentLayout(
            element: self,
            measureModes: BayaMeasureModes(
                width: .matchParent,
                height: .wrapContent))
    }

    func layoutMatchingParentHeight() -> BayaLayout {
        return BayaMatchParentLayout(
            element: self,
            measureModes: BayaMeasureModes(
                width: .wrapContent,
                height: .matchParent))
    }

    func layoutMatchingParent()
            -> BayaLayout {
        return BayaMatchParentLayout(
            element: self,
            measureModes: BayaMeasureModes(
                width: .matchParent,
                height: .matchParent))
    }
}

{'fraction_non_alphanumeric': 0.07719714964370546, 'fraction_numerical': 0.004750593824228029, 'mean_word_length': 2.3224852071005917, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3299088', 'n_tokens_mistral': 983, 'n_tokens_neox': 917, 'n_words': 248}