-
Notifications
You must be signed in to change notification settings - Fork 0
/
Showcase.js
71 lines (58 loc) · 1.91 KB
/
Showcase.js
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
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: red; icon-glyph: magic;
// >>> Please include the content of index.js below this code <<<
const gradient = new LinearGradient();
gradient.locations = [0, 1];
gradient.colors = [new Color('#2193b0'), new Color('#6dd5ed')];
const widget = render`
<ListWidget backgroundGradient=${gradient}>
<Text font=${Font.mediumSystemFont(14)}>Demo</Text>
<Spacer />
<HStack centerAlignContent>
<Text font=${Font.boldSystemFont(12)}>Text</Text>
<Spacer />
<Text color=${Color.red()}>Red</Text>
<Text font=${Font.boldSystemFont(12)}>Bold</Text>
</HStack>
<HStack centerAlignContent>
<Text font=${Font.boldSystemFont(12)}>Symbols</Text>
<Spacer />
<Symbol name="flame" color=${Color.orange()} bold />
<Symbol name="bolt" color=${Color.yellow()} thin />
</HStack>
<HStack centerAlignContent>
<Text font=${Font.boldSystemFont(12)}>Image</Text>
<Spacer />
<Image image=${getImage()} size=${new Size(10, 10)} />
</HStack>
<HStack centerAlignContent>
<Text font=${Font.boldSystemFont(12)}>Date</Text>
<Spacer />
<Date date=${new Date()} offsetStyle />
</HStack>
<Spacer />
</ListWidget>
`;
if (!config.runsInWidget) {
widget.presentSmall();
} else {
Script.setWidget(widget);
Script.complete();
}
// Image Helper
function getImage() {
const ctx = new DrawContext();
ctx.size = new Size(10, 10);
ctx.respectScreenScale = true;
ctx.setFillColor(Color.white());
ctx.fillRect(new Rect(0,0,10,10))
ctx.setFillColor(Color.blue());
ctx.fillEllipse(new Rect(0,0,10,10))
return ctx.getImage();
}
// helper function to download an image from a given url
async function loadImage(imgUrl) {
const req = new Request(imgUrl)
return await req.loadImage()
}