-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.fs
More file actions
160 lines (144 loc) · 4.65 KB
/
Program.fs
File metadata and controls
160 lines (144 loc) · 4.65 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
module Program
open System
open FSharpQt
open BuilderNode
open Reactor
open FSharpQt.Widgets
open BoxLayout
open GroupBox
open PushButton
open MainWindow
open WindowSet
open Tabs.Counter
open Tabs.DropTesting
open Tabs.PathStroking.PathStroking
open Tabs.TempConverter
open Tabs.FlightBooker
open Tabs.TimerPage
open Tabs.CRUD
open Tabs.CircleDrawer
[<RequireQualifiedAccess>]
type GuiKind =
// 7guis
| Counter
| TempConverter
| FlightBooker
| TimerPage
| CRUD
| CircleDrawer
| Spreadsheet
// misc
| DropTesting
| PathStroking
type GuiInstance = {
Key: int
Kind: GuiKind
}
type State = {
NextKey: int
Instances: GuiInstance list
}
type Msg =
| MainWindowClosed
| LaunchInstance of kind: GuiKind
| InstanceClosed of key: int
let init () =
let nextState = {
NextKey = 1
Instances = []
}
nextState, Cmd.None
let update (state: State) (msg: Msg) =
match msg with
| MainWindowClosed ->
state, Cmd.Signal QuitApplication
| LaunchInstance kind ->
let nextState =
let nextInstances =
let instance =
{ Key = state.NextKey; Kind = kind }
instance :: state.Instances
{ state with Instances = nextInstances; NextKey = state.NextKey + 1 }
nextState, Cmd.None
| InstanceClosed key ->
let nextState =
let nextInstances =
let index =
state.Instances
|> List.findIndex (fun inst -> inst.Key = key)
state.Instances
|> List.removeAt index
{ state with Instances = nextInstances }
nextState, Cmd.None
let view (state: State) =
let topGroup =
let buttons =
[ "Counter", GuiKind.Counter
"TempConv", GuiKind.TempConverter
"FlightBooker", GuiKind.FlightBooker
"Timer", GuiKind.TimerPage
"CRUD", GuiKind.CRUD
"CircleDrawer", GuiKind.CircleDrawer
"Spreadsheet", GuiKind.Spreadsheet ]
|> List.map (fun (name, kind) ->
let enabled =
match kind with
| GuiKind.Spreadsheet -> false
| _ -> true
PushButton(Text = name, Enabled = enabled, OnClicked = LaunchInstance kind))
let items =
buttons
|> List.map BoxItem
let vbox =
VBoxLayout(Items = items)
GroupBox(Title = "7GUIs", Layout = vbox)
let bottomGroup =
let buttons =
[ "DropTesting", GuiKind.DropTesting
"PathStroking", GuiKind.PathStroking ]
|> List.map (fun (name, kind) ->
PushButton(Text = name, OnClicked = LaunchInstance kind))
let items =
buttons
|> List.map BoxItem
let vbox =
VBoxLayout(Items = items)
GroupBox(Title = "Misc", Layout = vbox)
let vbox =
let items = [
// listed explicitly (vs. List.map) to avoid casting to :> IWidgetNode above
BoxItem(topGroup)
BoxItem(bottomGroup)
BoxItem(stretch = 1)
]
VBoxLayout(Items = items)
let mainWindow =
let window =
MainWindow(WindowTitle = "7GUIs in F#/Qt", CentralLayout = vbox, OnWindowClosed = MainWindowClosed)
IntKey 0, window :> IWindowNode<Msg>
let instanceWindows =
state.Instances
|> List.map (fun inst ->
let title, node =
match inst.Kind with
| GuiKind.Counter -> "Counter", Counter() :> ILayoutNode<Msg>
| GuiKind.TempConverter -> "Temperature Converter", TempConverter()
| GuiKind.FlightBooker -> "Flight Booker", FlightBooker()
| GuiKind.TimerPage -> "Timer", TimerPage()
| GuiKind.CRUD -> "CRUD", CRUDPage()
| GuiKind.CircleDrawer -> "Circle Drawer", CircleDrawer()
| GuiKind.Spreadsheet -> failwith "not yet implemented"
| GuiKind.DropTesting -> "Drop Testing", DropTesting()
| GuiKind.PathStroking -> "Path Stroking", PathStroking()
let window =
MainWindow(WindowTitle = title, CentralLayout = node, OnWindowClosed = InstanceClosed inst.Key)
IntKey inst.Key, window :> IWindowNode<Msg>)
WindowSet(Windows = mainWindow :: instanceWindows)
:> IBuilderNode<Msg>
[<EntryPoint>]
[<STAThread>]
let main argv =
use app =
createApplication init update view
app.SetStyle(Fusion)
app.Run argv