-
-
Notifications
You must be signed in to change notification settings - Fork 196
/
ScreenCapture.re
61 lines (52 loc) · 1.57 KB
/
ScreenCapture.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
open Revery;
open Revery.UI;
open Revery.UI.Components;
let backgroundColor = Color.hex("#212733");
let activeBackgroundColor = Color.hex("#2E3440");
let inactiveBackgroundColor = Color.hex("#272d39");
let selectionHighlight = Color.hex("#90f7ff");
module ActionButton = {
let make = (~name, ~onClick, ()) => {
let wrapperStyle =
Style.[
backgroundColor(selectionHighlight),
border(~width=4, ~color=activeBackgroundColor),
];
let textHeaderStyle = Style.[color(Colors.black), margin(16)];
<Clickable style=wrapperStyle onClick>
<Text style=textHeaderStyle text=name />
</Clickable>;
};
};
module CaptureArea = {
let%component make = (~w, ()) => {
let%hook (count, setCount) = Hooks.state(0);
let%hook (file, setFile) = Hooks.state(None);
let capture = () => {
let exed = Environment.getExecutingDirectory();
let filename = Printf.sprintf("Scrot_%d.tga", count);
let fullname = exed ++ filename;
Window.takeScreenshot(w, fullname);
setCount(_ => count + 1);
setFile(_ => Some(filename));
};
let viewStyle =
Style.[
position(`Absolute),
left(0),
right(0),
top(0),
bottom(0),
flexDirection(`Column),
];
let imageStyle = Style.[width(400), height(300)];
<View style=viewStyle>
<ActionButton name="Take a screenshot!" onClick=capture />
{switch (file) {
| None => <View />
| Some(src) => <Image style=imageStyle src={`File(src)} />
}}
</View>;
};
};
let render = w => <CaptureArea w />;