-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
69 lines (61 loc) · 2.03 KB
/
utils.js
File metadata and controls
69 lines (61 loc) · 2.03 KB
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
import GLib from 'gi://GLib';
import Adw from 'gi://Adw';
import Gtk from 'gi://Gtk';
export function rand(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min);
}
export function timeMs() {
return GLib.get_monotonic_time() / 1_000;
}
export function bindSwitch(settings, key, row) {
row.active = settings.get_boolean(key);
row.connect('notify::active', () => {
settings.set_boolean(key, row.active)
});
settings.connect(`changed::${key}`, () => {
row.active = settings.get_boolean(key);
});
}
export function bindSpin(settings, key, row) {
row.value = settings.get_int(key);
row.connect('notify::value', () => {
settings.set_int(key, row.value)
});
settings.connect(`changed::${key}`, () => {
row.value = settings.get_int(key);
});
}
export function makeSpinRow({ title, subtitle, lower, upper, step = 1, page = 10 }) {
return new Adw.SpinRow({
title,
subtitle,
adjustment: new Gtk.Adjustment({
lower, upper,
step_increment: step,
page_increment: page, value: 0
}),
});
}
export function makeChannelRow(settings, group, label, minKey, maxKey) {
const row = new Adw.ActionRow({ title: `${label} Range` });
const makeSpin = (key) => {
const spin = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 0, upper: 255, step_increment: 1, page_increment: 16,
value: settings.get_int(key),
}),
valign: Gtk.Align.CENTER,
width_request: 80,
});
spin.connect('value-changed', () => settings.set_int(key, spin.value));
settings.connect(`changed::${key}`, () => { spin.value = settings.get_int(key); });
return spin;
};
row.add_suffix(makeSpin(minKey));
row.add_suffix(new Gtk.Label({ label: '–', margin_start: 6, margin_end: 6 }));
row.add_suffix(makeSpin(maxKey));
group.add(row);
return row;
}