-
Notifications
You must be signed in to change notification settings - Fork 39
/
AppDelegate.swift
77 lines (68 loc) · 1.84 KB
/
AppDelegate.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// AppDelegate.swift
// Few
//
// Created by Josh Abernathy on 7/22/14.
// Copyright (c) 2014 Josh Abernathy. All rights reserved.
//
import Cocoa
import Few
enum ActiveComponent {
case Demo
case Converter
case Counter
}
func renderApp(component: Component<ActiveComponent>, state: ActiveComponent) -> Element {
var contentComponent: Element!
switch state {
case .Demo:
contentComponent = Demo()
case .Converter:
contentComponent = TemperatureConverter()
case .Counter:
contentComponent = Counter()
}
return Element()
.justification(.Center)
.childAlignment(.Center)
.direction(.Column)
.children([
contentComponent,
CustomButton(title: "Show me more!") {
component.updateState(toggleDisplay)
}
.margin(Edges(top: 20))
])
// return Element()
// .direction(.Column)
// .justification(.Center)
// .children([
// Element().height(90).children([
// View(backgroundColor: .grayColor()).width(32),
// View(backgroundColor: .blackColor(), cornerRadius: 20).width(40).height(40).margin(Edges(left: -10)).selfAlignment(.Center),
// Element().selfAlignment(.Center).direction(.Column).flex(1).children([
// Label("Lorem Ipsum"),
// Label("Dolor"),
// ]),
// View(backgroundColor: .blackColor()).width(30).height(30).selfAlignment(.Center).margin(Edges(right: 10))
// ])
// ])
}
func toggleDisplay(display: ActiveComponent) -> ActiveComponent {
switch display {
case .Demo:
return .Converter
case .Converter:
return .Counter
case .Counter:
return .Demo
}
}
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
private let appComponent = Component(initialState: .Converter, render: renderApp)
func applicationDidFinishLaunching(notification: NSNotification) {
let contentView = window.contentView as! NSView
appComponent.addToView(contentView)
}
}