@thi.ng/imgui 2.2.72 → 2.3.0
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 +11 -1
- package/README.md +3 -1
- package/components/ramp.d.ts +6 -0
- package/components/ramp.js +115 -0
- package/components/textlabel.d.ts +1 -1
- package/components/textlabel.js +9 -7
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +11 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-
|
|
3
|
+
- **Last updated**: 2024-09-05T12:23:14Z
|
|
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.
|
|
@@ -9,6 +9,16 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [2.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/imgui@2.3.0) (2024-09-05)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add ramp widget ([3c84204](https://github.com/thi-ng/umbrella/commit/3c84204))
|
|
17
|
+
|
|
18
|
+
#### ♻️ Refactoring
|
|
19
|
+
|
|
20
|
+
- update textLabel to use geom types ([176024f](https://github.com/thi-ng/umbrella/commit/176024f))
|
|
21
|
+
|
|
12
22
|
### [2.2.60](https://github.com/thi-ng/umbrella/tree/@thi.ng/imgui@2.2.60) (2024-06-21)
|
|
13
23
|
|
|
14
24
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
|
@@ -88,6 +88,7 @@ The above screenshot shows most of the currently available components:
|
|
|
88
88
|
- Dropdown
|
|
89
89
|
- Radial menu
|
|
90
90
|
- Radio button group (h / v)
|
|
91
|
+
- Ramp (keyframe-based control curve editor)
|
|
91
92
|
- Slider & slider groups (h / v)
|
|
92
93
|
- Text input (single line, filtered input)
|
|
93
94
|
- Text label
|
|
@@ -261,7 +262,7 @@ Browser ESM import:
|
|
|
261
262
|
|
|
262
263
|
[JSDelivr documentation](https://www.jsdelivr.com/)
|
|
263
264
|
|
|
264
|
-
Package sizes (brotli'd, pre-treeshake): ESM:
|
|
265
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 7.11 KB
|
|
265
266
|
|
|
266
267
|
## Dependencies
|
|
267
268
|
|
|
@@ -271,6 +272,7 @@ Package sizes (brotli'd, pre-treeshake): ESM: 6.67 KB
|
|
|
271
272
|
- [@thi.ng/geom-isec](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-isec)
|
|
272
273
|
- [@thi.ng/layout](https://github.com/thi-ng/umbrella/tree/develop/packages/layout)
|
|
273
274
|
- [@thi.ng/math](https://github.com/thi-ng/umbrella/tree/develop/packages/math)
|
|
275
|
+
- [@thi.ng/ramp](https://github.com/thi-ng/umbrella/tree/develop/packages/ramp)
|
|
274
276
|
- [@thi.ng/transducers](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers)
|
|
275
277
|
- [@thi.ng/vectors](https://github.com/thi-ng/umbrella/tree/develop/packages/vectors)
|
|
276
278
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Maybe } from "@thi.ng/api";
|
|
2
|
+
import type { IGridLayout, LayoutBox } from "@thi.ng/layout";
|
|
3
|
+
import type { Ramp } from "@thi.ng/ramp";
|
|
4
|
+
import type { IMGUI } from "../gui.js";
|
|
5
|
+
export declare const ramp: (gui: IMGUI, layout: IGridLayout<any> | LayoutBox, id: string, ramp: Ramp<number>, rampMode?: number, info?: string) => Maybe<Ramp<number>>;
|
|
6
|
+
//# sourceMappingURL=ramp.d.ts.map
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { group } from "@thi.ng/geom/group";
|
|
2
|
+
import { line } from "@thi.ng/geom/line";
|
|
3
|
+
import { polygon } from "@thi.ng/geom/polygon";
|
|
4
|
+
import { rect } from "@thi.ng/geom/rect";
|
|
5
|
+
import { triangle } from "@thi.ng/geom/triangle";
|
|
6
|
+
import { mix } from "@thi.ng/math/mix";
|
|
7
|
+
import { roundTo } from "@thi.ng/math/prec";
|
|
8
|
+
import { map } from "@thi.ng/transducers/map";
|
|
9
|
+
import { ONE2, ZERO2 } from "@thi.ng/vectors/api";
|
|
10
|
+
import { fit2 } from "@thi.ng/vectors/fit";
|
|
11
|
+
import { hash } from "@thi.ng/vectors/hash";
|
|
12
|
+
import { mix2 } from "@thi.ng/vectors/mix";
|
|
13
|
+
import { Key } from "../api.js";
|
|
14
|
+
import { isHoverSlider } from "../behaviors/slider.js";
|
|
15
|
+
import { layoutBox } from "../layout.js";
|
|
16
|
+
import { tooltipRaw } from "./tooltip.js";
|
|
17
|
+
const ramp = (gui, layout, id, ramp2, rampMode = 0, info) => {
|
|
18
|
+
let { x, y, w, h } = layoutBox(layout);
|
|
19
|
+
const maxX = x + w;
|
|
20
|
+
const maxY = y + h;
|
|
21
|
+
const pos = [x, maxY];
|
|
22
|
+
const maxPos = [maxX, y];
|
|
23
|
+
const key = hash([x, y, w, h]);
|
|
24
|
+
gui.registerID(id, key);
|
|
25
|
+
const box = gui.resource(id, key, () => rect([x, y], [w, h]));
|
|
26
|
+
const col = gui.textColor(false);
|
|
27
|
+
const hover = isHoverSlider(gui, id, box, "move");
|
|
28
|
+
const stops = ramp2.stops;
|
|
29
|
+
let selID = -1;
|
|
30
|
+
let sel;
|
|
31
|
+
let res;
|
|
32
|
+
const focused = gui.requestFocus(id);
|
|
33
|
+
if (hover) {
|
|
34
|
+
sel = fit2([], gui.mouse, pos, maxPos, ZERO2, ONE2);
|
|
35
|
+
selID = ramp2.closestIndex(sel[0], 0.05);
|
|
36
|
+
if (gui.isMouseDown()) {
|
|
37
|
+
gui.activeID = id;
|
|
38
|
+
if (selID >= 0) {
|
|
39
|
+
stops[selID] = sel;
|
|
40
|
+
} else {
|
|
41
|
+
ramp2.setStopAt(
|
|
42
|
+
roundTo(sel[0], 1e-3),
|
|
43
|
+
roundTo(sel[1], 1e-3),
|
|
44
|
+
0.05
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
res = ramp2;
|
|
48
|
+
}
|
|
49
|
+
if (focused && selID >= 0 && handleRampKeys(gui, ramp2, selID)) {
|
|
50
|
+
res = ramp2;
|
|
51
|
+
}
|
|
52
|
+
info && gui.draw && tooltipRaw(gui, info);
|
|
53
|
+
}
|
|
54
|
+
if (gui.draw) {
|
|
55
|
+
box.attribs = {
|
|
56
|
+
fill: gui.bgColor(hover || focused),
|
|
57
|
+
stroke: gui.focusColor(id)
|
|
58
|
+
};
|
|
59
|
+
gui.add(
|
|
60
|
+
box,
|
|
61
|
+
gui.resource(
|
|
62
|
+
id,
|
|
63
|
+
hash(stops.flatMap((x2) => x2)) + rampMode,
|
|
64
|
+
() => polygon(
|
|
65
|
+
[
|
|
66
|
+
[x, maxY],
|
|
67
|
+
mix2([], pos, maxPos, [0, stops[0][1]]),
|
|
68
|
+
...rampVertices(ramp2, pos, maxPos),
|
|
69
|
+
mix2([], pos, maxPos, [1, stops[stops.length - 1][1]]),
|
|
70
|
+
[maxX, maxY]
|
|
71
|
+
],
|
|
72
|
+
{ fill: col }
|
|
73
|
+
)
|
|
74
|
+
),
|
|
75
|
+
...stops.map(([t], i) => {
|
|
76
|
+
const xx = mix(x, maxX, t);
|
|
77
|
+
return triangle(
|
|
78
|
+
[
|
|
79
|
+
[xx - 5, maxY],
|
|
80
|
+
[xx + 5, maxY],
|
|
81
|
+
[xx, maxY - 5]
|
|
82
|
+
],
|
|
83
|
+
{ fill: gui.fgColor(selID === i) }
|
|
84
|
+
);
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
if (sel) {
|
|
88
|
+
const [cx, cy] = mix2([], pos, maxPos, sel);
|
|
89
|
+
gui.add(
|
|
90
|
+
group({ stroke: gui.fgColor(selID >= 0) }, [
|
|
91
|
+
line([x, cy], [maxX, cy]),
|
|
92
|
+
line([cx, y], [cx, maxY])
|
|
93
|
+
])
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
gui.lastID = id;
|
|
98
|
+
return res;
|
|
99
|
+
};
|
|
100
|
+
const rampVertices = (ramp2, pos, maxPos, numSamples = 100) => map((p) => mix2(p, pos, maxPos, p), ramp2.samples(numSamples));
|
|
101
|
+
const handleRampKeys = (gui, ramp2, selID) => {
|
|
102
|
+
switch (gui.key) {
|
|
103
|
+
case Key.TAB:
|
|
104
|
+
gui.switchFocus();
|
|
105
|
+
break;
|
|
106
|
+
case "x":
|
|
107
|
+
case Key.DELETE:
|
|
108
|
+
ramp2.removeStopAtIndex(selID);
|
|
109
|
+
return true;
|
|
110
|
+
default:
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
export {
|
|
114
|
+
ramp
|
|
115
|
+
};
|
|
@@ -4,7 +4,7 @@ import type { ReadonlyVec } from "@thi.ng/vectors";
|
|
|
4
4
|
import type { Color, GUITheme } from "../api.js";
|
|
5
5
|
import type { IMGUI } from "../gui.js";
|
|
6
6
|
export declare const textLabel: (gui: IMGUI, layout: IGridLayout<any> | LayoutBox, label: string, pad?: boolean) => void;
|
|
7
|
-
export declare const textLabelRaw: (p: ReadonlyVec, attribs: Color | any, label: string) => (
|
|
7
|
+
export declare const textLabelRaw: (p: ReadonlyVec, attribs: Color | any, label: string) => import("@thi.ng/geom").Text;
|
|
8
8
|
export declare const textTransformH: (theme: GUITheme, x: number, y: number, _: number, h: number) => number[];
|
|
9
9
|
export declare const textTransformV: (theme: GUITheme, x: number, y: number, w: number, h: number) => number[];
|
|
10
10
|
export declare const dialValueLabel: (gui: IMGUI, id: string, key: number, v: number, x: number, y: number, label: Maybe<string>, fmt: Maybe<Fn<number, string>>) => any;
|
package/components/textlabel.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { isPlainObject } from "@thi.ng/checks/is-plain-object";
|
|
2
|
+
import { text } from "@thi.ng/geom/text";
|
|
2
3
|
import { valHash } from "../hash.js";
|
|
3
4
|
import { layoutBox } from "../layout.js";
|
|
4
5
|
const textLabel = (gui, layout, label, pad = false) => {
|
|
5
6
|
const theme = gui.theme;
|
|
6
7
|
const { x, y, h } = layoutBox(layout);
|
|
7
|
-
gui.draw && gui.add(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
gui.draw && gui.add(
|
|
9
|
+
text(
|
|
10
|
+
[x + (pad ? theme.pad : 0), y + h / 2 + theme.baseLine],
|
|
11
|
+
label,
|
|
12
|
+
{ fill: gui.textColor(false) }
|
|
13
|
+
)
|
|
14
|
+
);
|
|
13
15
|
};
|
|
14
|
-
const textLabelRaw = (p, attribs, label) =>
|
|
16
|
+
const textLabelRaw = (p, attribs, label) => text(p, label, isPlainObject(attribs) ? attribs : { fill: attribs });
|
|
15
17
|
const textTransformH = (theme, x, y, _, h) => [1, 0, 0, 1, x + theme.pad, y + h / 2 + theme.baseLine];
|
|
16
18
|
const textTransformV = (theme, x, y, w, h) => [0, -1, 1, 0, x + w / 2 + theme.baseLine, y + h - theme.pad];
|
|
17
19
|
const dialValueLabel = (gui, id, key, v, x, y, label, fmt) => gui.resource(
|
package/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from "./components/dropdown.js";
|
|
|
7
7
|
export * from "./components/icon-button.js";
|
|
8
8
|
export * from "./components/radial-menu.js";
|
|
9
9
|
export * from "./components/radio.js";
|
|
10
|
+
export * from "./components/ramp.js";
|
|
10
11
|
export * from "./components/ring.js";
|
|
11
12
|
export * from "./components/sliderh.js";
|
|
12
13
|
export * from "./components/sliderv.js";
|
package/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export * from "./components/dropdown.js";
|
|
|
7
7
|
export * from "./components/icon-button.js";
|
|
8
8
|
export * from "./components/radial-menu.js";
|
|
9
9
|
export * from "./components/radio.js";
|
|
10
|
+
export * from "./components/ramp.js";
|
|
10
11
|
export * from "./components/ring.js";
|
|
11
12
|
export * from "./components/sliderh.js";
|
|
12
13
|
export * from "./components/sliderv.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/imgui",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Immediate mode GUI with flexible state handling & data only shape output",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -38,12 +38,13 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@thi.ng/api": "^8.11.9",
|
|
40
40
|
"@thi.ng/checks": "^3.6.11",
|
|
41
|
-
"@thi.ng/geom": "^8.1.
|
|
42
|
-
"@thi.ng/geom-isec": "^4.0.
|
|
41
|
+
"@thi.ng/geom": "^8.1.7",
|
|
42
|
+
"@thi.ng/geom-isec": "^4.0.12",
|
|
43
43
|
"@thi.ng/layout": "^3.1.1",
|
|
44
|
-
"@thi.ng/math": "^5.11.
|
|
45
|
-
"@thi.ng/
|
|
46
|
-
"@thi.ng/
|
|
44
|
+
"@thi.ng/math": "^5.11.9",
|
|
45
|
+
"@thi.ng/ramp": "^3.3.0",
|
|
46
|
+
"@thi.ng/transducers": "^9.2.2",
|
|
47
|
+
"@thi.ng/vectors": "^7.12.0"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@microsoft/api-extractor": "^7.47.5",
|
|
@@ -111,6 +112,9 @@
|
|
|
111
112
|
"./components/radio": {
|
|
112
113
|
"default": "./components/radio.js"
|
|
113
114
|
},
|
|
115
|
+
"./components/ramp": {
|
|
116
|
+
"default": "./components/ramp.js"
|
|
117
|
+
},
|
|
114
118
|
"./components/ring": {
|
|
115
119
|
"default": "./components/ring.js"
|
|
116
120
|
},
|
|
@@ -156,5 +160,5 @@
|
|
|
156
160
|
],
|
|
157
161
|
"year": 2019
|
|
158
162
|
},
|
|
159
|
-
"gitHead": "
|
|
163
|
+
"gitHead": "9f71f7f82fed2a980078a96bdafd2e706f526c75\n"
|
|
160
164
|
}
|