Commit 39e54828 by Daniel Dahan

development: refining Grid for Navigational controls

parent 9cfba910
...@@ -101,7 +101,7 @@ open class ControlView: View { ...@@ -101,7 +101,7 @@ open class ControlView: View {
} }
/// ContentView that holds the any desired subviews. /// ContentView that holds the any desired subviews.
open private(set) var contentView: View! open private(set) lazy var contentView: UIView = UIView()
/// Left side UIControls. /// Left side UIControls.
open var leftControls = [UIView]() { open var leftControls = [UIView]() {
...@@ -197,6 +197,9 @@ open class ControlView: View { ...@@ -197,6 +197,9 @@ open class ControlView: View {
grid.views.append(v) grid.views.append(v)
} }
grid.commit()
contentView.grid.begin()
if .center == contentViewAlignment { if .center == contentViewAlignment {
if lc < rc { if lc < rc {
contentView.grid.columns = columns - 2 * rc contentView.grid.columns = columns - 2 * rc
...@@ -208,8 +211,7 @@ open class ControlView: View { ...@@ -208,8 +211,7 @@ open class ControlView: View {
} else { } else {
contentView.grid.columns = columns - lc - rc contentView.grid.columns = columns - lc - rc
} }
contentView.grid.commit()
grid.commit()
} }
} }
...@@ -230,7 +232,6 @@ open class ControlView: View { ...@@ -230,7 +232,6 @@ open class ControlView: View {
/// Prepares the contentView. /// Prepares the contentView.
private func prepareContentView() { private func prepareContentView() {
contentView = View()
contentView.backgroundColor = nil contentView.backgroundColor = nil
} }
} }
...@@ -134,7 +134,7 @@ public class Grid { ...@@ -134,7 +134,7 @@ public class Grid {
public private(set) var axis: GridAxis! public private(set) var axis: GridAxis!
/// Preset inset value for grid. /// Preset inset value for grid.
public var layoutEdgeInsetsPreset: EdgeInsetsPreset = .none { public var layoutEdgeInsetsPreset = EdgeInsetsPreset.none {
didSet { didSet {
layoutEdgeInsets = EdgeInsetsPresetToValue(preset: contentEdgeInsetsPreset) layoutEdgeInsets = EdgeInsetsPresetToValue(preset: contentEdgeInsetsPreset)
} }
...@@ -148,7 +148,7 @@ public class Grid { ...@@ -148,7 +148,7 @@ 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 {
contentEdgeInsets = EdgeInsetsPresetToValue(preset: contentEdgeInsetsPreset) contentEdgeInsets = EdgeInsetsPresetToValue(preset: contentEdgeInsetsPreset)
} }
...@@ -218,38 +218,38 @@ public class Grid { ...@@ -218,38 +218,38 @@ public class Grid {
var i: Int = 0 var i: Int = 0
for child in views { for child in views {
guard let parent = context else { guard let canvas = context else {
return return
} }
if parent != child.superview { canvas.layoutIfNeeded()
if canvas != child.superview {
child.removeFromSuperview() child.removeFromSuperview()
parent.addSubview(child) canvas.addSubview(child)
} }
parent.layoutIfNeeded()
switch axis.direction { switch axis.direction {
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 - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right + interimSpace) / CGFloat(axis.columns) let w = (canvas.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right + interimSpace) / CGFloat(axis.columns)
child.x = CGFloat(i + n + co) * w + contentEdgeInsets.left + layoutEdgeInsets.left child.x = CGFloat(i + n + co) * w + contentEdgeInsets.left + layoutEdgeInsets.left
child.y = contentEdgeInsets.top + layoutEdgeInsets.top child.y = contentEdgeInsets.top + layoutEdgeInsets.top
child.width = w * CGFloat(c) - interimSpace child.width = w * CGFloat(c) - interimSpace
child.height = parent.bounds.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom child.height = canvas.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 - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom + interimSpace) / CGFloat(axis.rows) let h = (canvas.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom + interimSpace) / CGFloat(axis.rows)
child.x = contentEdgeInsets.left + layoutEdgeInsets.left child.x = contentEdgeInsets.left + layoutEdgeInsets.left
child.y = CGFloat(i + n + ro) * h + contentEdgeInsets.top + layoutEdgeInsets.top child.y = CGFloat(i + n + ro) * h + contentEdgeInsets.top + layoutEdgeInsets.top
child.width = parent.bounds.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right child.width = canvas.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
...@@ -259,8 +259,8 @@ public class Grid { ...@@ -259,8 +259,8 @@ 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 - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right + interimSpace) / CGFloat(axis.columns) let w = (canvas.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right + interimSpace) / CGFloat(axis.columns)
let h = (parent.bounds.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom + interimSpace) / CGFloat(axis.rows) let h = (canvas.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom + interimSpace) / CGFloat(axis.rows)
child.x = CGFloat(co) * w + contentEdgeInsets.left + layoutEdgeInsets.left child.x = CGFloat(co) * w + contentEdgeInsets.left + layoutEdgeInsets.left
child.y = CGFloat(ro) * h + contentEdgeInsets.top + layoutEdgeInsets.top child.y = CGFloat(ro) * h + contentEdgeInsets.top + layoutEdgeInsets.top
......
...@@ -230,6 +230,11 @@ open class NavigationBar: UINavigationBar { ...@@ -230,6 +230,11 @@ open class NavigationBar: UINavigationBar {
item.titleView!.grid.views.append(v) item.titleView!.grid.views.append(v)
} }
item.titleView!.grid.interimSpace = interimSpace
item.titleView!.grid.contentEdgeInsets = contentEdgeInsets
item.titleView!.grid.commit()
item.contentView.grid.begin()
if .center == item.contentViewAlignment { if .center == item.contentViewAlignment {
if lc < rc { if lc < rc {
item.contentView.grid.columns = columns - 2 * rc item.contentView.grid.columns = columns - 2 * rc
...@@ -241,10 +246,7 @@ open class NavigationBar: UINavigationBar { ...@@ -241,10 +246,7 @@ open class NavigationBar: UINavigationBar {
} else { } else {
item.contentView.grid.columns = columns - lc - rc item.contentView.grid.columns = columns - lc - rc
} }
item.contentView.grid.commit()
item.titleView!.grid.interimSpace = interimSpace
item.titleView!.grid.contentEdgeInsets = contentEdgeInsets
item.titleView!.grid.commit()
// contentView alignment. // contentView alignment.
if nil != item.title && "" != item.title { if nil != item.title && "" != item.title {
...@@ -279,8 +281,6 @@ open class NavigationBar: UINavigationBar { ...@@ -279,8 +281,6 @@ open class NavigationBar: UINavigationBar {
} else { } else {
item.detailLabel.removeFromSuperview() item.detailLabel.removeFromSuperview()
} }
item.contentView.grid.reload()
} }
} }
......
...@@ -55,10 +55,18 @@ public class NavigationItem: NSObject { ...@@ -55,10 +55,18 @@ public class NavigationItem: NSObject {
public private(set) lazy var detailLabel = UILabel() public private(set) lazy var detailLabel = UILabel()
/// Left controls. /// Left controls.
public var leftControls = [UIView]() public var leftControls = [UIView]() {
didSet {
navigationBar?.layoutSubviews()
}
}
/// Right controls. /// Right controls.
public var rightControls = [UIView]() public var rightControls = [UIView]() {
didSet {
navigationBar?.layoutSubviews()
}
}
public var navigationBar: NavigationBar? { public var navigationBar: NavigationBar? {
return contentView.superview?.superview as? NavigationBar return contentView.superview?.superview as? NavigationBar
......
...@@ -135,8 +135,6 @@ open class Toolbar: BarView { ...@@ -135,8 +135,6 @@ open class Toolbar: BarView {
} else { } else {
detailLabel.removeFromSuperview() detailLabel.removeFromSuperview()
} }
contentView.grid.reload()
} }
} }
......
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