Commit d2aa614b by Daniel Dahan

development: Updated grid layout and content EdgeInsets

parent d200c0b3
...@@ -141,10 +141,10 @@ public class MaterialCollectionReusableView: UICollectionReusableView { ...@@ -141,10 +141,10 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
/// A wrapper around grid.contentInset. /// A wrapper around grid.contentInset.
@IBInspectable public var contentInset: UIEdgeInsets { @IBInspectable public var contentInset: UIEdgeInsets {
get { get {
return grid.contentInset return grid.contentEdgeInsets
} }
set(value) { set(value) {
grid.contentInset = value grid.contentEdgeInsets = value
} }
} }
......
...@@ -141,10 +141,10 @@ public class CollectionViewCell: UICollectionViewCell { ...@@ -141,10 +141,10 @@ public class CollectionViewCell: UICollectionViewCell {
/// A wrapper around grid.contentInset. /// A wrapper around grid.contentInset.
@IBInspectable public var contentInset: UIEdgeInsets { @IBInspectable public var contentInset: UIEdgeInsets {
get { get {
return contentView.grid.contentInset return contentView.grid.contentEdgeInsets
} }
set(value) { set(value) {
contentView.grid.contentInset = value contentView.grid.contentEdgeInsets = value
} }
} }
......
...@@ -49,10 +49,10 @@ public class ControlView: View { ...@@ -49,10 +49,10 @@ public class ControlView: View {
/// A wrapper around grid.contentInset. /// A wrapper around grid.contentInset.
@IBInspectable public var contentInset: EdgeInsets { @IBInspectable public var contentInset: EdgeInsets {
get { get {
return grid.contentInset return grid.contentEdgeInsets
} }
set(value) { set(value) {
grid.contentInset = value grid.contentEdgeInsets = value
} }
} }
...@@ -209,7 +209,7 @@ public class ControlView: View { ...@@ -209,7 +209,7 @@ public class ControlView: View {
} }
} }
grid.contentInset = contentInset grid.contentEdgeInsets = contentInset
grid.interimSpace = interimSpace grid.interimSpace = interimSpace
grid.reload() grid.reload()
contentView.grid.reload() contentView.grid.reload()
......
...@@ -41,11 +41,12 @@ public class GridAxis { ...@@ -41,11 +41,12 @@ public class GridAxis {
/// Grid reference. /// Grid reference.
unowned var grid: Grid unowned var grid: Grid
/// Inherit grid rows and columns.
public var isInherited: Bool = false
/// The direction the grid lays its views out. /// The direction the grid lays its views out.
public var direction: GridAxisDirection = .horizontal public var direction: GridAxisDirection = .horizontal {
didSet {
grid.reload()
}
}
/// The rows size. /// The rows size.
public var rows: Int { public var rows: Int {
...@@ -132,12 +133,12 @@ public class Grid { ...@@ -132,12 +133,12 @@ public class Grid {
/// Preset inset value for grid. /// Preset inset value for grid.
public var layoutEdgeInsetsPreset: EdgeInsetsPreset = .none { public var layoutEdgeInsetsPreset: EdgeInsetsPreset = .none {
didSet { didSet {
layoutInset = EdgeInsetsPresetToValue(preset: contentEdgeInsetsPreset) layoutEdgeInsets = EdgeInsetsPresetToValue(preset: contentEdgeInsetsPreset)
} }
} }
/// Insets value for grid. /// Insets value for grid.
public var layoutInset = EdgeInsets.zero { public var layoutEdgeInsets = EdgeInsets.zero {
didSet { didSet {
reload() reload()
} }
...@@ -146,12 +147,12 @@ public class Grid { ...@@ -146,12 +147,12 @@ public class Grid {
/// Preset inset value for grid. /// Preset inset value for grid.
public var contentEdgeInsetsPreset: EdgeInsetsPreset = .none { public var contentEdgeInsetsPreset: EdgeInsetsPreset = .none {
didSet { didSet {
contentInset = EdgeInsetsPresetToValue(preset: contentEdgeInsetsPreset) contentEdgeInsets = EdgeInsetsPresetToValue(preset: contentEdgeInsetsPreset)
} }
} }
/// Insets value for grid. /// Insets value for grid.
public var contentInset: EdgeInsets = EdgeInsetsPresetToValue(preset: .none) { public var contentEdgeInsets = EdgeInsets.zero {
didSet { didSet {
reload() reload()
} }
...@@ -196,8 +197,6 @@ public class Grid { ...@@ -196,8 +197,6 @@ public class Grid {
/// Reload the button layout. /// Reload the button layout.
public func reload() { public func reload() {
let gc = axis.isInherited ? columns : axis.columns
let gr = axis.isInherited ? rows : axis.rows
var n: Int = 0 var n: Int = 0
for i in 0..<views.count { for i in 0..<views.count {
...@@ -215,23 +214,23 @@ public class Grid { ...@@ -215,23 +214,23 @@ public class Grid {
case .horizontal: case .horizontal:
let c = child.grid.columns let c = child.grid.columns
let co = child.grid.offset.columns let co = child.grid.offset.columns
let w = (parent.bounds.width - contentInset.left - contentInset.right - layoutInset.left - layoutInset.right + interimSpace) / CGFloat(gc) let w = (parent.bounds.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right + interimSpace) / CGFloat(axis.columns)
child.x = CGFloat(i + n + co) * w + contentInset.left + layoutInset.left child.x = CGFloat(i + n + co) * w + contentEdgeInsets.left + layoutEdgeInsets.left
child.y = contentInset.top + layoutInset.top child.y = contentEdgeInsets.top + layoutEdgeInsets.top
child.width = w * CGFloat(c) - interimSpace child.width = w * CGFloat(c) - interimSpace
child.height = parent.bounds.height - contentInset.top - contentInset.bottom - layoutInset.top - layoutInset.bottom child.height = parent.bounds.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom
n += c + co - 1 n += c + co - 1
case .vertical: 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 h = (parent.bounds.height - contentInset.top - contentInset.bottom - layoutInset.top - layoutInset.bottom + interimSpace) / CGFloat(gr) let h = (parent.bounds.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom + interimSpace) / CGFloat(axis.rows)
child.x = contentInset.left + layoutInset.left child.x = contentEdgeInsets.left + layoutEdgeInsets.left
child.y = CGFloat(i + n + ro) * h + contentInset.top + layoutInset.top child.y = CGFloat(i + n + ro) * h + contentEdgeInsets.top + layoutEdgeInsets.top
child.width = parent.bounds.width - contentInset.left - contentInset.right - layoutInset.left - layoutInset.right child.width = parent.bounds.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right
child.height = h * CGFloat(r) - interimSpace child.height = h * CGFloat(r) - interimSpace
n += r + ro - 1 n += r + ro - 1
...@@ -241,11 +240,11 @@ public class Grid { ...@@ -241,11 +240,11 @@ public class Grid {
let ro = child.grid.offset.rows let ro = child.grid.offset.rows
let c = child.grid.columns let c = child.grid.columns
let co = child.grid.offset.columns let co = child.grid.offset.columns
let w = (parent.bounds.width - contentInset.left - contentInset.right - layoutInset.left - layoutInset.right + interimSpace) / CGFloat(gc) let w = (parent.bounds.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right + interimSpace) / CGFloat(axis.columns)
let h = (parent.bounds.height - contentInset.top - contentInset.bottom - layoutInset.top - layoutInset.bottom + interimSpace) / CGFloat(gr) let h = (parent.bounds.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom + interimSpace) / CGFloat(axis.rows)
child.x = CGFloat(co) * w + contentInset.left + layoutInset.left child.x = CGFloat(co) * w + contentEdgeInsets.left + layoutEdgeInsets.left
child.y = CGFloat(ro) * h + contentInset.top + layoutInset.top child.y = CGFloat(ro) * h + contentEdgeInsets.top + layoutEdgeInsets.top
child.width = w * CGFloat(c) - interimSpace child.width = w * CGFloat(c) - interimSpace
child.height = h * CGFloat(r) - interimSpace child.height = h * CGFloat(r) - interimSpace
} }
......
...@@ -243,7 +243,7 @@ public class NavigationBar: UINavigationBar { ...@@ -243,7 +243,7 @@ public class NavigationBar: UINavigationBar {
} }
} }
titleView.grid.contentInset = contentInset titleView.grid.contentEdgeInsets = contentInset
titleView.grid.interimSpace = interimSpace titleView.grid.interimSpace = interimSpace
titleView.grid.reload() titleView.grid.reload()
......
...@@ -60,13 +60,13 @@ public class SearchBarController: RootController { ...@@ -60,13 +60,13 @@ public class SearchBarController: RootController {
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if let v: SearchBar = searchBar { if let v: SearchBar = searchBar {
v.grid.layoutInset.top = .phone == Device.userInterfaceIdiom && Device.isLandscape ? 0 : 20 v.grid.layoutEdgeInsets.top = .phone == Device.userInterfaceIdiom && Device.isLandscape ? 0 : 20
let h: CGFloat = Device.height let h: CGFloat = Device.height
let w: CGFloat = Device.width let w: CGFloat = Device.width
let p: CGFloat = v.intrinsicContentSize.height + v.grid.layoutInset.top + v.grid.layoutInset.bottom let p: CGFloat = v.intrinsicContentSize.height + v.grid.layoutEdgeInsets.top + v.grid.layoutEdgeInsets.bottom
v.width = w + v.grid.layoutInset.left + v.grid.layoutInset.right v.width = w + v.grid.layoutEdgeInsets.left + v.grid.layoutEdgeInsets.right
v.height = p v.height = p
rootViewController.view.frame.origin.y = p rootViewController.view.frame.origin.y = p
......
...@@ -163,13 +163,13 @@ public class ToolbarController: RootController { ...@@ -163,13 +163,13 @@ public class ToolbarController: RootController {
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if let v: Toolbar = toolbar { if let v: Toolbar = toolbar {
v.grid.layoutInset.top = .phone == Device.userInterfaceIdiom && Device.isLandscape ? 0 : 20 v.grid.layoutEdgeInsets.top = .phone == Device.userInterfaceIdiom && Device.isLandscape ? 0 : 20
let h: CGFloat = Device.height let h: CGFloat = Device.height
let w: CGFloat = Device.width let w: CGFloat = Device.width
let p: CGFloat = v.intrinsicContentSize.height + v.grid.layoutInset.top + v.grid.layoutInset.bottom let p: CGFloat = v.intrinsicContentSize.height + v.grid.layoutEdgeInsets.top + v.grid.layoutEdgeInsets.bottom
v.width = w + v.grid.layoutInset.left + v.grid.layoutInset.right v.width = w + v.grid.layoutEdgeInsets.left + v.grid.layoutEdgeInsets.right
v.height = p v.height = p
rootViewController.view.frame.origin.y = p rootViewController.view.frame.origin.y = p
......
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