-
Notifications
You must be signed in to change notification settings - Fork 2
Home
André J edited this page Jan 7, 2019
·
2 revisions
Some WIP code for when you implement spaceBetween and spaceAround
extension Constraint{
/**
* Aligns one item after the other and centers their total position
*/
// static func distribute(fromCenter views:[UIConstraintView], axis:Axis, length:CGFloat, offset:CGFloat) {
//
// //🏀 THEN DO THIS, only works with UIConstraintView where size is available
//
// //find the totalW of all items
// let totV:CGFloat = views.reduce(0){$0 + axis == .hor ? $1.size.width : $1.size.height}
// //Use Align.center to find x
// let v:CGPoint = offset + round(length/2) - round(totV/2)//Align.alignmentPoint(CGSize(totV,0), container.size, Alignment.centerCenter, Alignment.centerCenter, CGPoint())
// //Use justifyFlexStart and lay items out left to right with new rect as offset
// distributeFromStart(views, axis:axis, offset:v)
// }
}
extension Constraint{
/**
* Space items evenly to fill length
*/
//extension Distribution{
/**
* Aligns all items from the absolute start to absolute end and adds equa spacing between them
* TODO: ⚠️️ complete this
* IMPORTANT ⚠️️ only works with UIConstraintView where size is available
*/
// public static func spaceBetween(_ views:[ConstraintKind], _ container:CGRect) {
// let totW:CGFloat = views.reduce(0){$0 + $1.size?.w.constant || 0}/*find the totalW of all items*/
// let totVoid:CGFloat = container.width - totW/*find totVoid by doing w - totw*/
// let numOfVoids:CGFloat = CGFloat(views.count - 1)/*then divide this voidSpace with .count - 1 and*/
// let itemVoid:CGFloat = totVoid / numOfVoids/*iterate of each item and inserting itemVoid in + width*/
// var x:CGFloat = container.minX//interim x
// views.forEach{ item in
// item.flexible.x = x
// x += item.width + itemVoid
// }
// }
}
/**
* Same as spaceBetween but does not pin to sides but rather add equal spacing there as well
* TODO: ⚠️️ complete this
* IMPORTANT ⚠️️ only works with UIConstraintView where size is available
*/
// public static func spaceAround(_ items:[FlexBoxItemKind], _ container:CGRect) {
// let totW:CGFloat = items.reduce(0){$0 + $1.flexible.size.width}/*find the totalW of all items*/
// let totVoid:CGFloat = container.width - totW/*find totVoid by doing w - totw*/
// let numOfVoids:CGFloat = CGFloat(items.count)/*then divide this voidSpace with .count - 1 and*/
// let itemVoid:CGFloat = totVoid / numOfVoids/*iterate of each item and inserting itemVoid in + width*/
// let edgeVoid:CGFloat = itemVoid/2
// var x:CGFloat = container.x+edgeVoid//interim x
// items.forEach{ item in
// item.flexible.x = x
// x += item.width + itemVoid
// }
// }
//}