-
-
Notifications
You must be signed in to change notification settings - Fork 196
/
Examples.re
407 lines (372 loc) · 9.97 KB
/
Examples.re
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
open Revery;
open ExampleStubs;
module SliderExample = Slider;
module ScrollViewExample = ScrollView;
open Revery.UI;
open Revery.UI.Components;
let bgColor = Color.hex("#212733");
let activeBackgroundColor = Color.hex("#2E3440");
let inactiveBackgroundColor = Color.hex("#272d39");
let selectionHighlight = Color.hex("#90f7ff");
type example = {
name: string,
render: Window.t => element,
source: string,
};
let examples = [
{name: "Animation", render: _w => Hello.render(), source: "Hello.re"},
{
name: "Spring",
render: _w => SpringExample.render(),
source: "SpringExample.re",
},
{
name: "CanQuit",
render: _ => CanQuitExample.render(),
source: "CanQuit.re",
},
{
name: "Button",
render: _ => DefaultButton.render(),
source: "DefaultButton.re",
},
{
name: "Checkbox",
render: _ => CheckboxExample.render(),
source: "CheckboxExample.re",
},
{name: "Slider", render: _ => SliderExample.render(), source: "Slider.re"},
{name: "Border", render: _ => Border.render(), source: "Border.re"},
{
name: "ScrollView",
render: _ => ScrollViewExample.render(),
source: "ScrollView.re",
},
{
name: "Calculator",
render: w => Calculator.render(w),
source: "Calculator.re",
},
{name: "Flexbox", render: _ => Flexbox.render(), source: "Flexbox.re"},
{
name: "Box Shadow",
render: _ => Boxshadow.render(),
source: "Boxshadow.re",
},
{name: "Focus", render: _ => FocusExample.render(), source: "Focus.re"},
{name: "Fonts", render: _ => FontsExample.render(), source: "Fonts.re"},
{
name: "Stopwatch",
render: _ => Stopwatch.render(),
source: "Stopwatch.re",
},
{
name: "Native: File(s)/Folders(s)",
render: _ => NativeFileExample.render(),
source: "NativeFileExample.re",
},
{
name: "Native: Notifications",
render: _ => NativeNotificationExample.render(),
source: "NativeNotificationExample.re",
},
{
name: "Native: Icon Features",
render: w => NativeIconExample.render(w),
source: "NativeIconExample.re",
},
{
name: "Native: OSX Menu",
render: w => NativeMenuExample.render(w),
source: "NativeMenuExample.re",
},
{
name: "Native: Inputs",
render: _ => NativeInputExample.render(),
source: "NativeInputExample.re",
},
{
name: "Input",
render: _ => InputExample.render(),
source: "InputExample.re",
},
{
name: "Radio Button",
render: _ => RadioButtonExample.render(),
source: "RadioButtonExample.re",
},
{
name: "Game Of Life",
render: _ => GameOfLife.render(),
source: "GameOfLife.re",
},
{
name: "Screen Capture",
render: w => ScreenCapture.render(w),
source: "ScreenCapture.re",
},
{
name: "Tree View",
render: w => TreeView.render(w),
source: "TreeView.re",
},
{
name: "Analog Clock",
render: _ => AnalogClock.render(),
source: "AnalogClock.re",
},
{
name: "TodoMVC",
render: _ => TodoExample.render(),
source: "TodoExample.re",
},
{
name: "Dropdown",
render: _ => DropdownExample.render(),
source: "DropdownExample.re",
},
{
name: "Text",
render: _w => TextExample.render(),
source: "TextExample.re",
},
{
name: "Hover Example",
render: _ => HoverExample.render(),
source: "HoverExample.re",
},
{
name: "Canvas Example",
render: _ => CanvasExample.render(),
source: "CanvasExample.re",
},
{
name: "SVG Example",
render: _ => SVGExample.render(),
source: "SVGExample.re",
},
{
name: "Zoom Example",
render: _ => ZoomExample.render(),
source: "ZoomExample.re",
},
{
name: "Nested Clickables",
render: _ => NestedClickable.render(),
source: "NestedClickable.re",
},
{
name: "File Drag & Drop",
render: _ => FileDragAndDrop.render(),
source: "FileDragAndDrop.re",
},
{
name: "Rich Text Example",
render: _ => RichTextExample.render(),
source: "RichTextExample.re",
},
{
name: "Shell: Open URL",
render: _ => URLFileOpen.render(),
source: "URLFileOpen.re",
},
{
name: "Window: Hit Tests/Zones",
render: w => HitTests.render(w),
source: "HitTests.re",
},
{
name: "Window: Control",
render: w => WindowControl.render(w),
source: "WindowControl.re",
},
{
name: "Markdown",
render: _ => MarkdownExample.render(),
source: "MarkdownExample.re",
},
{
name: "ImageQuality",
render: _ => ImageQualityExample.render(),
source: "ImageQualityExample.re",
},
{
name: "Layer",
render: _ => LayerExample.render(),
source: "LayerExample.re",
},
{
name: "WavFilePlayback",
render: _ => WavFilePlaybackExample.render(),
source: "WavFilePlaybackExample.re",
},
];
let getExampleByName = name =>
List.find(example => example.name == name, examples);
let noop = () => ();
module ExampleButton = {
let make = (~isActive, ~name, ~onClick, ()) => {
let highlightColor =
isActive ? selectionHighlight : Colors.transparentWhite;
let buttonOpacity = 1.0;
let bgColor = isActive ? activeBackgroundColor : inactiveBackgroundColor;
let wrapperStyle =
Style.[
borderLeft(~width=4, ~color=highlightColor),
backgroundColor(bgColor),
];
let textColor = isActive ? Colors.white : Colors.grey;
let textHeaderStyle = Style.[color(textColor), margin(16)];
<Opacity opacity=buttonOpacity>
<Clickable style=wrapperStyle onClick>
<Text style=textHeaderStyle text=name />
</Clickable>
</Opacity>;
};
};
module ExampleHost = {
let%component make = (~window, ~initialExample, ()) => {
let%hook (selectedExample, setSelectedExample) =
Hooks.state(getExampleByName(initialExample));
let renderButton = example => {
let isActive = example === selectedExample;
let onClick = _ => {
Window.setTitle(window, "Revery Example - " ++ example.name);
prerr_endline("SOURCE FILE: " ++ example.source);
notifyExampleSwitched(example.source);
setSelectedExample(_ => example);
};
<ExampleButton isActive name={example.name} onClick />;
};
let buttons = List.map(renderButton, examples);
let exampleView = selectedExample.render(window);
<View
onMouseWheel={_evt => ()}
style=Style.[
position(`Absolute),
justifyContent(`Center),
alignItems(`Center),
backgroundColor(bgColor),
bottom(0),
top(0),
left(0),
right(0),
flexDirection(`Row),
]>
<ScrollView
style=Style.[
position(`Absolute),
top(0),
left(0),
width(175),
bottom(0),
backgroundColor(bgColor),
]>
<View> {buttons |> React.listToElement} </View>
</ScrollView>
<View
style=Style.[
position(`Absolute),
top(0),
left(175),
right(0),
bottom(0),
backgroundColor(activeBackgroundColor),
]>
exampleView
</View>
</View>;
};
};
let init = app => {
Revery.App.initConsole();
Timber.App.enable(Timber.Reporter.console());
Timber.App.setLevel(Timber.Level.perf);
App.onIdle(app, () => prerr_endline("Idle!"))
|> (ignore: Revery.App.unsubscribe => unit);
App.onBeforeQuit(
app,
(_code: int) => {
prerr_endline("Quitting!");
App.AllowQuit;
},
)
|> (ignore: Revery.App.unsubscribe => unit);
let initialExample = ref("Canvas Example");
let decorated = ref(true);
let forceScaleFactor = ref(None);
let showFPSCounter = ref(false);
Arg.parse(
[
("--trace", Unit(() => Timber.App.setLevel(Timber.Level.trace)), ""),
("--no-decoration", Unit(() => decorated := false), ""),
("--example", String(name => initialExample := name), ""),
(
"--force-device-scale-factor",
Float(scaleFactor => forceScaleFactor := Some(scaleFactor)),
"",
),
("--show-fps", Unit(() => showFPSCounter := true), ""),
],
_ => (),
"There is only --trace, --example, --no-decoration, --show-fps, and --force-device-scale-factor",
);
let initialExample = initialExample^;
let maximized = Environment.webGL;
let windowWidth = 800;
let windowHeight = 480;
print_endline("Hello from example app");
let window =
App.createWindow(
~createOptions=
WindowCreateOptions.create(
~width=windowWidth,
~height=windowHeight,
~maximized,
~titlebarStyle=Transparent,
~icon=Some("revery-icon.png"),
~decorated=decorated^,
~forceScaleFactor=forceScaleFactor^,
~acceleration=`Auto,
(),
),
app,
"Welcome to Revery!",
);
if (showFPSCounter^) {
Window.showFPSCounter(window);
};
if (Environment.webGL) {
Window.maximize(window);
};
/* NOTE: If you want to use network-calls or other IO, uncomment this line */
// let _startEventLoop = Revery_Lwt.startEventLoop();
let _unsubscribe =
Window.onFocusGained(window, () => print_endline("Focus gained"));
let _unsubscribe =
Window.onFocusLost(window, () => print_endline("Focus lost"));
let _unsubscribe =
Window.onMaximized(window, () => print_endline("Maximized!"));
let _unsubscribe =
Window.onFullscreen(window, () => print_endline("Fullscreen!"));
let _unsubscribe =
Window.onMinimized(window, () => print_endline("Minimized!"));
let _unsubscribe =
Window.onRestored(window, () => print_endline("Restored!"));
let _unsubscribe =
Window.onSizeChanged(window, ({width, height}) =>
print_endline(Printf.sprintf("Size changed: %d x %d", width, height))
);
let _unsubscribe =
Window.onMoved(window, ((x, y)) =>
print_endline(Printf.sprintf("Moved: %d x %d", x, y))
);
print_endline(
Printf.sprintf("Operating system: %s", Environment.osString),
);
let _renderFunction =
UI.start(window, <ExampleHost window initialExample />);
();
};
Printexc.record_backtrace(true);
App.start(init);