diff --git a/LearnAboutStackViews/LearnAboutStackViews.xcodeproj/project.pbxproj b/LearnAboutStackViews/LearnAboutStackViews.xcodeproj/project.pbxproj index 729a151..6d27213 100644 --- a/LearnAboutStackViews/LearnAboutStackViews.xcodeproj/project.pbxproj +++ b/LearnAboutStackViews/LearnAboutStackViews.xcodeproj/project.pbxproj @@ -11,6 +11,9 @@ FD07155F1F300A6300F7CB7A /* UILayoutConstraintAxis+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD07155E1F300A6300F7CB7A /* UILayoutConstraintAxis+Extensions.swift */; }; FD0715611F300F4100F7CB7A /* UIStackViewDistribution+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD0715601F300F4100F7CB7A /* UIStackViewDistribution+Extensions.swift */; }; FD0715631F3011F100F7CB7A /* UIStackViewAlignment+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD0715621F3011F100F7CB7A /* UIStackViewAlignment+Extensions.swift */; }; + FD0715651F3027D400F7CB7A /* CGFloat+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD0715641F3027D400F7CB7A /* CGFloat+Extensions.swift */; }; + FD96E4201F30DF810008DEE0 /* Bool+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD96E41F1F30DF810008DEE0 /* Bool+Extensions.swift */; }; + FD96E4221F30F3450008DEE0 /* EHPinningOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD96E4211F30F3450008DEE0 /* EHPinningOptions.swift */; }; FDD291411F2E18C2009CC565 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDD291401F2E18C2009CC565 /* AppDelegate.swift */; }; FDD291431F2E18C2009CC565 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDD291421F2E18C2009CC565 /* ViewController.swift */; }; FDD291461F2E18C2009CC565 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FDD291441F2E18C2009CC565 /* Main.storyboard */; }; @@ -38,6 +41,9 @@ FD07155E1F300A6300F7CB7A /* UILayoutConstraintAxis+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UILayoutConstraintAxis+Extensions.swift"; sourceTree = ""; }; FD0715601F300F4100F7CB7A /* UIStackViewDistribution+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIStackViewDistribution+Extensions.swift"; sourceTree = ""; }; FD0715621F3011F100F7CB7A /* UIStackViewAlignment+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIStackViewAlignment+Extensions.swift"; sourceTree = ""; }; + FD0715641F3027D400F7CB7A /* CGFloat+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CGFloat+Extensions.swift"; sourceTree = ""; }; + FD96E41F1F30DF810008DEE0 /* Bool+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Bool+Extensions.swift"; sourceTree = ""; }; + FD96E4211F30F3450008DEE0 /* EHPinningOptions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EHPinningOptions.swift; sourceTree = ""; }; FDD2913D1F2E18C2009CC565 /* LearnAboutStackViews.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LearnAboutStackViews.app; sourceTree = BUILT_PRODUCTS_DIR; }; FDD291401F2E18C2009CC565 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; FDD291421F2E18C2009CC565 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; @@ -104,6 +110,7 @@ FDD2916F1F2E3656009CC565 /* EHStackViewSettingsViewController.swift */, FDD291741F2E7060009CC565 /* EHStackViewSettingsModel.swift */, FD07155C1F2FF3AD00F7CB7A /* EHSelectionViewController.swift */, + FD96E4211F30F3450008DEE0 /* EHPinningOptions.swift */, ); path = LearnAboutStackViews; sourceTree = ""; @@ -149,6 +156,8 @@ FD07155E1F300A6300F7CB7A /* UILayoutConstraintAxis+Extensions.swift */, FD0715601F300F4100F7CB7A /* UIStackViewDistribution+Extensions.swift */, FD0715621F3011F100F7CB7A /* UIStackViewAlignment+Extensions.swift */, + FD0715641F3027D400F7CB7A /* CGFloat+Extensions.swift */, + FD96E41F1F30DF810008DEE0 /* Bool+Extensions.swift */, ); name = Extensions; sourceTree = ""; @@ -237,7 +246,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + FD0715651F3027D400F7CB7A /* CGFloat+Extensions.swift in Sources */, FDD291431F2E18C2009CC565 /* ViewController.swift in Sources */, + FD96E4221F30F3450008DEE0 /* EHPinningOptions.swift in Sources */, FDD291701F2E3656009CC565 /* EHStackViewSettingsViewController.swift in Sources */, FDD291411F2E18C2009CC565 /* AppDelegate.swift in Sources */, FD07155D1F2FF3AD00F7CB7A /* EHSelectionViewController.swift in Sources */, @@ -247,6 +258,7 @@ FD0715611F300F4100F7CB7A /* UIStackViewDistribution+Extensions.swift in Sources */, FD07155F1F300A6300F7CB7A /* UILayoutConstraintAxis+Extensions.swift in Sources */, FDD291751F2E7060009CC565 /* EHStackViewSettingsModel.swift in Sources */, + FD96E4201F30DF810008DEE0 /* Bool+Extensions.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/LearnAboutStackViews/LearnAboutStackViews.xcodeproj/project.xcworkspace/xcuserdata/ehyche.xcuserdatad/UserInterfaceState.xcuserstate b/LearnAboutStackViews/LearnAboutStackViews.xcodeproj/project.xcworkspace/xcuserdata/ehyche.xcuserdatad/UserInterfaceState.xcuserstate index f32142b..db66648 100644 Binary files a/LearnAboutStackViews/LearnAboutStackViews.xcodeproj/project.xcworkspace/xcuserdata/ehyche.xcuserdatad/UserInterfaceState.xcuserstate and b/LearnAboutStackViews/LearnAboutStackViews.xcodeproj/project.xcworkspace/xcuserdata/ehyche.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/LearnAboutStackViews/LearnAboutStackViews/Bool+Extensions.swift b/LearnAboutStackViews/LearnAboutStackViews/Bool+Extensions.swift new file mode 100644 index 0000000..445d39c --- /dev/null +++ b/LearnAboutStackViews/LearnAboutStackViews/Bool+Extensions.swift @@ -0,0 +1,46 @@ +// +// Bool+Extensions.swift +// LearnAboutStackViews +// +// Created by Eric Hyche on 8/1/17. +// Copyright © 2017 HeirPlay Software. All rights reserved. +// + +import Foundation + +extension Bool: EHMultipleChoiceDataSource { + + func title() -> String { + return "Boolean Selection" + } + + func choiceCount() -> Int { + return 2 + } + + func choiceText(atIndex: Int) -> String { + let indexChoice: Bool = (atIndex == 0 ? true : false) + return "\(indexChoice)" + } + + func isChoiceSelected(atIndex: Int) -> Bool { + let indexChoice: Bool = (atIndex == 0 ? true : false) + return self == indexChoice + } + + func canSelectMultipleChoices() -> Bool { + return false + } + + func canSelectChoice(atIndex: Int) -> Bool { + return true + } + + mutating func setChoice(selected: Bool, atIndex: Int) { + if atIndex < choiceCount() && selected { + let indexChoice: Bool = (atIndex == 0 ? true : false) + self = indexChoice + } + } + +} diff --git a/LearnAboutStackViews/LearnAboutStackViews/CGFloat+Extensions.swift b/LearnAboutStackViews/LearnAboutStackViews/CGFloat+Extensions.swift new file mode 100644 index 0000000..c93f074 --- /dev/null +++ b/LearnAboutStackViews/LearnAboutStackViews/CGFloat+Extensions.swift @@ -0,0 +1,48 @@ +// +// CGFloat+Extensions.swift +// LearnAboutStackViews +// +// Created by Eric Hyche on 7/31/17. +// Copyright © 2017 HeirPlay Software. All rights reserved. +// + +import UIKit + +extension CGFloat: EHMultipleChoiceDataSource { + + static let numberOfChoices = 25 + static let choiceDelta: CGFloat = 5.0 + + func title() -> String { + return "CGFloat Selection" + } + + func choiceCount() -> Int { + return CGFloat.numberOfChoices + } + + func choiceText(atIndex: Int) -> String { + return "\(CGFloat(atIndex) * CGFloat.choiceDelta)" + } + + func isChoiceSelected(atIndex: Int) -> Bool { + let indexValue = CGFloat(atIndex) * CGFloat.choiceDelta + return indexValue == self + } + + func canSelectMultipleChoices() -> Bool { + return false + } + + func canSelectChoice(atIndex: Int) -> Bool { + return true + } + + mutating func setChoice(selected: Bool, atIndex: Int) { + if atIndex < choiceCount() && selected { + let indexValue = CGFloat(atIndex) * CGFloat.choiceDelta + self = indexValue + } + } + +} diff --git a/LearnAboutStackViews/LearnAboutStackViews/EHPinningOptions.swift b/LearnAboutStackViews/LearnAboutStackViews/EHPinningOptions.swift new file mode 100644 index 0000000..3f450b4 --- /dev/null +++ b/LearnAboutStackViews/LearnAboutStackViews/EHPinningOptions.swift @@ -0,0 +1,114 @@ +// +// EHPinningOptions.swift +// LearnAboutStackViews +// +// Created by Eric Hyche on 8/1/17. +// Copyright © 2017 HeirPlay Software. All rights reserved. +// + +import UIKit + +struct EHPinningOptions: OptionSet { + let rawValue: Int + + static let none = EHPinningOptions(rawValue: 0) + static let leading = EHPinningOptions(rawValue: 1 << 0) + static let centerX = EHPinningOptions(rawValue: 1 << 1) + static let trailing = EHPinningOptions(rawValue: 1 << 2) + static let top = EHPinningOptions(rawValue: 1 << 3) + static let centerY = EHPinningOptions(rawValue: 1 << 4) + static let bottom = EHPinningOptions(rawValue: 1 << 5) + + var textDescription: String { + get { + return EHPinningOptions.toString(options: self) + } + } + + static func toString(options: EHPinningOptions) -> String { + var optionStrings = [String]() + + if options.contains(.leading) { + optionStrings.append("leading") + } + if options.contains(.centerX) { + optionStrings.append("centerX") + } + if options.contains(.trailing) { + optionStrings.append("trailing") + } + if options.contains(.top) { + optionStrings.append("top") + } + if options.contains(.centerY) { + optionStrings.append("centerY") + } + if options.contains(.bottom) { + optionStrings.append("bottom") + } + + var desc = "" + if optionStrings.isEmpty { + desc = "none" + } else if optionStrings.count == 1 { + desc = optionStrings[0] + } else { + desc = "\(optionStrings)" + } + + return desc + } + +} + +extension EHPinningOptions: EHMultipleChoiceDataSource { + + func title() -> String { + return "Pinning Options" + } + + func choiceCount() -> Int { + return 6 + } + + func choiceText(atIndex: Int) -> String { + var text = "unknown" + + if atIndex < choiceCount() { + let option = EHPinningOptions(rawValue: (1 << atIndex)) + text = option.textDescription + } + + return text + } + + func isChoiceSelected(atIndex: Int) -> Bool { + var selected = false + + if atIndex < choiceCount() { + selected = contains(EHPinningOptions(rawValue: (1 << atIndex))) + } + + return selected + } + + func canSelectMultipleChoices() -> Bool { + return true + } + + func canSelectChoice(atIndex: Int) -> Bool { + return true + } + + mutating func setChoice(selected: Bool, atIndex: Int) { + if atIndex < choiceCount() { + let option = EHPinningOptions(rawValue: (1 << atIndex)) + if selected { + insert(option) + } else { + remove(option) + } + } + } + +} diff --git a/LearnAboutStackViews/LearnAboutStackViews/EHStackViewSettingsModel.swift b/LearnAboutStackViews/LearnAboutStackViews/EHStackViewSettingsModel.swift index 5db8969..b2cff09 100644 --- a/LearnAboutStackViews/LearnAboutStackViews/EHStackViewSettingsModel.swift +++ b/LearnAboutStackViews/LearnAboutStackViews/EHStackViewSettingsModel.swift @@ -11,18 +11,6 @@ import UIKit typealias EHStackViewSettingsAnimationBlock = () -> Void typealias EHStackViewSettingsCompletionBlock = (_ finished: Bool) -> Void -struct EHPinningOptions: OptionSet { - let rawValue: Int - - static let none = EHPinningOptions(rawValue: 0) - static let top = EHPinningOptions(rawValue: 1 << 0) - static let centerY = EHPinningOptions(rawValue: 1 << 1) - static let bottom = EHPinningOptions(rawValue: 1 << 2) - static let leading = EHPinningOptions(rawValue: 1 << 3) - static let centerX = EHPinningOptions(rawValue: 1 << 4) - static let trailing = EHPinningOptions(rawValue: 1 << 5) -} - struct EHStackViewSettingsModel { var axis: UILayoutConstraintAxis var distribution: UIStackViewDistribution @@ -114,8 +102,9 @@ extension EHStackViewSettingsModel { static func computePinning(forStackView stackView: UIStackView, inContainerView containerView: UIView) -> EHPinningOptions { // Get all the contraints on the stackView var pinning: EHPinningOptions = EHPinningOptions.none - let constraints = stackView.constraints + let constraints = containerView.constraints for constraint in constraints { + print("constraint=\(constraint)") // This has to be a constraint between two views if let firstView = constraint.firstItem as? UIView, let secondView = constraint.secondItem as? UIView { @@ -129,8 +118,10 @@ extension EHStackViewSettingsModel { stackViewAttribute = constraint.secondAttribute containerViewAttribute = constraint.firstAttribute } - let pinOption = pinningOption(stackViewAttribute: stackViewAttribute, containerViewAttribute: containerViewAttribute) - pinning.update(with: pinOption) + if stackViewAttribute != .notAnAttribute && containerViewAttribute != .notAnAttribute { + let pinOption = pinningOption(stackViewAttribute: stackViewAttribute, containerViewAttribute: containerViewAttribute) + pinning.insert(pinOption) + } } } return pinning diff --git a/LearnAboutStackViews/LearnAboutStackViews/EHStackViewSettingsViewController.swift b/LearnAboutStackViews/LearnAboutStackViews/EHStackViewSettingsViewController.swift index 7a6ed9d..5bdb959 100644 --- a/LearnAboutStackViews/LearnAboutStackViews/EHStackViewSettingsViewController.swift +++ b/LearnAboutStackViews/LearnAboutStackViews/EHStackViewSettingsViewController.swift @@ -39,13 +39,20 @@ class EHStackViewSettingsViewController: UIViewController { // MARK: - Internal properties enum RowContent: Int { - case header + case paramsHeader case axis case distribution case alignment case spacing case isBaselineRelativeArrangement case isLayoutMarginsRelativeArrangement + case layoutMarginsHeader + case layoutMarginsLeft + case layoutMarginsTop + case layoutMarginsRight + case layoutMarginsBottom + case pinningHeader + case pinningValue } private let initialSettings: EHStackViewSettingsModel @@ -73,7 +80,7 @@ class EHStackViewSettingsViewController: UIViewController { displayStackView.distribution = .fill displayStackView.alignment = .fill displayStackView.isLayoutMarginsRelativeArrangement = true - displayStackView.layoutMargins = UIEdgeInsetsMake(0.0, 10.0, 0.0, 10.0) + displayStackView.layoutMargins = UIEdgeInsetsMake(20.0, 10.0, 20.0, 10.0) displayStackView.spacing = 8.0 scrollView.addSubview(displayStackView) @@ -96,23 +103,34 @@ class EHStackViewSettingsViewController: UIViewController { view.removeFromSuperview() } - displayStackView.addArrangedSubview(headerLabel(withText: "UIStackView parameters", content: .header)) + displayStackView.addArrangedSubview(headerLabel(withText: "Parameters", content: .paramsHeader)) displayStackView.addArrangedSubview(nameValueView(withName: "axis", andValue: currentSettings.axis.textDescription, content: .axis)) displayStackView.addArrangedSubview(nameValueView(withName: "distribution", andValue: currentSettings.distribution.textDescription, content: .distribution)) displayStackView.addArrangedSubview(nameValueView(withName: "alignment", andValue: currentSettings.alignment.textDescription, content: .alignment)) displayStackView.addArrangedSubview(nameValueView(withName: "spacing", andValue: "\(currentSettings.spacing)", content: .spacing)) displayStackView.addArrangedSubview(nameBooleanValueView(withName: "isBaselineRelativeArrangement", andValue: currentSettings.isBaselineRelativeArrangement, content: .isBaselineRelativeArrangement)) displayStackView.addArrangedSubview(nameBooleanValueView(withName: "isLayoutMarginsRelativeArrangement", andValue: currentSettings.isLayoutMarginsRelativeArrangement, content: .isLayoutMarginsRelativeArrangement)) + displayStackView.addArrangedSubview(headerLabel(withText: "layoutMargins", content: .layoutMarginsHeader)) + displayStackView.addArrangedSubview(nameValueView(withName: "left", andValue: "\(currentSettings.layoutMargins.left)", content: .layoutMarginsLeft)) + displayStackView.addArrangedSubview(nameValueView(withName: "top", andValue: "\(currentSettings.layoutMargins.top)", content: .layoutMarginsTop)) + displayStackView.addArrangedSubview(nameValueView(withName: "right", andValue: "\(currentSettings.layoutMargins.right)", content: .layoutMarginsRight)) + displayStackView.addArrangedSubview(nameValueView(withName: "bottom", andValue: "\(currentSettings.layoutMargins.bottom)", content: .layoutMarginsBottom)) + displayStackView.addArrangedSubview(headerLabel(withText: "Pinning", content: .pinningHeader)) + displayStackView.addArrangedSubview(nameValueView(withName: "Anchors", andValue: currentSettings.pinning.textDescription, content: .pinningValue)) } private func updateViewState() { - updateRow(content: .header) + // Headers are not updated since they don't change updateRow(content: .axis) updateRow(content: .distribution) updateRow(content: .alignment) updateRow(content: .spacing) updateRow(content: .isBaselineRelativeArrangement) updateRow(content: .isLayoutMarginsRelativeArrangement) + updateRow(content: .layoutMarginsLeft) + updateRow(content: .layoutMarginsTop) + updateRow(content: .layoutMarginsRight) + updateRow(content: .layoutMarginsBottom) } private func updateRow(content: RowContent) { @@ -126,7 +144,6 @@ class EHStackViewSettingsViewController: UIViewController { rowValueLabel.text = currentSettings.axis.textDescription rowValueLabel.textColor = textColor } - break case .distribution: if rowStackView.arrangedSubviews.count >= 2, let rowValueLabel = rowStackView.arrangedSubviews[1] as? UILabel { @@ -134,7 +151,6 @@ class EHStackViewSettingsViewController: UIViewController { rowValueLabel.text = currentSettings.distribution.textDescription rowValueLabel.textColor = textColor } - break case .alignment: if rowStackView.arrangedSubviews.count >= 2, let rowValueLabel = rowStackView.arrangedSubviews[1] as? UILabel { @@ -142,7 +158,6 @@ class EHStackViewSettingsViewController: UIViewController { rowValueLabel.text = currentSettings.alignment.textDescription rowValueLabel.textColor = textColor } - break case .spacing: if rowStackView.arrangedSubviews.count >= 2, let rowValueLabel = rowStackView.arrangedSubviews[1] as? UILabel { @@ -150,18 +165,51 @@ class EHStackViewSettingsViewController: UIViewController { rowValueLabel.text = "\(currentSettings.spacing)" rowValueLabel.textColor = textColor } - break case .isBaselineRelativeArrangement: if rowStackView.arrangedSubviews.count >= 2, let rowSwitch = rowStackView.arrangedSubviews[1] as? UISwitch { rowSwitch.isOn = currentSettings.isBaselineRelativeArrangement } - break case .isLayoutMarginsRelativeArrangement: if rowStackView.arrangedSubviews.count >= 2, let rowSwitch = rowStackView.arrangedSubviews[1] as? UISwitch { rowSwitch.isOn = currentSettings.isLayoutMarginsRelativeArrangement } + case .layoutMarginsLeft: + if rowStackView.arrangedSubviews.count >= 2, + let rowValueLabel = rowStackView.arrangedSubviews[1] as? UILabel { + let textColor = (currentSettings.layoutMargins.left == initialSettings.layoutMargins.left ? UIColor.blue : UIColor.red) + rowValueLabel.text = "\(currentSettings.layoutMargins.left)" + rowValueLabel.textColor = textColor + } + case .layoutMarginsTop: + if rowStackView.arrangedSubviews.count >= 2, + let rowValueLabel = rowStackView.arrangedSubviews[1] as? UILabel { + let textColor = (currentSettings.layoutMargins.top == initialSettings.layoutMargins.top ? UIColor.blue : UIColor.red) + rowValueLabel.text = "\(currentSettings.layoutMargins.top)" + rowValueLabel.textColor = textColor + } + case .layoutMarginsRight: + if rowStackView.arrangedSubviews.count >= 2, + let rowValueLabel = rowStackView.arrangedSubviews[1] as? UILabel { + let textColor = (currentSettings.layoutMargins.right == initialSettings.layoutMargins.right ? UIColor.blue : UIColor.red) + rowValueLabel.text = "\(currentSettings.layoutMargins.right)" + rowValueLabel.textColor = textColor + } + case .layoutMarginsBottom: + if rowStackView.arrangedSubviews.count >= 2, + let rowValueLabel = rowStackView.arrangedSubviews[1] as? UILabel { + let textColor = (currentSettings.layoutMargins.bottom == initialSettings.layoutMargins.bottom ? UIColor.blue : UIColor.red) + rowValueLabel.text = "\(currentSettings.layoutMargins.bottom)" + rowValueLabel.textColor = textColor + } + case .pinningValue: + if rowStackView.arrangedSubviews.count >= 2, + let rowValueLabel = rowStackView.arrangedSubviews[1] as? UILabel { + let textColor = (currentSettings.pinning == initialSettings.pinning ? UIColor.blue : UIColor.red) + rowValueLabel.text = currentSettings.pinning.textDescription + rowValueLabel.textColor = textColor + } break default: break @@ -256,7 +304,6 @@ class EHStackViewSettingsViewController: UIViewController { self?.navigationController?.popViewController(animated: true) } navigationController?.pushViewController(axisController, animated: true) - break case .distribution: let distController = EHMultipleChoiceViewController(withDataSource: currentSettings.distribution) distController.updateBlock = { [weak self] (dataSource) in @@ -267,7 +314,6 @@ class EHStackViewSettingsViewController: UIViewController { self?.navigationController?.popViewController(animated: true) } navigationController?.pushViewController(distController, animated: true) - break case .alignment: let alignController = EHMultipleChoiceViewController(withDataSource: currentSettings.alignment) alignController.updateBlock = { [weak self] (dataSource) in @@ -278,13 +324,72 @@ class EHStackViewSettingsViewController: UIViewController { self?.navigationController?.popViewController(animated: true) } navigationController?.pushViewController(alignController, animated: true) - break case .spacing: - break + let spacingController = EHMultipleChoiceViewController(withDataSource: currentSettings.spacing) + spacingController.updateBlock = { [weak self] (dataSource) in + if let updatedSpacing = dataSource as? CGFloat { + self?.currentSettings.spacing = updatedSpacing + } + self?.updateRow(content: rowEnum) + self?.navigationController?.popViewController(animated: true) + } + navigationController?.pushViewController(spacingController, animated: true) case .isLayoutMarginsRelativeArrangement: - break + currentSettings.isLayoutMarginsRelativeArrangement = !currentSettings.isLayoutMarginsRelativeArrangement + updateRow(content: rowEnum) case .isBaselineRelativeArrangement: - break + currentSettings.isBaselineRelativeArrangement = !currentSettings.isBaselineRelativeArrangement + updateRow(content: rowEnum) + case .layoutMarginsLeft: + let marginController = EHMultipleChoiceViewController(withDataSource: currentSettings.layoutMargins.left) + marginController.updateBlock = { [weak self] (dataSource) in + if let updatedMargin = dataSource as? CGFloat { + self?.currentSettings.layoutMargins.left = updatedMargin + } + self?.updateRow(content: rowEnum) + self?.navigationController?.popViewController(animated: true) + } + navigationController?.pushViewController(marginController, animated: true) + case .layoutMarginsTop: + let marginController = EHMultipleChoiceViewController(withDataSource: currentSettings.layoutMargins.top) + marginController.updateBlock = { [weak self] (dataSource) in + if let updatedMargin = dataSource as? CGFloat { + self?.currentSettings.layoutMargins.top = updatedMargin + } + self?.updateRow(content: rowEnum) + self?.navigationController?.popViewController(animated: true) + } + navigationController?.pushViewController(marginController, animated: true) + case .layoutMarginsRight: + let marginController = EHMultipleChoiceViewController(withDataSource: currentSettings.layoutMargins.right) + marginController.updateBlock = { [weak self] (dataSource) in + if let updatedMargin = dataSource as? CGFloat { + self?.currentSettings.layoutMargins.right = updatedMargin + } + self?.updateRow(content: rowEnum) + self?.navigationController?.popViewController(animated: true) + } + navigationController?.pushViewController(marginController, animated: true) + case .layoutMarginsBottom: + let marginController = EHMultipleChoiceViewController(withDataSource: currentSettings.layoutMargins.bottom) + marginController.updateBlock = { [weak self] (dataSource) in + if let updatedMargin = dataSource as? CGFloat { + self?.currentSettings.layoutMargins.bottom = updatedMargin + } + self?.updateRow(content: rowEnum) + self?.navigationController?.popViewController(animated: true) + } + navigationController?.pushViewController(marginController, animated: true) + case .pinningValue: + let pinningController = EHMultipleChoiceViewController(withDataSource: currentSettings.pinning) + pinningController.updateBlock = { [weak self] (dataSource) in + if let updatedPinning = dataSource as? EHPinningOptions { + self?.currentSettings.pinning = updatedPinning + } + self?.updateRow(content: rowEnum) + self?.navigationController?.popViewController(animated: true) + } + navigationController?.pushViewController(pinningController, animated: true) default: break }