@thi.ng/imgui 2.2.12 → 2.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/api.js +94 -84
- package/behaviors/button.js +26 -22
- package/behaviors/dial.js +12 -4
- package/behaviors/slider.js +46 -43
- package/behaviors/text.js +75 -70
- package/components/button.js +64 -41
- package/components/dial.js +102 -52
- package/components/dropdown.js +62 -64
- package/components/icon-button.js +40 -31
- package/components/radial-menu.js +43 -37
- package/components/radio.js +19 -14
- package/components/ring.js +123 -79
- package/components/sliderh.js +96 -46
- package/components/sliderv.js +100 -53
- package/components/textfield.js +83 -44
- package/components/textlabel.js +28 -14
- package/components/toggle.js +45 -38
- package/components/tooltip.js +16 -6
- package/components/xypad.js +89 -73
- package/events.js +36 -47
- package/gui.js +400 -415
- package/hash.js +17 -45
- package/layout.js +4 -1
- package/package.json +16 -14
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/api.js
CHANGED
|
@@ -1,86 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
})(MouseButton ||
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
})(KeyModifier ||
|
|
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
|
-
})(Key ||
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
1
|
+
var MouseButton = /* @__PURE__ */ ((MouseButton2) => {
|
|
2
|
+
MouseButton2[MouseButton2["LEFT"] = 1] = "LEFT";
|
|
3
|
+
MouseButton2[MouseButton2["RIGHT"] = 2] = "RIGHT";
|
|
4
|
+
MouseButton2[MouseButton2["MIDDLE"] = 4] = "MIDDLE";
|
|
5
|
+
return MouseButton2;
|
|
6
|
+
})(MouseButton || {});
|
|
7
|
+
var KeyModifier = /* @__PURE__ */ ((KeyModifier2) => {
|
|
8
|
+
KeyModifier2[KeyModifier2["SHIFT"] = 1] = "SHIFT";
|
|
9
|
+
KeyModifier2[KeyModifier2["CONTROL"] = 2] = "CONTROL";
|
|
10
|
+
KeyModifier2[KeyModifier2["META"] = 4] = "META";
|
|
11
|
+
KeyModifier2[KeyModifier2["ALT"] = 8] = "ALT";
|
|
12
|
+
return KeyModifier2;
|
|
13
|
+
})(KeyModifier || {});
|
|
14
|
+
var Key = /* @__PURE__ */ ((Key2) => {
|
|
15
|
+
Key2["ALT"] = "Alt";
|
|
16
|
+
Key2["BACKSPACE"] = "Backspace";
|
|
17
|
+
Key2["CAPSLOCK"] = "CapsLock";
|
|
18
|
+
Key2["CONTEXT_MENU"] = "ContextMenu";
|
|
19
|
+
Key2["CONTROL"] = "Control";
|
|
20
|
+
Key2["DELETE"] = "Delete";
|
|
21
|
+
Key2["DOWN"] = "ArrowDown";
|
|
22
|
+
Key2["END"] = "End";
|
|
23
|
+
Key2["ENTER"] = "Enter";
|
|
24
|
+
Key2["ESC"] = "Escape";
|
|
25
|
+
Key2["HELP"] = "Help";
|
|
26
|
+
Key2["HOME"] = "Home";
|
|
27
|
+
Key2["LEFT"] = "ArrowLeft";
|
|
28
|
+
Key2["META"] = "Meta";
|
|
29
|
+
Key2["NUM_LOCK"] = "NumLock";
|
|
30
|
+
Key2["PAGE_DOWN"] = "PageDown";
|
|
31
|
+
Key2["PAGE_UP"] = "PageUp";
|
|
32
|
+
Key2["RIGHT"] = "ArrowRight";
|
|
33
|
+
Key2["SHIFT"] = "Shift";
|
|
34
|
+
Key2["SPACE"] = " ";
|
|
35
|
+
Key2["TAB"] = "Tab";
|
|
36
|
+
Key2["UP"] = "ArrowUp";
|
|
37
|
+
return Key2;
|
|
38
|
+
})(Key || {});
|
|
39
|
+
const CONTROL_KEYS = /* @__PURE__ */ new Set([
|
|
40
|
+
"Alt" /* ALT */,
|
|
41
|
+
"Backspace" /* BACKSPACE */,
|
|
42
|
+
"CapsLock" /* CAPSLOCK */,
|
|
43
|
+
"ContextMenu" /* CONTEXT_MENU */,
|
|
44
|
+
"Control" /* CONTROL */,
|
|
45
|
+
"Delete" /* DELETE */,
|
|
46
|
+
"ArrowDown" /* DOWN */,
|
|
47
|
+
"End" /* END */,
|
|
48
|
+
"Enter" /* ENTER */,
|
|
49
|
+
"Escape" /* ESC */,
|
|
50
|
+
"Help" /* HELP */,
|
|
51
|
+
"Home" /* HOME */,
|
|
52
|
+
"ArrowLeft" /* LEFT */,
|
|
53
|
+
"Meta" /* META */,
|
|
54
|
+
"NumLock" /* NUM_LOCK */,
|
|
55
|
+
"PageDown" /* PAGE_DOWN */,
|
|
56
|
+
"PageUp" /* PAGE_UP */,
|
|
57
|
+
"ArrowRight" /* RIGHT */,
|
|
58
|
+
"Shift" /* SHIFT */,
|
|
59
|
+
"Tab" /* TAB */,
|
|
60
|
+
"ArrowUp" /* UP */
|
|
61
61
|
]);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
62
|
+
const NONE = "__NONE__";
|
|
63
|
+
const DEFAULT_THEME = {
|
|
64
|
+
font: "10px Menlo, monospace",
|
|
65
|
+
fontSize: 10,
|
|
66
|
+
charWidth: 6,
|
|
67
|
+
baseLine: 4,
|
|
68
|
+
pad: 8,
|
|
69
|
+
globalBg: "#ccc",
|
|
70
|
+
focus: [0, 1, 0, 1],
|
|
71
|
+
cursor: [0, 0, 0, 1],
|
|
72
|
+
cursorBlink: 2,
|
|
73
|
+
bg: [1, 1, 1, 0.66],
|
|
74
|
+
bgDisabled: [1, 1, 1, 0.33],
|
|
75
|
+
bgHover: [1, 1, 1, 0.9],
|
|
76
|
+
fg: [0.2, 0.8, 1, 1],
|
|
77
|
+
fgDisabled: [0.2, 0.8, 1, 0.5],
|
|
78
|
+
fgHover: [0.3, 0.9, 1, 1],
|
|
79
|
+
text: [0.3, 0.3, 0.3, 1],
|
|
80
|
+
textDisabled: [0.3, 0.3, 0.3, 0.5],
|
|
81
|
+
textHover: [0.2, 0.2, 0.4, 1],
|
|
82
|
+
bgTooltip: [1, 1, 0.8, 0.85],
|
|
83
|
+
textTooltip: [0, 0, 0, 1]
|
|
84
|
+
};
|
|
85
|
+
const INPUT_ALPHA = (x) => /^\w$/.test(x);
|
|
86
|
+
const INPUT_DIGITS = (x) => /^\d$/.test(x);
|
|
87
|
+
export {
|
|
88
|
+
CONTROL_KEYS,
|
|
89
|
+
DEFAULT_THEME,
|
|
90
|
+
INPUT_ALPHA,
|
|
91
|
+
INPUT_DIGITS,
|
|
92
|
+
Key,
|
|
93
|
+
KeyModifier,
|
|
94
|
+
MouseButton,
|
|
95
|
+
NONE
|
|
84
96
|
};
|
|
85
|
-
export const INPUT_ALPHA = (x) => /^\w$/.test(x);
|
|
86
|
-
export const INPUT_DIGITS = (x) => /^\d$/.test(x);
|
package/behaviors/button.js
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
import { pointInside } from "@thi.ng/geom/point-inside";
|
|
2
2
|
import { Key } from "../api.js";
|
|
3
3
|
import { tooltipRaw } from "../components/tooltip.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
const hoverButton = (gui, id, shape, info) => {
|
|
5
|
+
if (gui.disabled)
|
|
6
|
+
return false;
|
|
7
|
+
const aid = gui.activeID;
|
|
8
|
+
const hover = (aid === "" || aid === id) && pointInside(shape, gui.mouse);
|
|
9
|
+
if (hover) {
|
|
10
|
+
gui.setCursor("pointer");
|
|
11
|
+
gui.hotID = id;
|
|
12
|
+
gui.isMouseDown() && (gui.activeID = id);
|
|
13
|
+
info && gui.draw && tooltipRaw(gui, info);
|
|
14
|
+
}
|
|
15
|
+
return hover;
|
|
16
16
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
const handleButtonKeys = (gui) => {
|
|
18
|
+
switch (gui.key) {
|
|
19
|
+
case Key.TAB:
|
|
20
|
+
gui.switchFocus();
|
|
21
|
+
break;
|
|
22
|
+
case Key.ENTER:
|
|
23
|
+
case Key.SPACE:
|
|
24
|
+
return true;
|
|
25
|
+
default:
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
export {
|
|
29
|
+
handleButtonKeys,
|
|
30
|
+
hoverButton
|
|
27
31
|
};
|
package/behaviors/dial.js
CHANGED
|
@@ -3,8 +3,16 @@ import { fit } from "@thi.ng/math/fit";
|
|
|
3
3
|
import { heading } from "@thi.ng/vectors/heading";
|
|
4
4
|
import { sub2 } from "@thi.ng/vectors/sub";
|
|
5
5
|
import { slider1Val } from "./slider.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const dialVal = (p, c, startTheta, thetaGap, min, max, prec) => {
|
|
7
|
+
let theta = heading(sub2([], p, c)) - startTheta;
|
|
8
|
+
theta < -0.5 && (theta += TAU);
|
|
9
|
+
return slider1Val(
|
|
10
|
+
fit(Math.min(theta / (TAU - thetaGap)), 0, 1, min, max),
|
|
11
|
+
min,
|
|
12
|
+
max,
|
|
13
|
+
prec
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
dialVal
|
|
10
18
|
};
|
package/behaviors/slider.js
CHANGED
|
@@ -5,51 +5,54 @@ import { add2 } from "@thi.ng/vectors/add";
|
|
|
5
5
|
import { clamp2 } from "@thi.ng/vectors/clamp";
|
|
6
6
|
import { roundN2 } from "@thi.ng/vectors/round";
|
|
7
7
|
import { Key } from "../api.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
const isHoverSlider = (gui, id, shape, cursor = "ew-resize") => {
|
|
9
|
+
if (gui.disabled)
|
|
10
|
+
return false;
|
|
11
|
+
const aid = gui.activeID;
|
|
12
|
+
const hover = aid === id || aid === "" && pointInside(shape, gui.mouse);
|
|
13
|
+
if (hover) {
|
|
14
|
+
gui.setCursor(cursor);
|
|
15
|
+
gui.hotID = id;
|
|
16
|
+
}
|
|
17
|
+
return hover;
|
|
18
18
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return slider1Val(val + step, min, max, prec);
|
|
31
|
-
}
|
|
32
|
-
default:
|
|
19
|
+
const slider1Val = (x, min, max, prec) => clamp(roundTo(x, prec), min, max);
|
|
20
|
+
const slider2Val = (v, min, max, prec) => clamp2(null, roundN2([], v, prec), min, max);
|
|
21
|
+
const handleSlider1Keys = (gui, min, max, prec, val) => {
|
|
22
|
+
switch (gui.key) {
|
|
23
|
+
case Key.TAB:
|
|
24
|
+
gui.switchFocus();
|
|
25
|
+
break;
|
|
26
|
+
case Key.UP:
|
|
27
|
+
case Key.DOWN: {
|
|
28
|
+
const step = (gui.key === Key.UP ? prec : -prec) * (gui.isShiftDown() ? 5 : 1);
|
|
29
|
+
return slider1Val(val + step, min, max, prec);
|
|
33
30
|
}
|
|
31
|
+
default:
|
|
32
|
+
}
|
|
34
33
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
(yUp ? 1 : -1) *
|
|
50
|
-
(gui.isShiftDown() ? 5 : 1);
|
|
51
|
-
return slider2Val(add2([], val, [0, step]), min, max, prec);
|
|
52
|
-
}
|
|
53
|
-
default:
|
|
34
|
+
const handleSlider2Keys = (gui, min, max, prec, val, yUp) => {
|
|
35
|
+
switch (gui.key) {
|
|
36
|
+
case Key.TAB:
|
|
37
|
+
gui.switchFocus();
|
|
38
|
+
break;
|
|
39
|
+
case Key.LEFT:
|
|
40
|
+
case Key.RIGHT: {
|
|
41
|
+
const step = (gui.key === Key.RIGHT ? prec : -prec) * (gui.isShiftDown() ? 5 : 1);
|
|
42
|
+
return slider2Val(add2([], val, [step, 0]), min, max, prec);
|
|
43
|
+
}
|
|
44
|
+
case Key.UP:
|
|
45
|
+
case Key.DOWN: {
|
|
46
|
+
const step = (gui.key === Key.UP ? prec : -prec) * (yUp ? 1 : -1) * (gui.isShiftDown() ? 5 : 1);
|
|
47
|
+
return slider2Val(add2([], val, [0, step]), min, max, prec);
|
|
54
48
|
}
|
|
49
|
+
default:
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
export {
|
|
53
|
+
handleSlider1Keys,
|
|
54
|
+
handleSlider2Keys,
|
|
55
|
+
isHoverSlider,
|
|
56
|
+
slider1Val,
|
|
57
|
+
slider2Val
|
|
55
58
|
};
|
package/behaviors/text.js
CHANGED
|
@@ -2,80 +2,85 @@ import { clamp0 } from "@thi.ng/math/interval";
|
|
|
2
2
|
import { Key } from "../api.js";
|
|
3
3
|
const WS = /\s/;
|
|
4
4
|
const nextNonAlpha = (src, i) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
const n = src.length;
|
|
6
|
+
while (i < n && WS.test(src[i]))
|
|
7
|
+
i++;
|
|
8
|
+
for (; i < n && !WS.test(src[i]); i++) {
|
|
9
|
+
}
|
|
10
|
+
return i;
|
|
10
11
|
};
|
|
11
12
|
const prevNonAlpha = (src, i) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
while (i > 0 && WS.test(src[i]))
|
|
14
|
+
i--;
|
|
15
|
+
for (; i > 0 && !WS.test(src[i]); i--) {
|
|
16
|
+
}
|
|
17
|
+
return i;
|
|
16
18
|
};
|
|
17
19
|
const getNext = (gui, txt, cursor, dir) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
? (dir < 0 ? prevNonAlpha : nextNonAlpha)(txt, cursor)
|
|
21
|
-
: cursor;
|
|
20
|
+
cursor += dir;
|
|
21
|
+
return gui.isAltDown() ? (dir < 0 ? prevNonAlpha : nextNonAlpha)(txt, cursor) : cursor;
|
|
22
22
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const k = gui.key;
|
|
35
|
-
switch (k) {
|
|
36
|
-
case "":
|
|
37
|
-
break;
|
|
38
|
-
case Key.TAB:
|
|
39
|
-
gui.switchFocus();
|
|
40
|
-
break;
|
|
41
|
-
case Key.ENTER:
|
|
42
|
-
return txt;
|
|
43
|
-
case Key.BACKSPACE:
|
|
44
|
-
if (cursor > 0) {
|
|
45
|
-
const next = getNext(gui, txt, cursor, -1);
|
|
46
|
-
move(next, next - cursor);
|
|
47
|
-
return txt.substring(0, next) + txt.substring(cursor);
|
|
48
|
-
}
|
|
49
|
-
break;
|
|
50
|
-
case Key.DELETE:
|
|
51
|
-
if (cursor < txtLen) {
|
|
52
|
-
const next = getNext(gui, txt, cursor, 1);
|
|
53
|
-
return txt.substring(0, cursor) + txt.substring(next + 1);
|
|
54
|
-
}
|
|
55
|
-
break;
|
|
56
|
-
case Key.LEFT:
|
|
57
|
-
if (cursor > 0) {
|
|
58
|
-
const next = getNext(gui, txt, cursor, -1);
|
|
59
|
-
move(next, next - cursor);
|
|
60
|
-
}
|
|
61
|
-
break;
|
|
62
|
-
case Key.RIGHT:
|
|
63
|
-
if (cursor < txtLen) {
|
|
64
|
-
const next = getNext(gui, txt, cursor, 1);
|
|
65
|
-
move(next, next - cursor);
|
|
66
|
-
}
|
|
67
|
-
break;
|
|
68
|
-
case Key.HOME:
|
|
69
|
-
move(0, -cursor);
|
|
70
|
-
break;
|
|
71
|
-
case Key.END:
|
|
72
|
-
move(txtLen, txtLen - cursor);
|
|
73
|
-
break;
|
|
74
|
-
default: {
|
|
75
|
-
if (k.length === 1 && filter(k)) {
|
|
76
|
-
move(cursor + 1, 1);
|
|
77
|
-
return txt.substring(0, cursor) + k + txt.substring(cursor);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
23
|
+
const handleTextfieldKeys = (gui, state, filter, txt, cursor, drawCursor, maxLen) => {
|
|
24
|
+
const txtLen = txt.length;
|
|
25
|
+
const move = (next, delta) => {
|
|
26
|
+
state.cursor = next;
|
|
27
|
+
if (drawCursor + delta < 0) {
|
|
28
|
+
state.offset = Math.max(state.offset + delta, 0);
|
|
29
|
+
} else if (drawCursor + delta > maxLen) {
|
|
30
|
+
state.offset = Math.min(
|
|
31
|
+
state.offset + delta,
|
|
32
|
+
clamp0(txtLen - maxLen)
|
|
33
|
+
);
|
|
80
34
|
}
|
|
35
|
+
};
|
|
36
|
+
const k = gui.key;
|
|
37
|
+
switch (k) {
|
|
38
|
+
case "":
|
|
39
|
+
break;
|
|
40
|
+
case Key.TAB:
|
|
41
|
+
gui.switchFocus();
|
|
42
|
+
break;
|
|
43
|
+
case Key.ENTER:
|
|
44
|
+
return txt;
|
|
45
|
+
case Key.BACKSPACE:
|
|
46
|
+
if (cursor > 0) {
|
|
47
|
+
const next = getNext(gui, txt, cursor, -1);
|
|
48
|
+
move(next, next - cursor);
|
|
49
|
+
return txt.substring(0, next) + txt.substring(cursor);
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
case Key.DELETE:
|
|
53
|
+
if (cursor < txtLen) {
|
|
54
|
+
const next = getNext(gui, txt, cursor, 1);
|
|
55
|
+
return txt.substring(0, cursor) + txt.substring(next + 1);
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
case Key.LEFT:
|
|
59
|
+
if (cursor > 0) {
|
|
60
|
+
const next = getNext(gui, txt, cursor, -1);
|
|
61
|
+
move(next, next - cursor);
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
case Key.RIGHT:
|
|
65
|
+
if (cursor < txtLen) {
|
|
66
|
+
const next = getNext(gui, txt, cursor, 1);
|
|
67
|
+
move(next, next - cursor);
|
|
68
|
+
}
|
|
69
|
+
break;
|
|
70
|
+
case Key.HOME:
|
|
71
|
+
move(0, -cursor);
|
|
72
|
+
break;
|
|
73
|
+
case Key.END:
|
|
74
|
+
move(txtLen, txtLen - cursor);
|
|
75
|
+
break;
|
|
76
|
+
default: {
|
|
77
|
+
if (k.length === 1 && filter(k)) {
|
|
78
|
+
move(cursor + 1, 1);
|
|
79
|
+
return txt.substring(0, cursor) + k + txt.substring(cursor);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
export {
|
|
85
|
+
handleTextfieldKeys
|
|
81
86
|
};
|
package/components/button.js
CHANGED
|
@@ -5,47 +5,70 @@ import { handleButtonKeys, hoverButton } from "../behaviors/button.js";
|
|
|
5
5
|
import { labelHash } from "../hash.js";
|
|
6
6
|
import { layoutBox } from "../layout.js";
|
|
7
7
|
import { textLabelRaw, textTransformH, textTransformV } from "./textlabel.js";
|
|
8
|
-
const mkLabel = (gui, tx, id, key, x, y, w, h, hover, label) => gui.resource(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
const mkLabel = (gui, tx, id, key, x, y, w, h, hover, label) => gui.resource(
|
|
9
|
+
id,
|
|
10
|
+
labelHash(key, label, gui.disabled),
|
|
11
|
+
() => textLabelRaw(
|
|
12
|
+
ZERO2,
|
|
13
|
+
{
|
|
14
|
+
transform: tx(gui.theme, x, y, w, h),
|
|
15
|
+
fill: gui.textColor(hover)
|
|
16
|
+
},
|
|
17
|
+
label
|
|
18
|
+
)
|
|
19
|
+
);
|
|
20
|
+
const buttonH = (gui, layout, id, label, labelHover = label, info) => {
|
|
21
|
+
const { x, y, w, h } = layoutBox(layout);
|
|
22
|
+
const key = hash([x, y, w, h]);
|
|
23
|
+
return buttonRaw(
|
|
24
|
+
gui,
|
|
25
|
+
id,
|
|
26
|
+
gui.resource(id, key, () => rect([x, y], [w, h])),
|
|
27
|
+
key,
|
|
28
|
+
label ? mkLabel(gui, textTransformH, id, key, x, y, w, h, false, label) : void 0,
|
|
29
|
+
labelHover ? (
|
|
30
|
+
// prettier-ignore
|
|
31
|
+
mkLabel(gui, textTransformH, id, key, x, y, w, h, true, labelHover)
|
|
32
|
+
) : void 0,
|
|
33
|
+
info
|
|
34
|
+
);
|
|
21
35
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
const buttonV = (gui, layout, id, rows, label, labelHover = label, info) => {
|
|
37
|
+
const { x, y, w, h } = layoutBox(layout, [1, rows]);
|
|
38
|
+
const key = hash([x, y, w, h]);
|
|
39
|
+
return buttonRaw(
|
|
40
|
+
gui,
|
|
41
|
+
id,
|
|
42
|
+
gui.resource(id, key, () => rect([x, y], [w, h])),
|
|
43
|
+
key,
|
|
44
|
+
label ? mkLabel(gui, textTransformV, id, key, x, y, w, h, false, label) : void 0,
|
|
45
|
+
labelHover ? (
|
|
46
|
+
// prettier-ignore
|
|
47
|
+
mkLabel(gui, textTransformV, id, key, x, y, w, h, true, labelHover)
|
|
48
|
+
) : void 0,
|
|
49
|
+
info
|
|
50
|
+
);
|
|
31
51
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
const buttonRaw = (gui, id, shape, hash2, label, labelHover, info) => {
|
|
53
|
+
gui.registerID(id, hash2);
|
|
54
|
+
const hover = hoverButton(gui, id, shape, info);
|
|
55
|
+
const focused = gui.requestFocus(id);
|
|
56
|
+
if (gui.draw) {
|
|
57
|
+
shape.attribs = {
|
|
58
|
+
fill: hover ? gui.fgColor(true) : gui.bgColor(focused),
|
|
59
|
+
stroke: gui.focusColor(id)
|
|
60
|
+
};
|
|
61
|
+
gui.add(shape);
|
|
62
|
+
label && gui.add(hover && labelHover ? labelHover : label);
|
|
63
|
+
}
|
|
64
|
+
if (focused && handleButtonKeys(gui)) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
gui.lastID = id;
|
|
68
|
+
return !gui.buttons && gui.hotID === id && gui.activeID === id;
|
|
69
|
+
};
|
|
70
|
+
export {
|
|
71
|
+
buttonH,
|
|
72
|
+
buttonRaw,
|
|
73
|
+
buttonV
|
|
51
74
|
};
|