imxc 0.3.2 → 0.4.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/dist/init.js CHANGED
@@ -1,397 +1,416 @@
1
1
  import * as fs from 'node:fs';
2
2
  import * as path from 'node:path';
3
- const MAIN_CPP = `#include <imx/runtime.h>
4
- #include <imx/renderer.h>
5
-
6
- #include <imgui.h>
7
- #include <imgui_impl_glfw.h>
8
- #include <imgui_impl_opengl3.h>
9
- #include <GLFW/glfw3.h>
10
-
11
- struct App {
12
- GLFWwindow* window = nullptr;
13
- ImGuiIO* io = nullptr;
14
- imx::Runtime runtime;
15
- };
16
-
17
- static void render_frame(App& app) {
18
- glfwMakeContextCurrent(app.window);
19
- if (glfwGetWindowAttrib(app.window, GLFW_ICONIFIED) != 0) return;
20
-
21
- int fb_w = 0, fb_h = 0;
22
- glfwGetFramebufferSize(app.window, &fb_w, &fb_h);
23
- if (fb_w <= 0 || fb_h <= 0) return;
24
-
25
- ImGui_ImplOpenGL3_NewFrame();
26
- ImGui_ImplGlfw_NewFrame();
27
- ImGui::NewFrame();
28
-
29
- imx::render_root(app.runtime);
30
-
31
- ImGui::Render();
32
- glViewport(0, 0, fb_w, fb_h);
33
- glClearColor(0.12F, 0.12F, 0.15F, 1.0F);
34
- glClear(GL_COLOR_BUFFER_BIT);
35
- ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
36
-
37
- if ((app.io->ConfigFlags & ImGuiConfigFlags_ViewportsEnable) != 0) {
38
- ImGui::UpdatePlatformWindows();
39
- ImGui::RenderPlatformWindowsDefault();
40
- }
41
-
42
- glfwMakeContextCurrent(app.window);
43
- glfwSwapBuffers(app.window);
44
- }
45
-
46
- static void window_size_callback(GLFWwindow* window, int, int) {
47
- auto* app = static_cast<App*>(glfwGetWindowUserPointer(window));
48
- if (app) render_frame(*app);
49
- }
50
-
51
- int main() {
52
- if (glfwInit() == 0) return 1;
53
-
54
- const char* glsl_version = "#version 150";
55
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
56
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
57
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
58
- #ifdef __APPLE__
59
- glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
60
- #endif
61
-
62
- GLFWwindow* window = glfwCreateWindow(800, 600, "APP_NAME", nullptr, nullptr);
63
- if (!window) { glfwTerminate(); return 1; }
64
- glfwMakeContextCurrent(window);
65
- glfwSwapInterval(1);
66
-
67
- IMGUI_CHECKVERSION();
68
- ImGui::CreateContext();
69
- ImGuiIO& io = ImGui::GetIO();
70
- io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
71
- io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
72
-
73
- ImGui::StyleColorsDark();
74
- ImGuiStyle& style = ImGui::GetStyle();
75
- if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
76
- style.WindowRounding = 0.0F;
77
- style.Colors[ImGuiCol_WindowBg].w = 1.0F;
78
- }
79
-
80
- ImGui_ImplGlfw_InitForOpenGL(window, true);
81
- ImGui_ImplOpenGL3_Init(glsl_version);
82
-
83
- App app;
84
- app.window = window;
85
- app.io = &io;
86
- glfwSetWindowUserPointer(window, &app);
87
- glfwSetWindowSizeCallback(window, window_size_callback);
88
-
89
- while (glfwWindowShouldClose(window) == 0) {
90
- glfwPollEvents();
91
- render_frame(app);
92
- }
93
-
94
- ImGui_ImplOpenGL3_Shutdown();
95
- ImGui_ImplGlfw_Shutdown();
96
- ImGui::DestroyContext();
97
- glfwDestroyWindow(window);
98
- glfwTerminate();
99
- return 0;
100
- }
101
-
102
- #ifdef _WIN32
103
- #include <windows.h>
104
- int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { return main(); }
105
- #endif
3
+ const APPSTATE_H = `#pragma once
4
+ #include <functional>
5
+
6
+ struct AppState {
7
+ int count = 0;
8
+ float speed = 5.0f;
9
+ std::function<void()> onIncrement;
10
+ };
106
11
  `;
107
- const APP_TSX = `export default function App() {
108
- const [count, setCount] = useState(0);
109
-
110
- return (
111
- <DockSpace>
112
- <MenuBar>
113
- <Menu label="File">
114
- <MenuItem label="Exit" />
115
- </Menu>
116
- </MenuBar>
117
- <Window title="Hello">
118
- <Column gap={8}>
119
- <Text>Hello, World!</Text>
120
- <Row gap={8}>
121
- <Button title="Increment" onPress={() => setCount(count + 1)} />
122
- <Text>Count: {count}</Text>
123
- </Row>
124
- </Column>
125
- </Window>
126
- </DockSpace>
127
- );
128
- }
12
+ const MAIN_CPP = `#include <imx/runtime.h>
13
+ #include <imx/renderer.h>
14
+
15
+ #include <imgui.h>
16
+ #include <imgui_impl_glfw.h>
17
+ #include <imgui_impl_opengl3.h>
18
+ #include <GLFW/glfw3.h>
19
+
20
+ #include "AppState.h"
21
+
22
+ struct App {
23
+ GLFWwindow* window = nullptr;
24
+ ImGuiIO* io = nullptr;
25
+ imx::Runtime runtime;
26
+ AppState state;
27
+ };
28
+
29
+ static void render_frame(App& app) {
30
+ glfwMakeContextCurrent(app.window);
31
+ if (glfwGetWindowAttrib(app.window, GLFW_ICONIFIED) != 0) return;
32
+
33
+ int fb_w = 0, fb_h = 0;
34
+ glfwGetFramebufferSize(app.window, &fb_w, &fb_h);
35
+ if (fb_w <= 0 || fb_h <= 0) return;
36
+
37
+ ImGui_ImplOpenGL3_NewFrame();
38
+ ImGui_ImplGlfw_NewFrame();
39
+ ImGui::NewFrame();
40
+
41
+ imx::render_root(app.runtime, app.state);
42
+
43
+ ImGui::Render();
44
+ glViewport(0, 0, fb_w, fb_h);
45
+ glClearColor(0.12F, 0.12F, 0.15F, 1.0F);
46
+ glClear(GL_COLOR_BUFFER_BIT);
47
+ ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
48
+
49
+ if ((app.io->ConfigFlags & ImGuiConfigFlags_ViewportsEnable) != 0) {
50
+ ImGui::UpdatePlatformWindows();
51
+ ImGui::RenderPlatformWindowsDefault();
52
+ }
53
+
54
+ glfwMakeContextCurrent(app.window);
55
+ glfwSwapBuffers(app.window);
56
+ }
57
+
58
+ static void window_size_callback(GLFWwindow* window, int, int) {
59
+ auto* app = static_cast<App*>(glfwGetWindowUserPointer(window));
60
+ if (app) render_frame(*app);
61
+ }
62
+
63
+ int main() {
64
+ if (glfwInit() == 0) return 1;
65
+
66
+ const char* glsl_version = "#version 150";
67
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
68
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
69
+ glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
70
+ #ifdef __APPLE__
71
+ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
72
+ #endif
73
+
74
+ GLFWwindow* window = glfwCreateWindow(800, 600, "APP_NAME", nullptr, nullptr);
75
+ if (!window) { glfwTerminate(); return 1; }
76
+ glfwMakeContextCurrent(window);
77
+ glfwSwapInterval(1);
78
+
79
+ IMGUI_CHECKVERSION();
80
+ ImGui::CreateContext();
81
+ ImGuiIO& io = ImGui::GetIO();
82
+ io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
83
+ io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
84
+
85
+ ImGui::StyleColorsDark();
86
+ ImGuiStyle& style = ImGui::GetStyle();
87
+ if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
88
+ style.WindowRounding = 0.0F;
89
+ style.Colors[ImGuiCol_WindowBg].w = 1.0F;
90
+ }
91
+
92
+ ImGui_ImplGlfw_InitForOpenGL(window, true);
93
+ ImGui_ImplOpenGL3_Init(glsl_version);
94
+
95
+ App app;
96
+ app.window = window;
97
+ app.io = &io;
98
+ glfwSetWindowUserPointer(window, &app);
99
+ glfwSetWindowSizeCallback(window, window_size_callback);
100
+ app.state.onIncrement = [&]() { app.state.count++; };
101
+
102
+ while (glfwWindowShouldClose(window) == 0) {
103
+ glfwPollEvents();
104
+ render_frame(app);
105
+ }
106
+
107
+ ImGui_ImplOpenGL3_Shutdown();
108
+ ImGui_ImplGlfw_Shutdown();
109
+ ImGui::DestroyContext();
110
+ glfwDestroyWindow(window);
111
+ glfwTerminate();
112
+ return 0;
113
+ }
114
+
115
+ #ifdef _WIN32
116
+ #include <windows.h>
117
+ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { return main(); }
118
+ #endif
129
119
  `;
130
- const IMX_DTS = `// imx.d.ts Type definitions for IMX components
131
-
132
- interface Style {
133
- padding?: number;
134
- paddingHorizontal?: number;
135
- paddingVertical?: number;
136
- gap?: number;
137
- width?: number;
138
- height?: number;
139
- minWidth?: number;
140
- minHeight?: number;
141
- backgroundColor?: [number, number, number, number];
142
- textColor?: [number, number, number, number];
143
- fontSize?: number;
144
- }
145
-
146
- declare function useState<T>(initial: T): [T, (value: T) => void];
147
-
148
- interface WindowProps { title: string; open?: boolean; onClose?: () => void; noTitleBar?: boolean; noResize?: boolean; noMove?: boolean; noCollapse?: boolean; noDocking?: boolean; noScrollbar?: boolean; style?: Style; children?: any; }
149
- interface ViewProps { style?: Style; children?: any; }
150
- interface RowProps { gap?: number; style?: Style; children?: any; }
151
- interface ColumnProps { gap?: number; style?: Style; children?: any; }
152
- interface TextProps { style?: Style; children?: any; }
153
- interface ButtonProps { title: string; onPress: () => void; disabled?: boolean; style?: Style; }
154
- interface TextInputProps { value: string; onChange: (v: string) => void; label?: string; placeholder?: string; style?: Style; }
155
- interface CheckboxProps { value: boolean; onChange: (v: boolean) => void; label?: string; style?: Style; }
156
- interface SeparatorProps {}
157
- interface PopupProps { id: string; style?: Style; children?: any; }
158
- interface DockSpaceProps { style?: Style; children?: any; }
159
- interface DockLayoutProps { children?: any; }
160
- interface DockSplitProps { direction: "horizontal" | "vertical"; size: number; children?: any; }
161
- interface DockPanelProps { children?: any; }
162
- interface ThemeProps {
163
- preset: string;
164
- accentColor?: [number, number, number, number];
165
- backgroundColor?: [number, number, number, number];
166
- textColor?: [number, number, number, number];
167
- borderColor?: [number, number, number, number];
168
- surfaceColor?: [number, number, number, number];
169
- rounding?: number;
170
- borderSize?: number;
171
- spacing?: number;
172
- children?: any;
173
- }
174
- interface MenuBarProps { children?: any; }
175
- interface MenuProps { label: string; children?: any; }
176
- interface MenuItemProps { label: string; onPress?: () => void; shortcut?: string; }
177
- interface TableProps { columns: string[]; style?: Style; children?: any; }
178
- interface TableRowProps { children?: any; }
179
- interface TabBarProps { style?: Style; children?: any; }
180
- interface TabItemProps { label: string; children?: any; }
181
- interface TreeNodeProps { label: string; children?: any; }
182
- interface CollapsingHeaderProps { label: string; children?: any; }
183
- interface SliderFloatProps { label: string; value: number; onChange: (v: number) => void; min: number; max: number; style?: Style; }
184
- interface SliderIntProps { label: string; value: number; onChange: (v: number) => void; min: number; max: number; style?: Style; }
185
- interface DragFloatProps { label: string; value: number; onChange: (v: number) => void; speed?: number; style?: Style; }
186
- interface DragIntProps { label: string; value: number; onChange: (v: number) => void; speed?: number; style?: Style; }
187
- interface ComboProps { label: string; value: number; onChange: (v: number) => void; items: string[]; style?: Style; }
188
- interface InputIntProps { label: string; value: number; onChange: (v: number) => void; style?: Style; }
189
- interface InputFloatProps { label: string; value: number; onChange: (v: number) => void; style?: Style; }
190
- interface ColorEditProps { label: string; value: number[]; onChange: (v: number[]) => void; style?: Style; }
191
- interface ListBoxProps { label: string; value: number; onChange: (v: number) => void; items: string[]; style?: Style; }
192
- interface ProgressBarProps { value: number; overlay?: string; style?: Style; }
193
- interface TooltipProps { text: string; }
194
- interface BulletTextProps { style?: Style; children?: any; }
195
- interface LabelTextProps { label: string; value: string; }
196
- interface SelectableProps { label: string; selected?: boolean; onSelect?: () => void; style?: Style; }
197
- interface RadioProps { label: string; value: number; index: number; onChange?: (v: number) => void; style?: Style; }
198
- interface InputTextMultilineProps { label: string; value: string; style?: Style; }
199
- interface ColorPickerProps { label: string; value: number[]; style?: Style; }
200
- interface PlotLinesProps { label: string; values: number[]; overlay?: string; style?: Style; }
201
- interface PlotHistogramProps { label: string; values: number[]; overlay?: string; style?: Style; }
202
- interface ModalProps { title: string; open?: boolean; onClose?: () => void; style?: Style; children?: any; }
203
- interface ImageProps { src: string; embed?: boolean; width?: number; height?: number; }
204
- interface GroupProps { style?: Style; children?: any; }
205
- interface IDProps { scope: string | number; children?: any; }
206
- interface DragDropSourceProps { type: string; payload: number | string; children?: any; }
207
- interface DragDropTargetProps { type: string; onDrop: (payload: any) => void; children?: any; }
208
- interface CanvasProps { width: number; height: number; style?: Style; children?: any; }
209
- interface DrawLineProps { p1: [number, number]; p2: [number, number]; color: [number, number, number, number]; thickness?: number; }
210
- interface DrawRectProps { min: [number, number]; max: [number, number]; color: [number, number, number, number]; filled?: boolean; thickness?: number; rounding?: number; }
211
- interface DrawCircleProps { center: [number, number]; radius: number; color: [number, number, number, number]; filled?: boolean; thickness?: number; }
212
- interface DrawTextProps { pos: [number, number]; text: string; color: [number, number, number, number]; }
213
- interface StyleColorProps {
214
- text?: [number, number, number, number];
215
- textDisabled?: [number, number, number, number];
216
- windowBg?: [number, number, number, number];
217
- frameBg?: [number, number, number, number];
218
- frameBgHovered?: [number, number, number, number];
219
- frameBgActive?: [number, number, number, number];
220
- titleBg?: [number, number, number, number];
221
- titleBgActive?: [number, number, number, number];
222
- button?: [number, number, number, number];
223
- buttonHovered?: [number, number, number, number];
224
- buttonActive?: [number, number, number, number];
225
- header?: [number, number, number, number];
226
- headerHovered?: [number, number, number, number];
227
- headerActive?: [number, number, number, number];
228
- separator?: [number, number, number, number];
229
- checkMark?: [number, number, number, number];
230
- sliderGrab?: [number, number, number, number];
231
- border?: [number, number, number, number];
232
- popupBg?: [number, number, number, number];
233
- tab?: [number, number, number, number];
234
- children?: any;
235
- }
236
-
237
- declare function Window(props: WindowProps): any;
238
- declare function View(props: ViewProps): any;
239
- declare function Row(props: RowProps): any;
240
- declare function Column(props: ColumnProps): any;
241
- declare function Text(props: TextProps): any;
242
- declare function Button(props: ButtonProps): any;
243
- declare function TextInput(props: TextInputProps): any;
244
- declare function Checkbox(props: CheckboxProps): any;
245
- declare function Separator(props: SeparatorProps): any;
246
- declare function Popup(props: PopupProps): any;
247
- declare function DockSpace(props: DockSpaceProps): any;
248
- declare function DockLayout(props: DockLayoutProps): any;
249
- declare function DockSplit(props: DockSplitProps): any;
250
- declare function DockPanel(props: DockPanelProps): any;
251
- declare function Theme(props: ThemeProps): any;
252
- declare function MenuBar(props: MenuBarProps): any;
253
- declare function Menu(props: MenuProps): any;
254
- declare function MenuItem(props: MenuItemProps): any;
255
- declare function Table(props: TableProps): any;
256
- declare function TableRow(props: TableRowProps): any;
257
- declare function TabBar(props: TabBarProps): any;
258
- declare function TabItem(props: TabItemProps): any;
259
- declare function TreeNode(props: TreeNodeProps): any;
260
- declare function CollapsingHeader(props: CollapsingHeaderProps): any;
261
- declare function SliderFloat(props: SliderFloatProps): any;
262
- declare function SliderInt(props: SliderIntProps): any;
263
- declare function DragFloat(props: DragFloatProps): any;
264
- declare function DragInt(props: DragIntProps): any;
265
- declare function Combo(props: ComboProps): any;
266
- declare function InputInt(props: InputIntProps): any;
267
- declare function InputFloat(props: InputFloatProps): any;
268
- declare function ColorEdit(props: ColorEditProps): any;
269
- declare function ListBox(props: ListBoxProps): any;
270
- declare function ProgressBar(props: ProgressBarProps): any;
271
- declare function Tooltip(props: TooltipProps): any;
272
- declare function BulletText(props: BulletTextProps): any;
273
- declare function LabelText(props: LabelTextProps): any;
274
- declare function Selectable(props: SelectableProps): any;
275
- declare function Radio(props: RadioProps): any;
276
- declare function InputTextMultiline(props: InputTextMultilineProps): any;
277
- declare function ColorPicker(props: ColorPickerProps): any;
278
- declare function PlotLines(props: PlotLinesProps): any;
279
- declare function PlotHistogram(props: PlotHistogramProps): any;
280
- declare function Modal(props: ModalProps): any;
281
- declare function Image(props: ImageProps): any;
282
- declare function Group(props: GroupProps): any;
283
- declare function ID(props: IDProps): any;
284
- declare function StyleColor(props: StyleColorProps): any;
285
- declare function Canvas(props: CanvasProps): any;
286
- declare function DrawLine(props: DrawLineProps): any;
287
- declare function DrawRect(props: DrawRectProps): any;
288
- declare function DrawCircle(props: DrawCircleProps): any;
289
- declare function DrawText(props: DrawTextProps): any;
290
-
291
- interface StyleVarProps {
292
- alpha?: number;
293
- windowPadding?: [number, number];
294
- windowRounding?: number;
295
- framePadding?: [number, number];
296
- frameRounding?: number;
297
- frameBorderSize?: number;
298
- itemSpacing?: [number, number];
299
- itemInnerSpacing?: [number, number];
300
- indentSpacing?: number;
301
- cellPadding?: [number, number];
302
- tabRounding?: number;
303
- children?: any;
304
- }
305
- declare function StyleVar(props: StyleVarProps): any;
306
- declare function DragDropSource(props: DragDropSourceProps): any;
307
- declare function DragDropTarget(props: DragDropTargetProps): any;
308
- interface DisabledProps { disabled?: boolean; children?: any; }
309
- interface ChildProps { id: string; width?: number; height?: number; border?: boolean; style?: Style; children?: any; }
310
- declare function Disabled(props: DisabledProps): any;
311
- declare function Child(props: ChildProps): any;
312
-
313
- declare function resetLayout(): void;
314
-
315
- // --- Custom native widgets ---
316
- // Declare your C++ registered widgets here for type checking:
317
- //
318
- // interface KnobProps {
319
- // value: number;
320
- // onChange: (value: number) => void;
321
- // min: number;
322
- // max: number;
323
- // width?: number;
324
- // height?: number;
325
- // }
326
- // declare function Knob(props: KnobProps): any;
327
-
328
- declare module "imx/jsx-runtime" {
329
- export namespace JSX {
330
- type Element = any;
331
- interface IntrinsicElements { [tag: string]: any; }
332
- interface ElementChildrenAttribute { children: {}; }
333
- }
334
- export function jsx(type: any, props: any, key?: any): any;
335
- export function jsxs(type: any, props: any, key?: any): any;
336
- export function Fragment(props: any): any;
337
- }
120
+ const APP_TSX = `export default function App(props: AppState) {
121
+ const [showAbout, setShowAbout] = useState(false);
122
+
123
+ return (
124
+ <DockSpace>
125
+ <Window title="Controls">
126
+ <Column gap={8}>
127
+ <Text>Count: {props.count}</Text>
128
+ <Button title="Increment" onPress={props.onIncrement} />
129
+ <SliderFloat label="Speed" value={props.speed} min={0} max={100} />
130
+ <Separator />
131
+ <Button title="About" onPress={() => setShowAbout(!showAbout)} />
132
+ </Column>
133
+ </Window>
134
+ {showAbout && <Window title="About">
135
+ <Text>Built with IMX</Text>
136
+ <Button title="Close" onPress={() => setShowAbout(false)} />
137
+ </Window>}
138
+ </DockSpace>
139
+ );
140
+ }
338
141
  `;
339
- const TSCONFIG = `{
340
- "compilerOptions": {
341
- "target": "ES2022",
342
- "lib": ["ES2022"],
343
- "module": "ES2022",
344
- "moduleResolution": "bundler",
345
- "jsx": "react-jsx",
346
- "jsxImportSource": "imx",
347
- "strict": false,
348
- "noEmit": true,
349
- "skipLibCheck": true
350
- },
351
- "include": ["src/**/*.tsx", "src/imx.d.ts"]
352
- }
142
+ const IMX_DTS = `// imx.d.ts — Type definitions for IMX components
143
+
144
+ interface Style {
145
+ padding?: number;
146
+ paddingHorizontal?: number;
147
+ paddingVertical?: number;
148
+ gap?: number;
149
+ width?: number;
150
+ height?: number;
151
+ minWidth?: number;
152
+ minHeight?: number;
153
+ backgroundColor?: [number, number, number, number];
154
+ textColor?: [number, number, number, number];
155
+ fontSize?: number;
156
+ }
157
+
158
+ declare function useState<T>(initial: T): [T, (value: T) => void];
159
+
160
+ interface AppState {
161
+ count: number;
162
+ speed: number;
163
+ onIncrement: () => void;
164
+ }
165
+
166
+ interface WindowProps { title: string; open?: boolean; onClose?: () => void; noTitleBar?: boolean; noResize?: boolean; noMove?: boolean; noCollapse?: boolean; noDocking?: boolean; noScrollbar?: boolean; style?: Style; children?: any; }
167
+ interface ViewProps { style?: Style; children?: any; }
168
+ interface RowProps { gap?: number; style?: Style; children?: any; }
169
+ interface ColumnProps { gap?: number; style?: Style; children?: any; }
170
+ interface TextProps { style?: Style; children?: any; }
171
+ interface ButtonProps { title: string; onPress: () => void; disabled?: boolean; style?: Style; }
172
+ interface TextInputProps { value: string; onChange: (v: string) => void; label?: string; placeholder?: string; style?: Style; }
173
+ interface CheckboxProps { value: boolean; onChange?: (v: boolean) => void; label?: string; style?: Style; }
174
+ interface SeparatorProps {}
175
+ interface PopupProps { id: string; style?: Style; children?: any; }
176
+ interface DockSpaceProps { style?: Style; children?: any; }
177
+ interface DockLayoutProps { children?: any; }
178
+ interface DockSplitProps { direction: "horizontal" | "vertical"; size: number; children?: any; }
179
+ interface DockPanelProps { children?: any; }
180
+ interface ThemeProps {
181
+ preset: string;
182
+ accentColor?: [number, number, number, number];
183
+ backgroundColor?: [number, number, number, number];
184
+ textColor?: [number, number, number, number];
185
+ borderColor?: [number, number, number, number];
186
+ surfaceColor?: [number, number, number, number];
187
+ rounding?: number;
188
+ borderSize?: number;
189
+ spacing?: number;
190
+ children?: any;
191
+ }
192
+ interface MenuBarProps { children?: any; }
193
+ interface MenuProps { label: string; children?: any; }
194
+ interface MenuItemProps { label: string; onPress?: () => void; shortcut?: string; }
195
+ interface TableProps { columns: string[]; scrollY?: boolean; noBorders?: boolean; noRowBg?: boolean; style?: Style; children?: any; }
196
+ interface TableRowProps { key?: number | string; children?: any; }
197
+ interface TabBarProps { style?: Style; children?: any; }
198
+ interface TabItemProps { label: string; children?: any; }
199
+ interface TreeNodeProps { label: string; children?: any; }
200
+ interface CollapsingHeaderProps { label: string; children?: any; }
201
+ interface SliderFloatProps { label: string; value: number; onChange?: (v: number) => void; min: number; max: number; style?: Style; }
202
+ interface SliderIntProps { label: string; value: number; onChange?: (v: number) => void; min: number; max: number; style?: Style; }
203
+ interface DragFloatProps { label: string; value: number; onChange?: (v: number) => void; speed?: number; style?: Style; }
204
+ interface DragIntProps { label: string; value: number; onChange?: (v: number) => void; speed?: number; style?: Style; }
205
+ interface ComboProps { label: string; value: number; onChange?: (v: number) => void; items: string[]; style?: Style; }
206
+ interface InputIntProps { label: string; value: number; onChange?: (v: number) => void; style?: Style; }
207
+ interface InputFloatProps { label: string; value: number; onChange?: (v: number) => void; style?: Style; }
208
+ interface ColorEditProps { label: string; value: number[]; onChange: (v: number[]) => void; style?: Style; }
209
+ interface ListBoxProps { label: string; value: number; onChange?: (v: number) => void; items: string[]; style?: Style; }
210
+ interface ProgressBarProps { value: number; overlay?: string; style?: Style; }
211
+ interface TooltipProps { text: string; }
212
+ interface BulletTextProps { style?: Style; children?: any; }
213
+ interface LabelTextProps { label: string; value: string; }
214
+ interface SelectableProps { label: string; selected?: boolean; onSelect?: () => void; style?: Style; }
215
+ interface RadioProps { label: string; value: number; index: number; onChange?: (v: number) => void; style?: Style; }
216
+ interface InputTextMultilineProps { label: string; value: string; style?: Style; }
217
+ interface ColorPickerProps { label: string; value: number[]; style?: Style; }
218
+ interface PlotLinesProps { label: string; values: number[]; overlay?: string; style?: Style; }
219
+ interface PlotHistogramProps { label: string; values: number[]; overlay?: string; style?: Style; }
220
+ interface ModalProps { title: string; open?: boolean; onClose?: () => void; style?: Style; children?: any; }
221
+ interface ImageProps { src: string; embed?: boolean; width?: number; height?: number; }
222
+ interface GroupProps { style?: Style; children?: any; }
223
+ interface IDProps { scope: string | number; children?: any; }
224
+ interface DragDropSourceProps { type: string; payload: number | string; children?: any; }
225
+ interface DragDropTargetProps { type: string; onDrop: (payload: any) => void; children?: any; }
226
+ interface CanvasProps { width: number; height: number; style?: Style; children?: any; }
227
+ interface DrawLineProps { p1: [number, number]; p2: [number, number]; color: [number, number, number, number]; thickness?: number; }
228
+ interface DrawRectProps { min: [number, number]; max: [number, number]; color: [number, number, number, number]; filled?: boolean; thickness?: number; rounding?: number; }
229
+ interface DrawCircleProps { center: [number, number]; radius: number; color: [number, number, number, number]; filled?: boolean; thickness?: number; }
230
+ interface DrawTextProps { pos: [number, number]; text: string; color: [number, number, number, number]; }
231
+ interface StyleColorProps {
232
+ text?: [number, number, number, number];
233
+ textDisabled?: [number, number, number, number];
234
+ windowBg?: [number, number, number, number];
235
+ frameBg?: [number, number, number, number];
236
+ frameBgHovered?: [number, number, number, number];
237
+ frameBgActive?: [number, number, number, number];
238
+ titleBg?: [number, number, number, number];
239
+ titleBgActive?: [number, number, number, number];
240
+ button?: [number, number, number, number];
241
+ buttonHovered?: [number, number, number, number];
242
+ buttonActive?: [number, number, number, number];
243
+ header?: [number, number, number, number];
244
+ headerHovered?: [number, number, number, number];
245
+ headerActive?: [number, number, number, number];
246
+ separator?: [number, number, number, number];
247
+ checkMark?: [number, number, number, number];
248
+ sliderGrab?: [number, number, number, number];
249
+ border?: [number, number, number, number];
250
+ popupBg?: [number, number, number, number];
251
+ tab?: [number, number, number, number];
252
+ children?: any;
253
+ }
254
+
255
+ declare function Window(props: WindowProps): any;
256
+ declare function View(props: ViewProps): any;
257
+ declare function Row(props: RowProps): any;
258
+ declare function Column(props: ColumnProps): any;
259
+ declare function Text(props: TextProps): any;
260
+ declare function Button(props: ButtonProps): any;
261
+ declare function TextInput(props: TextInputProps): any;
262
+ declare function Checkbox(props: CheckboxProps): any;
263
+ declare function Separator(props: SeparatorProps): any;
264
+ declare function Popup(props: PopupProps): any;
265
+ declare function DockSpace(props: DockSpaceProps): any;
266
+ declare function DockLayout(props: DockLayoutProps): any;
267
+ declare function DockSplit(props: DockSplitProps): any;
268
+ declare function DockPanel(props: DockPanelProps): any;
269
+ declare function Theme(props: ThemeProps): any;
270
+ declare function MenuBar(props: MenuBarProps): any;
271
+ declare function Menu(props: MenuProps): any;
272
+ declare function MenuItem(props: MenuItemProps): any;
273
+ declare function Table(props: TableProps): any;
274
+ declare function TableRow(props: TableRowProps): any;
275
+ declare function TabBar(props: TabBarProps): any;
276
+ declare function TabItem(props: TabItemProps): any;
277
+ declare function TreeNode(props: TreeNodeProps): any;
278
+ declare function CollapsingHeader(props: CollapsingHeaderProps): any;
279
+ declare function SliderFloat(props: SliderFloatProps): any;
280
+ declare function SliderInt(props: SliderIntProps): any;
281
+ declare function DragFloat(props: DragFloatProps): any;
282
+ declare function DragInt(props: DragIntProps): any;
283
+ declare function Combo(props: ComboProps): any;
284
+ declare function InputInt(props: InputIntProps): any;
285
+ declare function InputFloat(props: InputFloatProps): any;
286
+ declare function ColorEdit(props: ColorEditProps): any;
287
+ declare function ListBox(props: ListBoxProps): any;
288
+ declare function ProgressBar(props: ProgressBarProps): any;
289
+ declare function Tooltip(props: TooltipProps): any;
290
+ declare function BulletText(props: BulletTextProps): any;
291
+ declare function LabelText(props: LabelTextProps): any;
292
+ declare function Selectable(props: SelectableProps): any;
293
+ declare function Radio(props: RadioProps): any;
294
+ declare function InputTextMultiline(props: InputTextMultilineProps): any;
295
+ declare function ColorPicker(props: ColorPickerProps): any;
296
+ declare function PlotLines(props: PlotLinesProps): any;
297
+ declare function PlotHistogram(props: PlotHistogramProps): any;
298
+ declare function Modal(props: ModalProps): any;
299
+ declare function Image(props: ImageProps): any;
300
+ declare function Group(props: GroupProps): any;
301
+ declare function ID(props: IDProps): any;
302
+ declare function StyleColor(props: StyleColorProps): any;
303
+ declare function Canvas(props: CanvasProps): any;
304
+ declare function DrawLine(props: DrawLineProps): any;
305
+ declare function DrawRect(props: DrawRectProps): any;
306
+ declare function DrawCircle(props: DrawCircleProps): any;
307
+ declare function DrawText(props: DrawTextProps): any;
308
+
309
+ interface StyleVarProps {
310
+ alpha?: number;
311
+ windowPadding?: [number, number];
312
+ windowRounding?: number;
313
+ framePadding?: [number, number];
314
+ frameRounding?: number;
315
+ frameBorderSize?: number;
316
+ itemSpacing?: [number, number];
317
+ itemInnerSpacing?: [number, number];
318
+ indentSpacing?: number;
319
+ cellPadding?: [number, number];
320
+ tabRounding?: number;
321
+ children?: any;
322
+ }
323
+ declare function StyleVar(props: StyleVarProps): any;
324
+ declare function DragDropSource(props: DragDropSourceProps): any;
325
+ declare function DragDropTarget(props: DragDropTargetProps): any;
326
+ interface DisabledProps { disabled?: boolean; children?: any; }
327
+ interface ChildProps { id: string; width?: number; height?: number; border?: boolean; style?: Style; children?: any; }
328
+ declare function Disabled(props: DisabledProps): any;
329
+ declare function Child(props: ChildProps): any;
330
+
331
+ declare function resetLayout(): void;
332
+
333
+ // --- Custom native widgets ---
334
+ // Declare your C++ registered widgets here for type checking:
335
+ //
336
+ // interface KnobProps {
337
+ // value: number;
338
+ // onChange: (value: number) => void;
339
+ // min: number;
340
+ // max: number;
341
+ // width?: number;
342
+ // height?: number;
343
+ // }
344
+ // declare function Knob(props: KnobProps): any;
345
+
346
+ declare module "imx/jsx-runtime" {
347
+ export namespace JSX {
348
+ type Element = any;
349
+ interface IntrinsicElements { [tag: string]: any; }
350
+ interface ElementChildrenAttribute { children: {}; }
351
+ }
352
+ export function jsx(type: any, props: any, key?: any): any;
353
+ export function jsxs(type: any, props: any, key?: any): any;
354
+ export function Fragment(props: any): any;
355
+ }
356
+ `;
357
+ const TSCONFIG = `{
358
+ "compilerOptions": {
359
+ "target": "ES2022",
360
+ "lib": ["ES2022"],
361
+ "module": "ES2022",
362
+ "moduleResolution": "bundler",
363
+ "jsx": "react-jsx",
364
+ "jsxImportSource": "imx",
365
+ "strict": false,
366
+ "noEmit": true,
367
+ "skipLibCheck": true
368
+ },
369
+ "include": ["src/**/*.tsx", "src/imx.d.ts"]
370
+ }
353
371
  `;
354
372
  function cmakeTemplate(projectName, repoUrl) {
355
- return `cmake_minimum_required(VERSION 3.25)
356
- project(${projectName} LANGUAGES CXX)
357
-
358
- set(CMAKE_CXX_STANDARD 20)
359
- set(CMAKE_CXX_STANDARD_REQUIRED ON)
360
-
361
- include(FetchContent)
362
- set(FETCHCONTENT_QUIET OFF)
363
-
364
- FetchContent_Declare(
365
- imx
366
- GIT_REPOSITORY ${repoUrl}
367
- GIT_TAG main
368
- GIT_PROGRESS TRUE
369
- )
370
- message(STATUS "Fetching IMX (includes ImGui + GLFW)...")
371
- FetchContent_MakeAvailable(imx)
372
-
373
- include(ImxCompile)
374
-
375
- imx_compile_tsx(GENERATED
376
- SOURCES src/App.tsx
377
- OUTPUT_DIR \${CMAKE_BINARY_DIR}/generated
378
- )
379
-
380
- add_executable(${projectName}
381
- src/main.cpp
382
- \${GENERATED}
383
- )
384
- set_target_properties(${projectName} PROPERTIES WIN32_EXECUTABLE $<CONFIG:Release>)
385
- target_link_libraries(${projectName} PRIVATE imx::renderer)
386
- target_include_directories(${projectName} PRIVATE \${CMAKE_BINARY_DIR}/generated)
387
-
388
- # Copy public/ assets to output directory
389
- add_custom_command(TARGET ${projectName} POST_BUILD
390
- COMMAND \${CMAKE_COMMAND} -E copy_directory
391
- \${CMAKE_CURRENT_SOURCE_DIR}/public
392
- $<TARGET_FILE_DIR:${projectName}>
393
- COMMENT "Copying public/ assets"
394
- )
373
+ return `cmake_minimum_required(VERSION 3.25)
374
+ project(${projectName} LANGUAGES CXX)
375
+
376
+ set(CMAKE_CXX_STANDARD 20)
377
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
378
+
379
+ include(FetchContent)
380
+ set(FETCHCONTENT_QUIET OFF)
381
+
382
+ FetchContent_Declare(
383
+ imx
384
+ GIT_REPOSITORY ${repoUrl}
385
+ GIT_TAG main
386
+ GIT_SHALLOW TRUE
387
+ GIT_PROGRESS TRUE
388
+ )
389
+ message(STATUS "Fetching IMX (includes ImGui + GLFW)...")
390
+ FetchContent_MakeAvailable(imx)
391
+
392
+ include(ImxCompile)
393
+
394
+ imx_compile_tsx(GENERATED
395
+ SOURCES src/App.tsx
396
+ OUTPUT_DIR \${CMAKE_BINARY_DIR}/generated
397
+ )
398
+
399
+ add_executable(${projectName}
400
+ src/main.cpp
401
+ \${GENERATED}
402
+ )
403
+ set_target_properties(${projectName} PROPERTIES WIN32_EXECUTABLE $<CONFIG:Release>)
404
+ target_link_libraries(${projectName} PRIVATE imx::renderer)
405
+ target_include_directories(${projectName} PRIVATE \${CMAKE_BINARY_DIR}/generated \${CMAKE_CURRENT_SOURCE_DIR}/src)
406
+
407
+ # Copy public/ assets to output directory
408
+ add_custom_command(TARGET ${projectName} POST_BUILD
409
+ COMMAND \${CMAKE_COMMAND} -E copy_directory
410
+ \${CMAKE_CURRENT_SOURCE_DIR}/public
411
+ $<TARGET_FILE_DIR:${projectName}>
412
+ COMMENT "Copying public/ assets"
413
+ )
395
414
  `;
396
415
  }
397
416
  export function addToProject(projectDir) {
@@ -461,6 +480,7 @@ export function initProject(projectDir, projectName) {
461
480
  fs.mkdirSync(publicDir, { recursive: true });
462
481
  // Write files
463
482
  fs.writeFileSync(path.join(srcDir, 'main.cpp'), MAIN_CPP.replace('APP_NAME', name));
483
+ fs.writeFileSync(path.join(srcDir, 'AppState.h'), APPSTATE_H);
464
484
  fs.writeFileSync(path.join(srcDir, 'App.tsx'), APP_TSX);
465
485
  fs.writeFileSync(path.join(srcDir, 'imx.d.ts'), IMX_DTS);
466
486
  fs.writeFileSync(path.join(projectDir, 'tsconfig.json'), TSCONFIG);
@@ -469,8 +489,9 @@ export function initProject(projectDir, projectName) {
469
489
  console.log('');
470
490
  console.log(' Created:');
471
491
  console.log(` src/main.cpp — app shell (GLFW + OpenGL + ImGui)`);
492
+ console.log(` src/AppState.h — C++ state struct (bound to TSX props)`);
472
493
  console.log(` src/App.tsx — your root component`);
473
- console.log(` src/imx.d.ts — type definitions for IDE support`);
494
+ console.log(` src/imx.d.ts — type definitions for IDE support`);
474
495
  console.log(` tsconfig.json — TypeScript config`);
475
496
  console.log(` CMakeLists.txt — build config with FetchContent`);
476
497
  console.log(` public/ — static assets (copied to exe directory)`);