Commit 19fad6e1 by Daniel Dahan

development: updated to Grid and Layout

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