@thi.ng/imgui 2.2.13 → 2.2.15

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-12-09T19:12:03Z
3
+ - **Last updated**: 2023-12-11T10:07:09Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
package/README.md CHANGED
@@ -253,7 +253,7 @@ For Node.js REPL:
253
253
  const imgui = await import("@thi.ng/imgui");
254
254
  ```
255
255
 
256
- Package sizes (brotli'd, pre-treeshake): ESM: 6.69 KB
256
+ Package sizes (brotli'd, pre-treeshake): ESM: 6.65 KB
257
257
 
258
258
  ## Dependencies
259
259
 
package/api.js CHANGED
@@ -1,86 +1,96 @@
1
- export var MouseButton;
2
- (function (MouseButton) {
3
- MouseButton[MouseButton["LEFT"] = 1] = "LEFT";
4
- MouseButton[MouseButton["RIGHT"] = 2] = "RIGHT";
5
- MouseButton[MouseButton["MIDDLE"] = 4] = "MIDDLE";
6
- })(MouseButton || (MouseButton = {}));
7
- export var KeyModifier;
8
- (function (KeyModifier) {
9
- KeyModifier[KeyModifier["SHIFT"] = 1] = "SHIFT";
10
- KeyModifier[KeyModifier["CONTROL"] = 2] = "CONTROL";
11
- KeyModifier[KeyModifier["META"] = 4] = "META";
12
- KeyModifier[KeyModifier["ALT"] = 8] = "ALT";
13
- })(KeyModifier || (KeyModifier = {}));
14
- export var Key;
15
- (function (Key) {
16
- Key["ALT"] = "Alt";
17
- Key["BACKSPACE"] = "Backspace";
18
- Key["CAPSLOCK"] = "CapsLock";
19
- Key["CONTEXT_MENU"] = "ContextMenu";
20
- Key["CONTROL"] = "Control";
21
- Key["DELETE"] = "Delete";
22
- Key["DOWN"] = "ArrowDown";
23
- Key["END"] = "End";
24
- Key["ENTER"] = "Enter";
25
- Key["ESC"] = "Escape";
26
- Key["HELP"] = "Help";
27
- Key["HOME"] = "Home";
28
- Key["LEFT"] = "ArrowLeft";
29
- Key["META"] = "Meta";
30
- Key["NUM_LOCK"] = "NumLock";
31
- Key["PAGE_DOWN"] = "PageDown";
32
- Key["PAGE_UP"] = "PageUp";
33
- Key["RIGHT"] = "ArrowRight";
34
- Key["SHIFT"] = "Shift";
35
- Key["SPACE"] = " ";
36
- Key["TAB"] = "Tab";
37
- Key["UP"] = "ArrowUp";
38
- })(Key || (Key = {}));
39
- export const CONTROL_KEYS = new Set([
40
- Key.ALT,
41
- Key.BACKSPACE,
42
- Key.CAPSLOCK,
43
- Key.CONTEXT_MENU,
44
- Key.CONTROL,
45
- Key.DELETE,
46
- Key.DOWN,
47
- Key.END,
48
- Key.ENTER,
49
- Key.ESC,
50
- Key.HELP,
51
- Key.HOME,
52
- Key.LEFT,
53
- Key.META,
54
- Key.NUM_LOCK,
55
- Key.PAGE_DOWN,
56
- Key.PAGE_UP,
57
- Key.RIGHT,
58
- Key.SHIFT,
59
- Key.TAB,
60
- Key.UP,
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
- export const NONE = "__NONE__";
63
- export 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],
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);
@@ -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
- export 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;
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
- export 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
- }
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
- export 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(fit(Math.min(theta / (TAU - thetaGap)), 0, 1, min, max), min, max, prec);
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
  };
@@ -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
- export 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;
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
- export const slider1Val = (x, min, max, prec) => clamp(roundTo(x, prec), min, max);
20
- export const slider2Val = (v, min, max, prec) => clamp2(null, roundN2([], v, prec), min, max);
21
- export 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) *
29
- (gui.isShiftDown() ? 5 : 1);
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
- export const handleSlider2Keys = (gui, min, max, prec, val, yUp) => {
36
- switch (gui.key) {
37
- case Key.TAB:
38
- gui.switchFocus();
39
- break;
40
- case Key.LEFT:
41
- case Key.RIGHT: {
42
- const step = (gui.key === Key.RIGHT ? prec : -prec) *
43
- (gui.isShiftDown() ? 5 : 1);
44
- return slider2Val(add2([], val, [step, 0]), min, max, prec);
45
- }
46
- case Key.UP:
47
- case Key.DOWN: {
48
- const step = (gui.key === Key.UP ? prec : -prec) *
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
- const n = src.length;
6
- while (i < n && WS.test(src[i]))
7
- i++;
8
- for (; i < n && !WS.test(src[i]); i++) { }
9
- return i;
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
- while (i > 0 && WS.test(src[i]))
13
- i--;
14
- for (; i > 0 && !WS.test(src[i]); i--) { }
15
- return i;
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
- cursor += dir;
19
- return gui.isAltDown()
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
- export 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
- }
30
- else if (drawCursor + delta > maxLen) {
31
- state.offset = Math.min(state.offset + delta, clamp0(txtLen - maxLen));
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
  };
@@ -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(id, labelHash(key, label, gui.disabled), () => textLabelRaw(ZERO2, {
9
- transform: tx(gui.theme, x, y, w, h),
10
- fill: gui.textColor(hover),
11
- }, label));
12
- export const buttonH = (gui, layout, id, label, labelHover = label, info) => {
13
- const { x, y, w, h } = layoutBox(layout);
14
- const key = hash([x, y, w, h]);
15
- return buttonRaw(gui, id, gui.resource(id, key, () => rect([x, y], [w, h])), key, label
16
- ? mkLabel(gui, textTransformH, id, key, x, y, w, h, false, label)
17
- : undefined, labelHover
18
- ? // prettier-ignore
19
- mkLabel(gui, textTransformH, id, key, x, y, w, h, true, labelHover)
20
- : undefined, info);
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
- export const buttonV = (gui, layout, id, rows, label, labelHover = label, info) => {
23
- const { x, y, w, h } = layoutBox(layout, [1, rows]);
24
- const key = hash([x, y, w, h]);
25
- return buttonRaw(gui, id, gui.resource(id, key, () => rect([x, y], [w, h])), key, label
26
- ? mkLabel(gui, textTransformV, id, key, x, y, w, h, false, label)
27
- : undefined, labelHover
28
- ? // prettier-ignore
29
- mkLabel(gui, textTransformV, id, key, x, y, w, h, true, labelHover)
30
- : undefined, info);
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
- export const buttonRaw = (gui, id, shape, hash, label, labelHover, info) => {
33
- gui.registerID(id, hash);
34
- const hover = hoverButton(gui, id, shape, info);
35
- const focused = gui.requestFocus(id);
36
- if (gui.draw) {
37
- shape.attribs = {
38
- fill: hover ? gui.fgColor(true) : gui.bgColor(focused),
39
- stroke: gui.focusColor(id),
40
- };
41
- gui.add(shape);
42
- label && gui.add(hover && labelHover ? labelHover : label);
43
- }
44
- if (focused && handleButtonKeys(gui)) {
45
- return true;
46
- }
47
- gui.lastID = id;
48
- // only emit true on mouse release over this button
49
- // TODO extract as behavior function
50
- return !gui.buttons && gui.hotID === id && gui.activeID === id;
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
  };