Commit b53376dd by Daniel Dahan

development: Update Grid to no longer use an optional views array.

parent d0e01ffe
...@@ -185,12 +185,12 @@ public class ControlView: View { ...@@ -185,12 +185,12 @@ public class ControlView: View {
contentView.grid.columns -= c.grid.columns contentView.grid.columns -= c.grid.columns
addSubview(c) addSubview(c)
grid.views?.append(c) grid.views.append(c)
} }
} }
addSubview(contentView) addSubview(contentView)
grid.views?.append(contentView) grid.views.append(contentView)
// rightControls // rightControls
if let v = rightControls { if let v = rightControls {
...@@ -205,7 +205,7 @@ public class ControlView: View { ...@@ -205,7 +205,7 @@ public class ControlView: View {
contentView.grid.columns -= c.grid.columns contentView.grid.columns -= c.grid.columns
addSubview(c) addSubview(c)
grid.views?.append(c) grid.views.append(c)
} }
} }
......
...@@ -172,7 +172,7 @@ public class Grid { ...@@ -172,7 +172,7 @@ public class Grid {
} }
/// An Array of UIButtons. /// An Array of UIButtons.
public var views: [UIView]? { public var views: [UIView] {
didSet { didSet {
reload() reload()
} }
...@@ -189,66 +189,65 @@ public class Grid { ...@@ -189,66 +189,65 @@ public class Grid {
self.rows = rows self.rows = rows
self.columns = columns self.columns = columns
self.interimSpace = interimSpace self.interimSpace = interimSpace
views = [UIView]()
offset = GridOffset(grid: self) offset = GridOffset(grid: self)
axis = GridAxis(grid: self) axis = GridAxis(grid: self)
} }
/// Reload the button layout. /// Reload the button layout.
public func reload() { public func reload() {
if let v = views { 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..<views.count {
let child = views[i]
for i in 0..<v.count { if let parent = context {
let child = v[i] if parent != child.superview {
child.removeFromSuperview()
parent.addSubview(child)
}
parent.layoutIfNeeded()
if let parent = context { switch axis.direction {
if parent != child.superview { case .horizontal:
child.removeFromSuperview() let c = child.grid.columns
parent.addSubview(child) let co = child.grid.offset.columns
} let w = (parent.bounds.width - contentInset.left - contentInset.right - layoutInset.left - layoutInset.right + interimSpace) / CGFloat(gc)
child.x = CGFloat(i + n + co) * w + contentInset.left + layoutInset.left
child.y = contentInset.top + layoutInset.top
child.width = w * CGFloat(c) - interimSpace
child.height = parent.bounds.height - contentInset.top - contentInset.bottom - layoutInset.top - layoutInset.bottom
parent.layoutIfNeeded() n += c + co - 1
switch axis.direction { case .vertical:
case .horizontal: let r = child.grid.rows
let c = child.grid.columns let ro = child.grid.offset.rows
let co = child.grid.offset.columns let h = (parent.bounds.height - contentInset.top - contentInset.bottom - layoutInset.top - layoutInset.bottom + interimSpace) / CGFloat(gr)
let w = (parent.bounds.width - contentInset.left - contentInset.right - layoutInset.left - layoutInset.right + interimSpace) / CGFloat(gc)
child.x = contentInset.left + layoutInset.left
child.x = CGFloat(i + n + co) * w + contentInset.left + layoutInset.left child.y = CGFloat(i + n + ro) * h + contentInset.top + layoutInset.top
child.y = contentInset.top + layoutInset.top child.width = parent.bounds.width - contentInset.left - contentInset.right - layoutInset.left - layoutInset.right
child.width = w * CGFloat(c) - interimSpace child.height = h * CGFloat(r) - interimSpace
child.height = parent.bounds.height - contentInset.top - contentInset.bottom - layoutInset.top - layoutInset.bottom
n += r + ro - 1
n += c + co - 1
case .any:
case .vertical: let r = child.grid.rows
let r = child.grid.rows let ro = child.grid.offset.rows
let ro = child.grid.offset.rows let c = child.grid.columns
let h = (parent.bounds.height - contentInset.top - contentInset.bottom - layoutInset.top - layoutInset.bottom + interimSpace) / CGFloat(gr) let co = child.grid.offset.columns
let w = (parent.bounds.width - contentInset.left - contentInset.right - layoutInset.left - layoutInset.right + interimSpace) / CGFloat(gc)
child.x = contentInset.left + layoutInset.left let h = (parent.bounds.height - contentInset.top - contentInset.bottom - layoutInset.top - layoutInset.bottom + interimSpace) / CGFloat(gr)
child.y = CGFloat(i + n + ro) * h + contentInset.top + layoutInset.top
child.width = parent.bounds.width - contentInset.left - contentInset.right - layoutInset.left - layoutInset.right
child.height = h * CGFloat(r) - interimSpace
n += r + ro - 1
case .any: child.x = CGFloat(co) * w + contentInset.left + layoutInset.left
let r = child.grid.rows child.y = CGFloat(ro) * h + contentInset.top + layoutInset.top
let ro = child.grid.offset.rows child.width = w * CGFloat(c) - interimSpace
let c = child.grid.columns child.height = h * CGFloat(r) - interimSpace
let co = child.grid.offset.columns
let w = (parent.bounds.width - contentInset.left - contentInset.right - layoutInset.left - layoutInset.right + interimSpace) / CGFloat(gc)
let h = (parent.bounds.height - contentInset.top - contentInset.bottom - layoutInset.top - layoutInset.bottom + interimSpace) / CGFloat(gr)
child.x = CGFloat(co) * w + contentInset.left + layoutInset.left
child.y = CGFloat(ro) * h + contentInset.top + layoutInset.top
child.width = w * CGFloat(c) - interimSpace
child.height = h * CGFloat(r) - interimSpace
}
} }
} }
} }
......
...@@ -219,12 +219,12 @@ public class NavigationBar: UINavigationBar { ...@@ -219,12 +219,12 @@ public class NavigationBar: UINavigationBar {
contentView.grid.columns -= c.grid.columns contentView.grid.columns -= c.grid.columns
titleView.addSubview(c) titleView.addSubview(c)
titleView.grid.views?.append(c) titleView.grid.views.append(c)
} }
} }
titleView.addSubview(contentView) titleView.addSubview(contentView)
titleView.grid.views?.append(contentView) titleView.grid.views.append(contentView)
// rightControls // rightControls
if let v: Array<UIControl> = item.rightControls { if let v: Array<UIControl> = item.rightControls {
...@@ -239,7 +239,7 @@ public class NavigationBar: UINavigationBar { ...@@ -239,7 +239,7 @@ public class NavigationBar: UINavigationBar {
contentView.grid.columns -= c.grid.columns contentView.grid.columns -= c.grid.columns
titleView.addSubview(c) titleView.addSubview(c)
titleView.grid.views?.append(c) titleView.grid.views.append(c)
} }
} }
......
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