-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Window.takeScreenshot API (#225)
* Integrate Window.takeScreenshot into examples * Add Window.takeScreenshot * Change screen capture example * Fix formatting
- Loading branch information
Showing
3 changed files
with
102 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
open Revery.UI; | ||
open Revery.UI.Components; | ||
open Revery.Core; | ||
|
||
let backgroundColor = Color.hex("#212733"); | ||
let activeBackgroundColor = Color.hex("#2E3440"); | ||
let inactiveBackgroundColor = Color.hex("#272d39"); | ||
let selectionHighlight = Color.hex("#90f7ff"); | ||
|
||
module ActionButton = { | ||
let component = React.component("ActionButton"); | ||
|
||
let make = (~name, ~onClick, ()) => | ||
component((_slots: React.Hooks.empty) => { | ||
let wrapperStyle = | ||
Style.[ | ||
backgroundColor(selectionHighlight), | ||
border(~width=4, ~color=activeBackgroundColor), | ||
]; | ||
let textHeaderStyle = | ||
Style.[ | ||
color(Colors.black), | ||
fontFamily("Roboto-Regular.ttf"), | ||
fontSize(14), | ||
margin(16), | ||
]; | ||
<Clickable style=wrapperStyle onClick> | ||
<Text style=textHeaderStyle text=name /> | ||
</Clickable>; | ||
}); | ||
|
||
let createElement = (~children as _, ~name, ~onClick, ()) => | ||
React.element(make(~name, ~onClick, ())); | ||
}; | ||
|
||
module CaptureArea = { | ||
let component = React.component("Capture Area"); | ||
|
||
let make = w => | ||
component(slots => { | ||
let (count, setCount, slots) = React.Hooks.state(0, slots); | ||
let (file, setFile, _slots: React.Hooks.empty) = | ||
React.Hooks.state(None, slots); | ||
|
||
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 /> | ||
}} | ||
</View>; | ||
}); | ||
|
||
let createElement = (~w, ~children as _, ()) => React.element(make(w)); | ||
}; | ||
|
||
let render = w => <CaptureArea w />; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters