<commit_before>//
//  LayoutView.swift
//  NotAutoLayout
//
//  Created by 史翔新 on 2017/02/09.
//  Copyright © 2017年 史翔新. All rights reserved.
//

import UIKit

public class LayoutView: UIView {
	
	public typealias Condition = (CGSize) -> Bool
	public typealias LayoutMethod = (condition: (CGSize) -> Bool, position: Position)
	public typealias SubviewTuple = (view: UIView, layoutMethods: [LayoutMethod])
	
	public var layoutingSubviews: [SubviewTuple] = []
	
}

extension LayoutView {
	
	private func place(_ view: UIView, at position: Position) {
		
		let rect = position.absoluteRect(in: self.bounds.size)
		let centerX = rect.origin.x + (rect.width * 0.5)
		let centerY = rect.origin.y + (rect.height * 0.5)
		view.bounds.size = rect.size
		view.center = CGPoint(x: centerX, y: centerY)
		
	}
	
	private func layout(_ viewTuple: SubviewTuple) {
		
		for layoutMethod in viewTuple.layoutMethods {
			if layoutMethod.condition(self.bounds.size) == true {
				self.place(viewTuple.view, at: layoutMethod.position)
				break
			}
		}
		
	}
	
	public override func layoutSubviews() {
		super.layoutSubviews()
		
		self.layoutingSubviews.forEach { (tuple) in
			self.layout(tuple)
		}
		
	}
	
}

extension LayoutView {
	
	private func removeAllSubviews() {
		self.subviews.forEach { (view) in
			view.removeFromSuperview()
		}
	}
	
	private func addLayoutingSubviews() {
		self.layoutingSubviews.forEach { (view, _) in
			self.addSubview(view)
		}
	}
	
	public func reloadLayoutingSubviews() {
		
		self.removeAllSubviews()
		self.addLayoutingSubviews()
		
	}
	
}

private func * (lhs: CGRect, rhs: CGRect) -> CGRect {
	return CGRect(x: lhs.origin.x * rhs.origin.x, y: lhs.origin.y * rhs.origin.y, width: lhs.width * rhs.width, height: lhs.height * rhs.height)
}<commit_msg>Remove old unused method<commit_after>//
//  LayoutView.swift
//  NotAutoLayout
//
//  Created by 史翔新 on 2017/02/09.
//  Copyright © 2017年 史翔新. All rights reserved.
//

import UIKit

public class LayoutView: UIView {
	
	public typealias Condition = (CGSize) -> Bool
	public typealias LayoutMethod = (condition: (CGSize) -> Bool, position: Position)
	public typealias SubviewTuple = (view: UIView, layoutMethods: [LayoutMethod])
	
	public var layoutingSubviews: [SubviewTuple] = []
	
}

extension LayoutView {
	
	private func place(_ view: UIView, at position: Position) {
		
		let rect = position.absoluteRect(in: self.bounds.size)
		let centerX = rect.origin.x + (rect.width * 0.5)
		let centerY = rect.origin.y + (rect.height * 0.5)
		view.bounds.size = rect.size
		view.center = CGPoint(x: centerX, y: centerY)
		
	}
	
	private func layout(_ viewTuple: SubviewTuple) {
		
		for layoutMethod in viewTuple.layoutMethods {
			if layoutMethod.condition(self.bounds.size) == true {
				self.place(viewTuple.view, at: layoutMethod.position)
				break
			}
		}
		
	}
	
	public override func layoutSubviews() {
		super.layoutSubviews()
		
		self.layoutingSubviews.forEach { (tuple) in
			self.layout(tuple)
		}
		
	}
	
}

extension LayoutView {
	
	private func removeAllSubviews() {
		self.subviews.forEach { (view) in
			view.removeFromSuperview()
		}
	}
	
	private func addLayoutingSubviews() {
		self.layoutingSubviews.forEach { (view, _) in
			self.addSubview(view)
		}
	}
	
	public func reloadLayoutingSubviews() {
		
		self.removeAllSubviews()
		self.addLayoutingSubviews()
		
	}
	
}
{'fraction_non_alphanumeric': 0.11769964243146604, 'fraction_numerical': 0.009535160905840286, 'mean_word_length': 3.4463576158940397, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '1359243', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1127, 'n_words': 267}