Commit 19fad6e1 by Daniel Dahan

development: updated to Grid and Layout

parent ccc51561
......@@ -199,14 +199,18 @@ public class Grid {
let gc = axis.inherited ? columns : axis.columns
let gr = axis.inherited ? rows : axis.rows
var n: Int = 0
for i in 0..<v.count {
let child: UIView = v[i]
if let parent: UIView = context {
if parent != child.superview {
child.removeFromSuperview()
parent.addSubview(child)
}
parent.layoutIfNeeded()
switch axis.direction {
case .horizontal:
let w = (parent.bounds.width - contentInset.left - contentInset.right - layoutInset.left - layoutInset.right + interimSpace) / CGFloat(gc)
......@@ -215,8 +219,14 @@ public class Grid {
let vh = parent.bounds.height - contentInset.top - contentInset.bottom - layoutInset.top - layoutInset.bottom
let vl = CGFloat(i + n + co) * w + contentInset.left + layoutInset.left
let vw = w * CGFloat(c) - interimSpace
child.frame = CGRect(x: vl, y: contentInset.top + layoutInset.top, width: vw, height: vh)
child.x = vl
child.y = contentInset.top + layoutInset.top
child.width = vw
child.height = vh
n += c + co - 1
case .vertical:
let h = (parent.bounds.height - contentInset.top - contentInset.bottom - layoutInset.top - layoutInset.bottom + interimSpace) / CGFloat(gr)
let r = child.grid.rows
......@@ -224,8 +234,14 @@ public class Grid {
let vw = parent.bounds.width - contentInset.left - contentInset.right - layoutInset.left - layoutInset.right
let vt = CGFloat(i + n + ro) * h + contentInset.top + layoutInset.top
let vh = h * CGFloat(r) - interimSpace
child.frame = CGRect(x: contentInset.left + layoutInset.left, y: vt, width: vw, height: vh)
child.x = contentInset.left + layoutInset.left
child.y = vt
child.width = vw
child.height = vh
n += r + ro - 1
case .none:
let w = (parent.bounds.width - contentInset.left - contentInset.right - layoutInset.left - layoutInset.right + interimSpace) / CGFloat(gc)
let c = child.grid.columns
......@@ -237,7 +253,11 @@ public class Grid {
let vl = CGFloat(co) * w + contentInset.left + layoutInset.left
let vh = h * CGFloat(r) - interimSpace
let vw = w * CGFloat(c) - interimSpace
child.frame = CGRect(x: vl, y: vt, width: vw, height: vh)
child.x = vl
child.y = vt
child.width = vw
child.height = vh
}
}
}
......
......@@ -134,30 +134,28 @@ public class Layout {
/**
Sets the width and height of a view.
- Parameter child: A child UIView to layout.
- Parameter width: A CGFloat value.
- Parameter height: A CGFloat value.
- Parameter size: A CGSize value.
- Returns: The current Layout instance.
*/
public func size(_ child: UIView, width: CGFloat, height: CGFloat) -> Layout {
public func size(_ child: UIView, size: CGSize) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.size(parent: v, child: child, width: width, height: height)
Layout.size(parent: v, child: child, size: size)
return self
}
/**
Sets the width and height of a view assuming a child context view.
- Parameter width: A CGFloat value.
- Parameter height: A CGFloat value.
- Parameter size: A CGSize value.
- Returns: The current Layout instance.
*/
public func size(width: CGFloat, height: CGFloat) -> Layout {
public func size(_ size: CGSize = CGSize.zero) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return size(v, width: width, height: height)
return self.size(v, size: size)
}
/**
......@@ -622,12 +620,11 @@ public extension Layout {
Sets the width and height of a view.
- Parameter parent: A parent UIView context.
- Parameter child: A child UIView to layout.
- Parameter width: A CGFloat value.
- Parameter height: A CGFloat value.
- Parameter size: A CGSize value.
*/
public class func size(parent: UIView, child: UIView, width: CGFloat = 0, height: CGFloat = 0) {
Layout.width(parent: parent, child: child, width: width)
Layout.height(parent: parent, child: child, height: height)
public class func size(parent: UIView, child: UIView, size: CGSize = CGSize.zero) {
Layout.width(parent: parent, child: child, width: size.width)
Layout.height(parent: parent, child: child, height: size.height)
}
/**
......
......@@ -401,9 +401,14 @@ public extension UIView {
/// Manages the layout for the shape of the view instance.
public func layoutShape() {
if .circle == shapePreset {
let w: CGFloat = (width / 2)
if w != cornerRadius {
cornerRadius = w
if width < height {
width = height
} else {
height = width
}
let r = width / 2
if r != cornerRadius {
cornerRadius = r
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment