sfml.js-imgui 0.0.0-stage → 1.2.1
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/README.ja.md +113 -0
- package/README.ko.md +113 -0
- package/README.md +112 -2
- package/README.zh-CN.md +113 -0
- package/binding.gyp +125 -0
- package/dist/callbacks.d.ts +368 -0
- package/dist/callbacks.js +310 -0
- package/dist/enums/colors.d.ts +779 -0
- package/dist/enums/colors.js +766 -0
- package/dist/enums/drawing.d.ts +286 -0
- package/dist/enums/drawing.js +257 -0
- package/dist/enums/input.d.ts +792 -0
- package/dist/enums/input.js +731 -0
- package/dist/enums/keys.d.ts +1389 -0
- package/dist/enums/keys.js +1384 -0
- package/dist/enums/selection.d.ts +195 -0
- package/dist/enums/selection.js +182 -0
- package/dist/enums/style.d.ts +362 -0
- package/dist/enums/style.js +349 -0
- package/dist/enums/tables.d.ts +681 -0
- package/dist/enums/tables.js +644 -0
- package/dist/enums/text.d.ts +411 -0
- package/dist/enums/text.js +390 -0
- package/dist/enums/widgets.d.ts +861 -0
- package/dist/enums/widgets.js +800 -0
- package/dist/enums/windows.d.ts +487 -0
- package/dist/enums/windows.js +458 -0
- package/dist/enums.d.ts +10 -0
- package/dist/enums.js +26 -0
- package/dist/font.d.ts +249 -0
- package/dist/font.js +285 -0
- package/dist/formatted.d.ts +301 -0
- package/dist/formatted.js +342 -0
- package/dist/imgui/color.d.ts +493 -0
- package/dist/imgui/color.js +532 -0
- package/dist/imgui/columns.d.ts +242 -0
- package/dist/imgui/columns.js +273 -0
- package/dist/imgui/combo.d.ts +322 -0
- package/dist/imgui/combo.js +344 -0
- package/dist/imgui/context.d.ts +240 -0
- package/dist/imgui/context.js +270 -0
- package/dist/imgui/debug.d.ts +478 -0
- package/dist/imgui/debug.js +526 -0
- package/dist/imgui/drag-drop.d.ts +378 -0
- package/dist/imgui/drag-drop.js +414 -0
- package/dist/imgui/drag.d.ts +1371 -0
- package/dist/imgui/drag.js +1447 -0
- package/dist/imgui/draw-data.d.ts +139 -0
- package/dist/imgui/draw-data.js +154 -0
- package/dist/imgui/draw-list-images.d.ts +306 -0
- package/dist/imgui/draw-list-images.js +324 -0
- package/dist/imgui/draw-list-internals.d.ts +223 -0
- package/dist/imgui/draw-list-internals.js +259 -0
- package/dist/imgui/draw-list-path.d.ts +451 -0
- package/dist/imgui/draw-list-path.js +493 -0
- package/dist/imgui/draw-list-primitives.d.ts +297 -0
- package/dist/imgui/draw-list-primitives.js +324 -0
- package/dist/imgui/draw-list-shapes.d.ts +1258 -0
- package/dist/imgui/draw-list-shapes.js +1345 -0
- package/dist/imgui/draw-list-state.d.ts +458 -0
- package/dist/imgui/draw-list-state.js +515 -0
- package/dist/imgui/draw-list-text.d.ts +367 -0
- package/dist/imgui/draw-list-text.js +247 -0
- package/dist/imgui/drawing.d.ts +151 -0
- package/dist/imgui/drawing.js +169 -0
- package/dist/imgui/font-atlas.d.ts +726 -0
- package/dist/imgui/font-atlas.js +777 -0
- package/dist/imgui/font-glyph-ranges.d.ts +260 -0
- package/dist/imgui/font-glyph-ranges.js +230 -0
- package/dist/imgui/fonts.d.ts +114 -0
- package/dist/imgui/fonts.js +132 -0
- package/dist/imgui/id-stack.d.ts +363 -0
- package/dist/imgui/id-stack.js +309 -0
- package/dist/imgui/images.d.ts +310 -0
- package/dist/imgui/images.js +331 -0
- package/dist/imgui/index.d.ts +57 -0
- package/dist/imgui/index.js +73 -0
- package/dist/imgui/input-text-callback.d.ts +176 -0
- package/dist/imgui/input-text-callback.js +144 -0
- package/dist/imgui/inputs.d.ts +1086 -0
- package/dist/imgui/inputs.js +1159 -0
- package/dist/imgui/io.d.ts +546 -0
- package/dist/imgui/io.js +600 -0
- package/dist/imgui/item-state.d.ts +766 -0
- package/dist/imgui/item-state.js +850 -0
- package/dist/imgui/keyboard.d.ts +547 -0
- package/dist/imgui/keyboard.js +584 -0
- package/dist/imgui/layout.d.ts +927 -0
- package/dist/imgui/layout.js +1029 -0
- package/dist/imgui/legacy.d.ts +413 -0
- package/dist/imgui/legacy.js +461 -0
- package/dist/imgui/list-clipper.d.ts +282 -0
- package/dist/imgui/list-clipper.js +309 -0
- package/dist/imgui/logging.d.ts +113 -0
- package/dist/imgui/logging.js +135 -0
- package/dist/imgui/memory.d.ts +35 -0
- package/dist/imgui/memory.js +45 -0
- package/dist/imgui/menus.d.ts +373 -0
- package/dist/imgui/menus.js +407 -0
- package/dist/imgui/mouse.d.ts +740 -0
- package/dist/imgui/mouse.js +803 -0
- package/dist/imgui/plots.d.ts +252 -0
- package/dist/imgui/plots.js +267 -0
- package/dist/imgui/popups.d.ts +711 -0
- package/dist/imgui/popups.js +757 -0
- package/dist/imgui/scrolling.d.ts +341 -0
- package/dist/imgui/scrolling.js +375 -0
- package/dist/imgui/selection.d.ts +785 -0
- package/dist/imgui/selection.js +845 -0
- package/dist/imgui/settings.d.ts +194 -0
- package/dist/imgui/settings.js +216 -0
- package/dist/imgui/sliders.d.ts +1664 -0
- package/dist/imgui/sliders.js +1751 -0
- package/dist/imgui/storage.d.ts +344 -0
- package/dist/imgui/storage.js +386 -0
- package/dist/imgui/style.d.ts +680 -0
- package/dist/imgui/style.js +770 -0
- package/dist/imgui/tables.d.ts +762 -0
- package/dist/imgui/tables.js +831 -0
- package/dist/imgui/tabs.d.ts +228 -0
- package/dist/imgui/tabs.js +250 -0
- package/dist/imgui/text-buffer.d.ts +251 -0
- package/dist/imgui/text-buffer.js +239 -0
- package/dist/imgui/text-filter.d.ts +181 -0
- package/dist/imgui/text-filter.js +151 -0
- package/dist/imgui/text.d.ts +506 -0
- package/dist/imgui/text.js +425 -0
- package/dist/imgui/tooltips.d.ts +202 -0
- package/dist/imgui/tooltips.js +221 -0
- package/dist/imgui/trees.d.ts +516 -0
- package/dist/imgui/trees.js +562 -0
- package/dist/imgui/viewport.d.ts +93 -0
- package/dist/imgui/viewport.js +105 -0
- package/dist/imgui/widgets.d.ts +524 -0
- package/dist/imgui/widgets.js +572 -0
- package/dist/imgui/windows.d.ts +1210 -0
- package/dist/imgui/windows.js +1309 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +19 -0
- package/dist/internal/imgui-binding.d.ts +40 -0
- package/dist/internal/imgui-binding.js +2 -0
- package/dist/internal/native.d.ts +67 -0
- package/dist/internal/native.js +7 -0
- package/dist/internal/sfml-interop.d.ts +45 -0
- package/dist/internal/sfml-interop.js +102 -0
- package/dist/references.d.ts +393 -0
- package/dist/references.js +372 -0
- package/dist/sfml.d.ts +223 -0
- package/dist/sfml.js +320 -0
- package/dist/struct-views.d.ts +3056 -0
- package/dist/struct-views.js +418 -0
- package/dist/types.d.ts +508 -0
- package/dist/types.js +2 -0
- package/native/addon.cc +68 -0
- package/native/cimgui.h +12 -0
- package/native/imgui-args.h +492 -0
- package/native/imgui-bindings.h +35 -0
- package/native/imgui-callbacks.cc +376 -0
- package/native/imgui-context.cc +117 -0
- package/native/imgui-debug.cc +171 -0
- package/native/imgui-drag-drop.cc +120 -0
- package/native/imgui-drag-widgets.cc +473 -0
- package/native/imgui-draw-callbacks.cc +210 -0
- package/native/imgui-draw-callbacks.h +25 -0
- package/native/imgui-draw-paths.cc +413 -0
- package/native/imgui-draw-primitives.cc +317 -0
- package/native/imgui-drawing.cc +963 -0
- package/native/imgui-font-ranges.cc +73 -0
- package/native/imgui-font.cc +488 -0
- package/native/imgui-formatted.cc +388 -0
- package/native/imgui-frame.cc +56 -0
- package/native/imgui-glyph-fields.cc +87 -0
- package/native/imgui-glyph-fields.h +12 -0
- package/native/imgui-input-widgets.cc +447 -0
- package/native/imgui-input.cc +277 -0
- package/native/imgui-integration.cc +442 -0
- package/native/imgui-io.cc +255 -0
- package/native/imgui-items.cc +290 -0
- package/native/imgui-layout.cc +349 -0
- package/native/imgui-popups.cc +331 -0
- package/native/imgui-references.cc +230 -0
- package/native/imgui-selection.cc +394 -0
- package/native/imgui-slider-widgets.cc +550 -0
- package/native/imgui-storage.cc +177 -0
- package/native/imgui-struct-views.cc +626 -0
- package/native/imgui-style.cc +283 -0
- package/native/imgui-tables.cc +267 -0
- package/native/imgui-text.cc +291 -0
- package/native/imgui-utilities.cc +127 -0
- package/native/imgui-values.cc +66 -0
- package/native/imgui-widgets.cc +570 -0
- package/native/imgui-windows.cc +436 -0
- package/native/interop.h +19 -0
- package/package.json +72 -3
- package/src/callbacks.ts +447 -0
- package/src/enums/colors.ts +782 -0
- package/src/enums/drawing.ts +293 -0
- package/src/enums/input.ts +807 -0
- package/src/enums/keys.ts +1390 -0
- package/src/enums/selection.ts +198 -0
- package/src/enums/style.ts +365 -0
- package/src/enums/tables.ts +690 -0
- package/src/enums/text.ts +416 -0
- package/src/enums/widgets.ts +876 -0
- package/src/enums/windows.ts +494 -0
- package/src/enums.ts +10 -0
- package/src/font.ts +287 -0
- package/src/formatted.ts +386 -0
- package/src/imgui/color.ts +575 -0
- package/src/imgui/columns.ts +274 -0
- package/src/imgui/combo.ts +376 -0
- package/src/imgui/context.ts +268 -0
- package/src/imgui/debug.ts +542 -0
- package/src/imgui/drag-drop.ts +423 -0
- package/src/imgui/drag.ts +1615 -0
- package/src/imgui/draw-data.ts +158 -0
- package/src/imgui/draw-list-images.ts +394 -0
- package/src/imgui/draw-list-internals.ts +291 -0
- package/src/imgui/draw-list-path.ts +568 -0
- package/src/imgui/draw-list-primitives.ts +363 -0
- package/src/imgui/draw-list-shapes.ts +1593 -0
- package/src/imgui/draw-list-state.ts +551 -0
- package/src/imgui/draw-list-text.ts +594 -0
- package/src/imgui/drawing.ts +170 -0
- package/src/imgui/font-atlas.ts +862 -0
- package/src/imgui/font-glyph-ranges.ts +357 -0
- package/src/imgui/fonts.ts +133 -0
- package/src/imgui/id-stack.ts +496 -0
- package/src/imgui/images.ts +364 -0
- package/src/imgui/index.ts +57 -0
- package/src/imgui/input-text-callback.ts +268 -0
- package/src/imgui/inputs.ts +1292 -0
- package/src/imgui/io.ts +638 -0
- package/src/imgui/item-state.ts +856 -0
- package/src/imgui/keyboard.ts +590 -0
- package/src/imgui/layout.ts +1030 -0
- package/src/imgui/legacy.ts +477 -0
- package/src/imgui/list-clipper.ts +329 -0
- package/src/imgui/logging.ts +135 -0
- package/src/imgui/memory.ts +42 -0
- package/src/imgui/menus.ts +417 -0
- package/src/imgui/mouse.ts +824 -0
- package/src/imgui/plots.ts +313 -0
- package/src/imgui/popups.ts +779 -0
- package/src/imgui/scrolling.ts +378 -0
- package/src/imgui/selection.ts +904 -0
- package/src/imgui/settings.ts +220 -0
- package/src/imgui/sliders.ts +1969 -0
- package/src/imgui/storage.ts +415 -0
- package/src/imgui/style.ts +781 -0
- package/src/imgui/tables.ts +854 -0
- package/src/imgui/tabs.ts +259 -0
- package/src/imgui/text-buffer.ts +337 -0
- package/src/imgui/text-filter.ts +262 -0
- package/src/imgui/text.ts +688 -0
- package/src/imgui/tooltips.ts +218 -0
- package/src/imgui/trees.ts +583 -0
- package/src/imgui/viewport.ts +103 -0
- package/src/imgui/widgets.ts +599 -0
- package/src/imgui/windows.ts +1350 -0
- package/src/index.ts +21 -0
- package/src/internal/imgui-binding.ts +142 -0
- package/src/internal/native.ts +163 -0
- package/src/internal/sfml-interop.ts +171 -0
- package/src/references.ts +464 -0
- package/src/sfml.ts +412 -0
- package/src/struct-views.ts +3194 -0
- package/src/types.ts +539 -0
- package/tools/deps_downloader.cjs +213 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
// Copyright (c) 2026 XadillaX
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
#include <nan.h>
|
|
5
|
+
#include <sfml-js-interop.h>
|
|
6
|
+
|
|
7
|
+
#include <cstddef>
|
|
8
|
+
#include <cstdint>
|
|
9
|
+
#include <cstdio>
|
|
10
|
+
#include <cstring>
|
|
11
|
+
#include <string>
|
|
12
|
+
#include <vector>
|
|
13
|
+
|
|
14
|
+
#include "native/imgui-args.h"
|
|
15
|
+
|
|
16
|
+
namespace sfmlimgui {
|
|
17
|
+
namespace {
|
|
18
|
+
|
|
19
|
+
using CallbackInfo = Nan::FunctionCallbackInfo<v8::Value>;
|
|
20
|
+
|
|
21
|
+
bool ReadSigned(v8::Local<v8::Value> value, std::int64_t* output) {
|
|
22
|
+
if (value->IsBigInt()) {
|
|
23
|
+
bool lossless = false;
|
|
24
|
+
*output = value.As<v8::BigInt>()->Int64Value(&lossless);
|
|
25
|
+
if (!lossless) {
|
|
26
|
+
Nan::ThrowRangeError("Expected a lossless integer");
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
if (!value->IsNumber()) {
|
|
32
|
+
Nan::ThrowTypeError("Expected a number or bigint");
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
*output = static_cast<std::int64_t>(Nan::To<double>(value).FromJust());
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
bool ReadUnsigned(v8::Local<v8::Value> value, std::uint64_t* output) {
|
|
40
|
+
if (value->IsBigInt()) {
|
|
41
|
+
bool lossless = false;
|
|
42
|
+
*output = value.As<v8::BigInt>()->Uint64Value(&lossless);
|
|
43
|
+
if (!lossless) {
|
|
44
|
+
Nan::ThrowRangeError("Expected a lossless integer");
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
if (!value->IsNumber()) {
|
|
50
|
+
Nan::ThrowTypeError("Expected a number or bigint");
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
const double number = Nan::To<double>(value).FromJust();
|
|
54
|
+
if (number < 0) {
|
|
55
|
+
Nan::ThrowRangeError("Expected a non-negative number");
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
*output = static_cast<std::uint64_t>(number);
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
bool ReadDouble(v8::Local<v8::Value> value, double* output) {
|
|
63
|
+
if (!value->IsNumber()) {
|
|
64
|
+
Nan::ThrowTypeError("Expected a number");
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
*output = Nan::To<double>(value).FromJust();
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// JS has no va_list, so each conversion is expanded one argument at a time.
|
|
72
|
+
// Returns the written length, or -1 after throwing.
|
|
73
|
+
|
|
74
|
+
int FormatSingle(char* buffer,
|
|
75
|
+
std::size_t size,
|
|
76
|
+
const std::string& format,
|
|
77
|
+
char specifier,
|
|
78
|
+
v8::Local<v8::Value> value) {
|
|
79
|
+
switch (specifier) {
|
|
80
|
+
case 's': {
|
|
81
|
+
if (value->IsUint8Array()) {
|
|
82
|
+
auto bytes = value.As<v8::Uint8Array>();
|
|
83
|
+
std::string text(reinterpret_cast<const char*>(
|
|
84
|
+
bytes->Buffer()->GetBackingStore()->Data()) +
|
|
85
|
+
bytes->ByteOffset(),
|
|
86
|
+
bytes->Length());
|
|
87
|
+
return std::snprintf(buffer, size, format.c_str(), text.c_str());
|
|
88
|
+
}
|
|
89
|
+
if (!value->IsString()) {
|
|
90
|
+
Nan::ThrowTypeError("Expected a string for %s");
|
|
91
|
+
return -1;
|
|
92
|
+
}
|
|
93
|
+
Nan::Utf8String text(value);
|
|
94
|
+
return std::snprintf(buffer, size, format.c_str(), *text);
|
|
95
|
+
}
|
|
96
|
+
case 'c': {
|
|
97
|
+
std::int64_t number = 0;
|
|
98
|
+
if (!ReadSigned(value, &number)) return -1;
|
|
99
|
+
return std::snprintf(
|
|
100
|
+
buffer, size, format.c_str(), static_cast<int>(number));
|
|
101
|
+
}
|
|
102
|
+
case 'd':
|
|
103
|
+
case 'i': {
|
|
104
|
+
std::int64_t number = 0;
|
|
105
|
+
if (!ReadSigned(value, &number)) return -1;
|
|
106
|
+
return std::snprintf(
|
|
107
|
+
buffer, size, format.c_str(), static_cast<std::intmax_t>(number));
|
|
108
|
+
}
|
|
109
|
+
case 'u':
|
|
110
|
+
case 'o':
|
|
111
|
+
case 'x':
|
|
112
|
+
case 'X': {
|
|
113
|
+
std::uint64_t number = 0;
|
|
114
|
+
if (!ReadUnsigned(value, &number)) return -1;
|
|
115
|
+
return std::snprintf(
|
|
116
|
+
buffer, size, format.c_str(), static_cast<std::uintmax_t>(number));
|
|
117
|
+
}
|
|
118
|
+
case 'f':
|
|
119
|
+
case 'F':
|
|
120
|
+
case 'e':
|
|
121
|
+
case 'E':
|
|
122
|
+
case 'g':
|
|
123
|
+
case 'G':
|
|
124
|
+
case 'a':
|
|
125
|
+
case 'A': {
|
|
126
|
+
double number = 0;
|
|
127
|
+
if (!ReadDouble(value, &number)) return -1;
|
|
128
|
+
return std::snprintf(buffer, size, format.c_str(), number);
|
|
129
|
+
}
|
|
130
|
+
case 'p': {
|
|
131
|
+
std::uint64_t number = 0;
|
|
132
|
+
if (!ReadUnsigned(value, &number)) return -1;
|
|
133
|
+
return std::snprintf(
|
|
134
|
+
buffer,
|
|
135
|
+
size,
|
|
136
|
+
format.c_str(),
|
|
137
|
+
reinterpret_cast<void*>(static_cast<std::uintptr_t>(number)));
|
|
138
|
+
}
|
|
139
|
+
default:
|
|
140
|
+
return std::snprintf(buffer, size, "%s", format.c_str());
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Retries with a larger buffer when the first pass exceeds the stack buffer.
|
|
145
|
+
|
|
146
|
+
bool AppendValue(std::string* out,
|
|
147
|
+
const std::string& prefix,
|
|
148
|
+
char specifier,
|
|
149
|
+
v8::Local<v8::Value> value) {
|
|
150
|
+
std::string format = prefix;
|
|
151
|
+
switch (specifier) {
|
|
152
|
+
case 'd':
|
|
153
|
+
case 'i':
|
|
154
|
+
case 'u':
|
|
155
|
+
case 'o':
|
|
156
|
+
case 'x':
|
|
157
|
+
case 'X':
|
|
158
|
+
format += 'j';
|
|
159
|
+
break;
|
|
160
|
+
default:
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
format += specifier;
|
|
164
|
+
|
|
165
|
+
char buffer[512];
|
|
166
|
+
int length = FormatSingle(buffer, sizeof(buffer), format, specifier, value);
|
|
167
|
+
if (length < 0) return false;
|
|
168
|
+
if (static_cast<std::size_t>(length) < sizeof(buffer)) {
|
|
169
|
+
out->append(buffer, static_cast<std::size_t>(length));
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
std::vector<char> large(static_cast<std::size_t>(length) + 1);
|
|
173
|
+
length = FormatSingle(large.data(), large.size(), format, specifier, value);
|
|
174
|
+
if (length < 0) return false;
|
|
175
|
+
out->append(large.data(), static_cast<std::size_t>(length));
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Positional and dynamic-width conversions are rejected; they cannot be
|
|
180
|
+
// resolved without consuming arguments out of order.
|
|
181
|
+
|
|
182
|
+
bool FormatArguments(const CallbackInfo& info,
|
|
183
|
+
unsigned formatIndex,
|
|
184
|
+
unsigned argsIndex,
|
|
185
|
+
std::string* out) {
|
|
186
|
+
std::string formatStorage;
|
|
187
|
+
const char* format = nullptr;
|
|
188
|
+
if (!ReadUtf8(info, formatIndex, &formatStorage, &format, false)) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
if (!info[argsIndex]->IsArray()) {
|
|
192
|
+
Nan::ThrowTypeError("Expected an argument array");
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
auto args = info[argsIndex].As<v8::Array>();
|
|
196
|
+
std::uint32_t argument = 0;
|
|
197
|
+
const char* cursor = format;
|
|
198
|
+
|
|
199
|
+
while (*cursor) {
|
|
200
|
+
if (*cursor != '%') {
|
|
201
|
+
out->push_back(*cursor++);
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
const char* start = cursor++;
|
|
205
|
+
if (*cursor == '%') {
|
|
206
|
+
out->push_back('%');
|
|
207
|
+
++cursor;
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
while (*cursor && std::strchr("-+ #0", *cursor)) ++cursor;
|
|
211
|
+
if (*cursor == '*') {
|
|
212
|
+
Nan::ThrowError("Dynamic width is not supported");
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
while (*cursor >= '0' && *cursor <= '9') ++cursor;
|
|
216
|
+
if (*cursor == '*') {
|
|
217
|
+
Nan::ThrowError("Dynamic precision is not supported");
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
if (*cursor == '.') {
|
|
221
|
+
++cursor;
|
|
222
|
+
while (*cursor >= '0' && *cursor <= '9') ++cursor;
|
|
223
|
+
}
|
|
224
|
+
const char* prefixEnd = cursor;
|
|
225
|
+
while (*cursor == 'h' || *cursor == 'l' || *cursor == 'j' ||
|
|
226
|
+
*cursor == 'z' || *cursor == 't' || *cursor == 'L') {
|
|
227
|
+
++cursor;
|
|
228
|
+
}
|
|
229
|
+
const char specifier = *cursor;
|
|
230
|
+
if (!specifier) {
|
|
231
|
+
out->append(start, cursor);
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
++cursor;
|
|
235
|
+
if (argument >= args->Length()) {
|
|
236
|
+
Nan::ThrowRangeError("Not enough format arguments");
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
auto value = Nan::Get(args, argument++).ToLocalChecked();
|
|
240
|
+
if (!AppendValue(out, std::string(start, prefixEnd), specifier, value)) {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
bool Format(const CallbackInfo& info,
|
|
248
|
+
unsigned formatIndex,
|
|
249
|
+
unsigned argsIndex,
|
|
250
|
+
std::string* out) {
|
|
251
|
+
return FormatArguments(info, formatIndex, argsIndex, out);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
NAN_METHOD(Text) {
|
|
255
|
+
std::string message;
|
|
256
|
+
if (!Format(info, 0, 1, &message)) return;
|
|
257
|
+
::cimgui::ImGui_Text("%s", message.c_str());
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
NAN_METHOD(TextColored) {
|
|
261
|
+
cimgui::ImVec4 color;
|
|
262
|
+
if (!ReadImVec4(info, 0, &color)) return;
|
|
263
|
+
std::string message;
|
|
264
|
+
if (!Format(info, 1, 2, &message)) return;
|
|
265
|
+
::cimgui::ImGui_TextColored(color, "%s", message.c_str());
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
NAN_METHOD(TextDisabled) {
|
|
269
|
+
std::string message;
|
|
270
|
+
if (!Format(info, 0, 1, &message)) return;
|
|
271
|
+
::cimgui::ImGui_TextDisabled("%s", message.c_str());
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
NAN_METHOD(TextWrapped) {
|
|
275
|
+
std::string message;
|
|
276
|
+
if (!Format(info, 0, 1, &message)) return;
|
|
277
|
+
::cimgui::ImGui_TextWrapped("%s", message.c_str());
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
NAN_METHOD(LabelText) {
|
|
281
|
+
std::string labelStorage;
|
|
282
|
+
const char* label = nullptr;
|
|
283
|
+
if (!ReadUtf8(info, 0, &labelStorage, &label, false)) return;
|
|
284
|
+
std::string message;
|
|
285
|
+
if (!Format(info, 1, 2, &message)) return;
|
|
286
|
+
::cimgui::ImGui_LabelText(label, "%s", message.c_str());
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
NAN_METHOD(BulletText) {
|
|
290
|
+
std::string message;
|
|
291
|
+
if (!Format(info, 0, 1, &message)) return;
|
|
292
|
+
::cimgui::ImGui_BulletText("%s", message.c_str());
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
NAN_METHOD(TreeNodeStr) {
|
|
296
|
+
std::string idStorage;
|
|
297
|
+
const char* id = nullptr;
|
|
298
|
+
if (!ReadUtf8(info, 0, &idStorage, &id, false)) return;
|
|
299
|
+
std::string message;
|
|
300
|
+
if (!Format(info, 1, 2, &message)) return;
|
|
301
|
+
info.GetReturnValue().Set(
|
|
302
|
+
::cimgui::ImGui_TreeNodeStr(id, "%s", message.c_str()));
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
NAN_METHOD(TreeNodePtr) {
|
|
306
|
+
void* id = nullptr;
|
|
307
|
+
if (!ReadPointer(info, 0, &id)) return;
|
|
308
|
+
std::string message;
|
|
309
|
+
if (!Format(info, 1, 2, &message)) return;
|
|
310
|
+
info.GetReturnValue().Set(
|
|
311
|
+
::cimgui::ImGui_TreeNodePtr(id, "%s", message.c_str()));
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
NAN_METHOD(TreeNodeExStr) {
|
|
315
|
+
std::string idStorage;
|
|
316
|
+
const char* id = nullptr;
|
|
317
|
+
if (!ReadUtf8(info, 0, &idStorage, &id, false)) return;
|
|
318
|
+
int flags = 0;
|
|
319
|
+
if (!ReadScalar(info, 1, &flags)) return;
|
|
320
|
+
std::string message;
|
|
321
|
+
if (!Format(info, 2, 3, &message)) return;
|
|
322
|
+
info.GetReturnValue().Set(
|
|
323
|
+
::cimgui::ImGui_TreeNodeExStr(id, flags, "%s", message.c_str()));
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
NAN_METHOD(TreeNodeExPtr) {
|
|
327
|
+
void* id = nullptr;
|
|
328
|
+
if (!ReadPointer(info, 0, &id)) return;
|
|
329
|
+
int flags = 0;
|
|
330
|
+
if (!ReadScalar(info, 1, &flags)) return;
|
|
331
|
+
std::string message;
|
|
332
|
+
if (!Format(info, 2, 3, &message)) return;
|
|
333
|
+
info.GetReturnValue().Set(
|
|
334
|
+
::cimgui::ImGui_TreeNodeExPtr(id, flags, "%s", message.c_str()));
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
NAN_METHOD(SetTooltip) {
|
|
338
|
+
std::string message;
|
|
339
|
+
if (!Format(info, 0, 1, &message)) return;
|
|
340
|
+
::cimgui::ImGui_SetTooltip("%s", message.c_str());
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
NAN_METHOD(SetItemTooltip) {
|
|
344
|
+
std::string message;
|
|
345
|
+
if (!Format(info, 0, 1, &message)) return;
|
|
346
|
+
::cimgui::ImGui_SetItemTooltip("%s", message.c_str());
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
NAN_METHOD(LogText) {
|
|
350
|
+
std::string message;
|
|
351
|
+
if (!Format(info, 0, 1, &message)) return;
|
|
352
|
+
::cimgui::ImGui_LogText("%s", message.c_str());
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
NAN_METHOD(DebugLog) {
|
|
356
|
+
std::string message;
|
|
357
|
+
if (!Format(info, 0, 1, &message)) return;
|
|
358
|
+
::cimgui::ImGui_DebugLog("%s", message.c_str());
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
NAN_METHOD(TextBufferAppendf) {
|
|
362
|
+
auto* buffer = ReadStruct<cimgui::ImGuiTextBuffer>(info, 0);
|
|
363
|
+
if (!buffer) return;
|
|
364
|
+
std::string message;
|
|
365
|
+
if (!Format(info, 1, 2, &message)) return;
|
|
366
|
+
::cimgui::ImGuiTextBuffer_appendf(buffer, "%s", message.c_str());
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
} // namespace
|
|
370
|
+
|
|
371
|
+
NAN_MODULE_INIT(InitializeImGuiFormatted) {
|
|
372
|
+
sfmljs::SetMethod<Text>(target, "Text");
|
|
373
|
+
sfmljs::SetMethod<TextColored>(target, "TextColored");
|
|
374
|
+
sfmljs::SetMethod<TextDisabled>(target, "TextDisabled");
|
|
375
|
+
sfmljs::SetMethod<TextWrapped>(target, "TextWrapped");
|
|
376
|
+
sfmljs::SetMethod<LabelText>(target, "LabelText");
|
|
377
|
+
sfmljs::SetMethod<BulletText>(target, "BulletText");
|
|
378
|
+
sfmljs::SetMethod<TreeNodeStr>(target, "TreeNodeStr");
|
|
379
|
+
sfmljs::SetMethod<TreeNodePtr>(target, "TreeNodePtr");
|
|
380
|
+
sfmljs::SetMethod<TreeNodeExStr>(target, "TreeNodeExStr");
|
|
381
|
+
sfmljs::SetMethod<TreeNodeExPtr>(target, "TreeNodeExPtr");
|
|
382
|
+
sfmljs::SetMethod<SetTooltip>(target, "SetTooltip");
|
|
383
|
+
sfmljs::SetMethod<SetItemTooltip>(target, "SetItemTooltip");
|
|
384
|
+
sfmljs::SetMethod<LogText>(target, "LogText");
|
|
385
|
+
sfmljs::SetMethod<DebugLog>(target, "DebugLog");
|
|
386
|
+
sfmljs::SetMethod<TextBufferAppendf>(target, "TextBuffer_appendf");
|
|
387
|
+
}
|
|
388
|
+
} // namespace sfmlimgui
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Copyright (c) 2026 XadillaX
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
#include "native/imgui-args.h"
|
|
5
|
+
#include "native/imgui-bindings.h"
|
|
6
|
+
#include "native/imgui-draw-callbacks.h"
|
|
7
|
+
|
|
8
|
+
namespace sfmlimgui {
|
|
9
|
+
namespace {
|
|
10
|
+
|
|
11
|
+
NAN_METHOD(NewFrame) {
|
|
12
|
+
::cimgui::ImGui_NewFrame();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
NAN_METHOD(EndFrame) {
|
|
16
|
+
::cimgui::ImGui_EndFrame();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
NAN_METHOD(Render) {
|
|
20
|
+
::cimgui::ImGui_Render();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
NAN_METHOD(GetDrawData) {
|
|
24
|
+
auto result = ::cimgui::ImGui_GetDrawData();
|
|
25
|
+
TrackImGuiDrawData(result);
|
|
26
|
+
ReturnStruct<cimgui::ImDrawData>(info, result);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
NAN_METHOD(GetVersion) {
|
|
30
|
+
auto result = ::cimgui::ImGui_GetVersion();
|
|
31
|
+
ReturnString(info, result);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
NAN_METHOD(GetTime) {
|
|
35
|
+
auto result = ::cimgui::ImGui_GetTime();
|
|
36
|
+
info.GetReturnValue().Set(Nan::New(static_cast<double>(result)));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
NAN_METHOD(GetFrameCount) {
|
|
40
|
+
auto result = ::cimgui::ImGui_GetFrameCount();
|
|
41
|
+
info.GetReturnValue().Set(Nan::New(static_cast<double>(result)));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
} // namespace
|
|
45
|
+
|
|
46
|
+
NAN_MODULE_INIT(InitializeImGuiFrame) {
|
|
47
|
+
sfmljs::SetMethod<NewFrame>(target, "NewFrame");
|
|
48
|
+
sfmljs::SetMethod<EndFrame>(target, "EndFrame");
|
|
49
|
+
sfmljs::SetMethod<Render>(target, "Render");
|
|
50
|
+
sfmljs::SetMethod<GetDrawData>(target, "GetDrawData");
|
|
51
|
+
sfmljs::SetMethod<GetVersion>(target, "GetVersion");
|
|
52
|
+
sfmljs::SetMethod<GetTime>(target, "GetTime");
|
|
53
|
+
sfmljs::SetMethod<GetFrameCount>(target, "GetFrameCount");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
} // namespace sfmlimgui
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Copyright (c) 2026 XadillaX
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
#include "native/imgui-glyph-fields.h"
|
|
5
|
+
|
|
6
|
+
#include <nan.h>
|
|
7
|
+
#include <sfml-js-interop.h>
|
|
8
|
+
|
|
9
|
+
#include <cmath>
|
|
10
|
+
|
|
11
|
+
#include "native/cimgui.h"
|
|
12
|
+
|
|
13
|
+
namespace sfmlimgui {
|
|
14
|
+
namespace {
|
|
15
|
+
|
|
16
|
+
enum class GlyphBitfield { Colored, Visible, Codepoint };
|
|
17
|
+
|
|
18
|
+
template <GlyphBitfield field>
|
|
19
|
+
NAN_METHOD(ReadGlyphBitfield) {
|
|
20
|
+
auto* handle = sfmljs::SharedHandle<cimgui::ImFontGlyph>::From(info.Data());
|
|
21
|
+
if (!handle) return;
|
|
22
|
+
const auto& glyph = *handle->owner();
|
|
23
|
+
if constexpr (field == GlyphBitfield::Colored) {
|
|
24
|
+
info.GetReturnValue().Set(Nan::New(glyph.Colored));
|
|
25
|
+
} else if constexpr (field == GlyphBitfield::Visible) {
|
|
26
|
+
info.GetReturnValue().Set(Nan::New(glyph.Visible));
|
|
27
|
+
} else {
|
|
28
|
+
info.GetReturnValue().Set(Nan::New(glyph.Codepoint));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
template <GlyphBitfield field>
|
|
33
|
+
NAN_METHOD(WriteGlyphBitfield) {
|
|
34
|
+
auto* handle = sfmljs::SharedHandle<cimgui::ImFontGlyph>::From(info.Data());
|
|
35
|
+
if (!handle) return;
|
|
36
|
+
if (!info[0]->IsNumber()) {
|
|
37
|
+
Nan::ThrowTypeError("Glyph bitfield value must be a number");
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const double number = info[0].As<v8::Number>()->Value();
|
|
41
|
+
constexpr unsigned int maximum =
|
|
42
|
+
field == GlyphBitfield::Codepoint ? 0x3fffffffU : 1U;
|
|
43
|
+
if (!std::isfinite(number) || std::trunc(number) != number || number < 0 ||
|
|
44
|
+
number > maximum) {
|
|
45
|
+
Nan::ThrowRangeError(
|
|
46
|
+
field == GlyphBitfield::Codepoint
|
|
47
|
+
? "Codepoint must be an integer between 0 and 0x3fffffff"
|
|
48
|
+
: "Colored and Visible must be 0 or 1");
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
auto& glyph = *handle->owner();
|
|
52
|
+
const auto value = static_cast<unsigned int>(number);
|
|
53
|
+
if constexpr (field == GlyphBitfield::Colored) {
|
|
54
|
+
glyph.Colored = value;
|
|
55
|
+
} else if constexpr (field == GlyphBitfield::Visible) {
|
|
56
|
+
glyph.Visible = value;
|
|
57
|
+
} else {
|
|
58
|
+
glyph.Codepoint = value;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
template <GlyphBitfield field>
|
|
63
|
+
void AddGlyphBitfield(v8::Local<v8::Object> result,
|
|
64
|
+
const char* name,
|
|
65
|
+
v8::Local<v8::Value> handle) {
|
|
66
|
+
// Callback data retains the SharedHandle even when JS copies the descriptor.
|
|
67
|
+
auto getter = Nan::GetFunction(Nan::New<v8::FunctionTemplate>(
|
|
68
|
+
ReadGlyphBitfield<field>, handle))
|
|
69
|
+
.ToLocalChecked();
|
|
70
|
+
auto setter = Nan::GetFunction(Nan::New<v8::FunctionTemplate>(
|
|
71
|
+
WriteGlyphBitfield<field>, handle))
|
|
72
|
+
.ToLocalChecked();
|
|
73
|
+
result->SetAccessorProperty(
|
|
74
|
+
Nan::New(name).ToLocalChecked(), getter, setter, v8::DontDelete);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
} // namespace
|
|
78
|
+
|
|
79
|
+
v8::Local<v8::Object> FontGlyphBitfields(v8::Local<v8::Value> handle) {
|
|
80
|
+
auto result = Nan::New<v8::Object>();
|
|
81
|
+
AddGlyphBitfield<GlyphBitfield::Colored>(result, "Colored", handle);
|
|
82
|
+
AddGlyphBitfield<GlyphBitfield::Visible>(result, "Visible", handle);
|
|
83
|
+
AddGlyphBitfield<GlyphBitfield::Codepoint>(result, "Codepoint", handle);
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
} // namespace sfmlimgui
|