-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
ui.ts
84 lines (71 loc) · 1.28 KB
/
ui.ts
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
const LABEL_X = 10;
const INPUT_X = 70;
let y = 0;
export type ChangeEventHandler<Value> = (value: Value) => void;
export type ClickEventHandler = () => void;
export type Choice = {
name: string;
identifier: string;
};
export function Document(...widgets: Widget[]): Widget[] {
y = 0;
return widgets;
}
export function Dropdown(
text: string,
choices: Choice[],
selectedIndex: number,
onChange: ChangeEventHandler<number>,
): [LabelWidget, DropdownWidget] {
const items = choices.map((b) => `${b.name} ${b.identifier}`);
y += 20;
return [
{
type: "label",
x: LABEL_X,
y,
width: 60,
height: 10,
text,
},
{
type: "dropdown",
x: INPUT_X,
y,
width: 200,
height: 10,
items,
selectedIndex,
onChange,
},
];
}
export function Checkbox(
text: string,
isChecked: boolean,
onChange: ChangeEventHandler<boolean>,
): CheckboxWidget {
y += 15;
return {
type: "checkbox",
x: LABEL_X,
y,
width: 200,
height: 15,
isChecked,
text,
onChange,
};
}
export function Button(text: string, onClick: ClickEventHandler): ButtonWidget {
y += 20;
return {
type: "button",
text,
x: 10,
y: y,
width: 100,
height: 20,
onClick,
};
}