Skip to content

Commit

Permalink
Merge pull request #100 from aocenas/swift-box-update-fix
Browse files Browse the repository at this point in the history
Swift box update fix
  • Loading branch information
joshaber committed Dec 17, 2015
2 parents 1240694 + 7f3ab26 commit 67bef11
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 36 deletions.
4 changes: 2 additions & 2 deletions Cartfile.private
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "Quick/Quick" "v0.6.0"
github "Quick/Nimble" "v2.0.0-rc.3"
github "Quick/Quick" "v0.8.0"
github "Quick/Nimble" "v3.0.0"
6 changes: 3 additions & 3 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
github "Quick/Nimble" "v2.0.0-rc.3"
github "Quick/Quick" "v0.6.0"
github "joshaber/SwiftBox" "6ec5ef5492c411163d34cd46c46434bbd2181faf"
github "Quick/Nimble" "v3.0.0"
github "Quick/Quick" "v0.8.0"
github "joshaber/SwiftBox" "c316daebb98237a0c20c5fc7cb92028f44809861"
19 changes: 17 additions & 2 deletions Few-Mac/Label.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,23 @@ public class Label: Element {

public override func assembleLayoutNode() -> Node {
let childNodes = children.map { $0.assembleLayoutNode() }
return Node(size: frame.size, children: childNodes, direction: direction, margin: marginWithPlatformSpecificAdjustments, padding: paddingWithPlatformSpecificAdjustments, wrap: wrap, justification: justification, selfAlignment: selfAlignment, childAlignment: childAlignment, flex: flex) { w in
estimateStringSize(self.attributedString, maxSize: CGSize(width: w.isNaN ? ABigDimension : w, height: ABigDimension))
return Node(
size: frame.size,
children: childNodes,
flexDirection: flexDirection,
margin: marginWithPlatformSpecificAdjustments,
padding: paddingWithPlatformSpecificAdjustments,
wrap: wrap,
justification: justification,
selfAlignment: selfAlignment,
childAlignment: childAlignment,
flex: flex
) { w in
estimateStringSize(
self.attributedString,
maxSize: CGSize(
width: w.isNaN ? ABigDimension : w,
height: ABigDimension))
}
}
}
20 changes: 18 additions & 2 deletions Few-iOS/Label.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,24 @@ public class Label: Element {

public override func assembleLayoutNode() -> Node {
let childNodes = children.map { $0.assembleLayoutNode() }
return Node(size: frame.size, children: childNodes, direction: direction, margin: marginWithPlatformSpecificAdjustments, padding: paddingWithPlatformSpecificAdjustments, wrap: wrap, justification: justification, selfAlignment: selfAlignment, childAlignment: childAlignment, flex: flex) { w in
estimateStringSize(self.attributedString, maxSize: CGSize(width: w.isNaN ? ABigDimension : w, height: ABigDimension), numberOfLines: self.numberOfLines)
return Node(
size: frame.size,
children: childNodes,
flexDirection: flexDirection,
margin: marginWithPlatformSpecificAdjustments,
padding: paddingWithPlatformSpecificAdjustments,
wrap: wrap,
justification: justification,
selfAlignment: selfAlignment,
childAlignment: childAlignment,
flex: flex
) { w in
estimateStringSize(
self.attributedString,
maxSize: CGSize(
width: w.isNaN ? ABigDimension : w,
height: ABigDimension),
numberOfLines: self.numberOfLines)
}
}
}
43 changes: 34 additions & 9 deletions FewCore/Element.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ public class Element {
public var children: [Element] {
didSet {
#if os(OSX)
if direction == .Column {
if flexDirection == .Column {
children = children.reverse()
}
#endif
}
}

#if os(OSX)
public var direction: Direction {
public var flexDirection: FlexDirection {
didSet {
if direction != oldValue {
if flexDirection != oldValue {
children = children.reverse()
}
}
}
#else
public var direction: Direction
public var flexDirection: FlexDirection
#endif

public var margin: Edges
Expand All @@ -66,14 +66,29 @@ public class Element {
/// Should the input make itself the focus after it's been realized?
public var autofocus: Bool

public init(frame: CGRect = CGRect(x: 0, y: 0, width: Node.Undefined, height: Node.Undefined), key: String? = nil, hidden: Bool = false, alpha: CGFloat = 1, autofocus: Bool = false, children: [Element] = [], direction: Direction = .Row, margin: Edges = Edges(), padding: Edges = Edges(), wrap: Bool = false, justification: Justification = .FlexStart, selfAlignment: SelfAlignment = .Auto, childAlignment: ChildAlignment = .Stretch, flex: CGFloat = 0) {
public init(
frame: CGRect = CGRect(x: 0, y: 0, width: Node.Undefined, height: Node.Undefined),
key: String? = nil,
hidden: Bool = false,
alpha: CGFloat = 1,
autofocus: Bool = false,
children: [Element] = [],
flexDirection: FlexDirection = .Row,
margin: Edges = Edges(),
padding: Edges = Edges(),
wrap: Bool = false,
justification: Justification = .FlexStart,
selfAlignment: SelfAlignment = .Auto,
childAlignment: ChildAlignment = .Stretch,
flex: CGFloat = 0
) {
self.frame = frame
self.key = key
self.hidden = hidden
self.alpha = alpha
self.autofocus = autofocus
self.children = children
self.direction = direction
self.flexDirection = flexDirection
self.margin = margin
self.padding = padding
self.wrap = wrap
Expand Down Expand Up @@ -193,7 +208,17 @@ public class Element {
public func assembleLayoutNode() -> Node {
let childNodes = children.map { $0.assembleLayoutNode() }

return Node(size: frame.size, children: childNodes, direction: direction, margin: marginWithPlatformSpecificAdjustments, padding: paddingWithPlatformSpecificAdjustments, wrap: wrap, justification: justification, selfAlignment: selfAlignment, childAlignment: childAlignment, flex: flex)
return Node(
size: frame.size,
children: childNodes,
flexDirection: flexDirection,
margin: marginWithPlatformSpecificAdjustments,
padding: paddingWithPlatformSpecificAdjustments,
wrap: wrap,
justification: justification,
selfAlignment: selfAlignment,
childAlignment: childAlignment,
flex: flex)
}

private final func verticallyFlippedEdges(edges: Edges) -> Edges {
Expand Down Expand Up @@ -278,8 +303,8 @@ extension Element {
return self
}

public func direction(d: Direction) -> Self {
direction = d
public func flexDirection(d: FlexDirection) -> Self {
flexDirection = d
return self
}

Expand Down
14 changes: 7 additions & 7 deletions FewDemo-iOS/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func renderCounter(component: Component<Int>, count: Int) -> Element {
// The children should be centered in the view.
.childAlignment(.Center)
// Layout children in a column.
.direction(.Column)
.flexDirection(.Column)
.flex(1)
.children([
Label("You've clicked \(count) times!"),
Expand All @@ -32,15 +32,15 @@ let Counter = { Component(initialState: 0, render: renderCounter) }

private func renderRow1(row: Int) -> Element {
return Element()
.direction(.Row)
.flexDirection(.Row)
.padding(Edges(uniform: 10))
.children([
Image(UIImage(named: "Apple_Swift_Logo.png"))
.size(42, 42)
.selfAlignment(.FlexStart),
Element()
.margin(Edges(left: 10))
.direction(.Column)
.flexDirection(.Column)
.children([
Label("I am a banana.", textColor: UIColor.blackColor(), font: UIFont.systemFontOfSize(18)),
Label("\(row)", textColor: UIColor.greenColor())
Expand All @@ -50,15 +50,15 @@ private func renderRow1(row: Int) -> Element {

private func renderRow2(row: Int) -> Element {
return Element()
.direction(.Row)
.flexDirection(.Row)
.padding(Edges(uniform: 10))
.children([
Image(UIImage(named: "Apple_Swift_Logo.png"))
.size(42, 42)
.selfAlignment(.FlexStart),
Element()
.margin(Edges(left: 10))
.direction(.Column)
.flexDirection(.Column)
.children([
Label("I am a banana.", textColor: UIColor.redColor(), font: UIFont.systemFontOfSize(18)),
Label("\(row)", textColor: UIColor.greenColor())
Expand Down Expand Up @@ -108,7 +108,7 @@ func renderInput(component: Component<String>, state: String) -> Element {
.flex(1)
.children([
View(backgroundColor: UIColor.greenColor())
.direction(.Column)
.flexDirection(.Column)
.children([
View(backgroundColor: UIColor.blueColor(), borderColor: UIColor.blackColor(), borderWidth: 2, cornerRadius: 5)
.margin(Edges(uniform: 10))
Expand Down Expand Up @@ -153,7 +153,7 @@ func renderApp(component: Component<AppState>, state: AppState) -> Element {

let showMore = { component.updateState(toggleDisplay) }
return Element()
.direction(.Column)
.flexDirection(.Column)
.children([
Element()
.children([
Expand Down
4 changes: 2 additions & 2 deletions FewDemo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func renderApp(component: Component<ActiveComponent>, state: ActiveComponent) ->
return Element()
.justification(.Center)
.childAlignment(.Center)
.direction(.Column)
.flexDirection(.Column)
.children([
contentComponent,
CustomButton(title: "Show me more!") {
Expand All @@ -39,7 +39,7 @@ func renderApp(component: Component<ActiveComponent>, state: ActiveComponent) ->
])

// return Element()
// .direction(.Column)
// .flexDirection(.Column)
// .justification(.Center)
// .children([
// Element().height(90).children([
Expand Down
2 changes: 1 addition & 1 deletion FewDemo/Counter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Counter_<LOL>: Component<Int> {
// The children should be centered in the view.
.childAlignment(.Center)
// Layout children in a column.
.direction(.Column)
.flexDirection(.Column)
.children([
Label("You've clicked \(count) times!"),
Button(title: "Click me!", action: {
Expand Down
12 changes: 6 additions & 6 deletions FewDemo/Demo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private func renderInput(component: Component<LoginState>, label: String, secure
}

return Element()
.direction(.Row)
.flexDirection(.Row)
.padding(Edges(bottom: 4))
.children([
Label(label).size(75, 19),
Expand Down Expand Up @@ -80,7 +80,7 @@ private func renderScrollView() -> Element {
keyDown: { _, event in
return keyDown(event, component: component)
})
.direction(.Column)
.flexDirection(.Column)
.children([
Label("\(items.count) \(itemPlurality)"),
TableView(items, selectionChanged: { row in
Expand All @@ -93,7 +93,7 @@ private func renderScrollView() -> Element {

private func renderRow1(row: Int) -> Element {
return Element()
.direction(.Column)
.flexDirection(.Column)
.children([
Label("\(row)"),
Label("I am a banana.", textColor: .blackColor(), font: .systemFontOfSize(18)),
Expand All @@ -103,7 +103,7 @@ private func renderRow1(row: Int) -> Element {

private func renderRow2(row: Int) -> Element {
return Element()
.direction(.Row)
.flexDirection(.Row)
.children([
Image(NSImage(named: NSImageNameApplicationIcon)).size(14, 14),
Label("I am a banana.", textColor: .redColor(), font: .systemFontOfSize(11)),
Expand All @@ -114,7 +114,7 @@ private func renderLogin() -> Element {
return Component(initialState: LoginState()) { component, state in
let loginEnabled = !state.username.isEmpty && !state.password.isEmpty
return Element()
.direction(.Column)
.flexDirection(.Column)
.children([
renderThingy(state.username.utf16.count),
renderInput(component, label: "Username", secure: false) {
Expand Down Expand Up @@ -145,7 +145,7 @@ class Demo_<LOL>: Component<()> {
return Element()
.justification(.Center)
.childAlignment(.Center)
.direction(.Column)
.flexDirection(.Column)
.children([
renderLogin(),
renderScrollView().size(100, 200),
Expand Down
4 changes: 2 additions & 2 deletions FewDemo/TemperatureConverter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private func f2c(f: CGFloat) -> CGFloat {

private func renderLabeledInput(label: String, value: String, autofocus: Bool, fn: String -> ()) -> Element {
return Element()
.direction(.Row)
.flexDirection(.Row)
.padding(Edges(bottom: 4))
.children([
Label(label).width(75),
Expand Down Expand Up @@ -58,7 +58,7 @@ class TemperatureConverter_<LOL>: Component<ConverterState> {
return Element()
.justification(.Center)
.childAlignment(.Center)
.direction(.Column)
.flexDirection(.Column)
.children([
renderLabeledInput("Fahrenheit", value: "\(state.fahrenheit)", autofocus: true) {
if let f = parseFloat($0) {
Expand Down

0 comments on commit 67bef11

Please sign in to comment.