Skip to content

Commit 7eea4c5

Browse files
committed
reorganize exports & change README
1 parent 869cdc9 commit 7eea4c5

File tree

11 files changed

+65
-46
lines changed

11 files changed

+65
-46
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,23 @@
44
55
# Status
66

7-
> Not ready for use
7+
> For now, only build on windows with opengl backend.
88
99
# Usage
1010

11+
```typescript
12+
// TODO
13+
```
14+
15+
# Contribute
16+
1117
```bash
12-
# build
18+
# build the shared library
1319
deno task build
14-
15-
# generate cimgui ffi symbols
20+
# generate cimgui ffi symbols and many draft to copy
1621
deno task gen
17-
# test for window created by imgui.dll
18-
deno task test-self
1922
# test for window created by dwm
2023
deno task test-dwm
24+
# test for window created by embeded glfw
25+
deno task test-self
2126
```

deno.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
]
2323
}
2424
}
25-
}
25+
}

mod.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
export * from "./src/type.ts";
2-
export * from "./src/enum.ts";
3-
export * from "./src/call.ts";
1+
export * from "./src/mod.ts";
2+
export * from "./src/demo.ts";

script/build.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function embed(): void {
2222
const binFile = join(binPath, getBinFileName());
2323
const outFile = join(distPath, getOutFileName());
2424

25+
// deno-lint-ignore no-explicit-any
2526
const encode = (Deno as any)[(Deno as any).internal]
2627
.core
2728
.ops.op_base64_encode;

script/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const DIMGUI_VERSION = "0.1.1";
1+
export const DIMGUI_VERSION = "0.2.0";

src/call.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -814,13 +814,6 @@ export function getColorU32_U32(col: ImU32): ImU32 {
814814
return imgui.igGetColorU32_U32(col);
815815
}
816816

817-
// export function getStyleColorVec4(idx: ImGuiCol): ImVec4 {
818-
// TODO editable ImVec4
819-
// const vec4 = new ImVec4();
820-
// return imgui.igGetStyleColorVec4(idx);
821-
// return vec4;
822-
// }
823-
824817
// // Cursor / Layout
825818
// // - By "cursor" we mean the current output position.
826819
// // - The typical widget behavior is to output themselves at the current cursor position, then move the cursor one line down.

test/test_demo.ts renamed to src/demo.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
1-
import * as imgui from "../mod.ts";
1+
import * as imgui from "./mod.ts";
22
import {
33
Bool,
44
Double,
55
Float,
66
ImGuiCol,
7+
ImGuiColorEditFlagBits,
78
ImGuiComboFlagBits,
89
ImGuiCond,
910
ImGuiDir,
11+
ImGuiDragDropFlagBits,
12+
ImGuiFocusedFlagBits,
1013
ImGuiHoveredFlagBits,
14+
ImGuiInputTextCallbackData,
15+
ImGuiInputTextFlagBits,
1116
ImGuiKey,
17+
ImGuiPayloadType,
1218
ImGuiSelectableFlagBits,
1319
ImGuiSliderFlagBits,
20+
ImGuiStyleVar,
21+
ImGuiTabBarFlagBits,
22+
ImGuiTabItemFlagBits,
1423
ImGuiTableFlagBits,
1524
ImGuiTreeNodeFlagBits,
1625
ImVec2,
1726
ImVec4,
1827
Int32,
1928
Utf8Array,
20-
} from "../mod.ts";
21-
import {
22-
ImGuiColorEditFlagBits,
23-
ImGuiDragDropFlagBits,
24-
ImGuiFocusedFlagBits,
25-
ImGuiInputTextFlagBits,
26-
ImGuiPayloadType,
27-
ImGuiStyleVar,
28-
ImGuiTabBarFlagBits,
29-
ImGuiTabItemFlagBits,
30-
} from "../src/enum.ts";
31-
import { ImGuiInputTextCallbackData } from "../src/imgui_input_text_callback_data.ts";
29+
} from "./mod.ts";
3230

3331
/**
3432
* Helper to display a little (?) mark which shows a tooltip when hovered.
@@ -2307,7 +2305,7 @@ function demoQueryingWindow() {
23072305
* The Checkbox for that is inside the "Disabled" section at the bottom
23082306
*/
23092307
const disable_all = Bool.of(false);
2310-
export function showDemoWindowWidgets() {
2308+
export function showWidgetDemoWindow() {
23112309
// Most "big" widgets share a common width settings by default. See 'Demo->Layout->Widgets Width' for details.
23122310
// e.g. Use 2/3 of the space for widgets and 1/3 for labels (right align)
23132311
//ImGui::PushItemWidth(-ImGui::GetWindowWidth() * 0.35f);

src/imgui_input_text_callback_data.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ImGuiKey } from "./enum.ts";
22
import { ImGuiInputTextFlags, ImWchar } from "./type.ts";
3-
import { ffi as imgui } from "./ffi.ts";
3+
import { cString, ffi as imgui, StringSource } from "./ffi.ts";
44

55
/**
66
* Shared state of InputText() when using
@@ -116,4 +116,28 @@ export class ImGuiInputTextCallbackData {
116116
set SelectionEnd(value: number) {
117117
imgui.DImGuiInputTextCallbackDataSetSelectionEnd(this.#self, value);
118118
}
119+
120+
// IMGUI_API void DeleteChars(int pos, int bytes_count);
121+
// IMGUI_API void InsertChars(int pos, const char* text, const char* text_end = NULL);
122+
// void SelectAll() { SelectionStart = 0; SelectionEnd = BufTextLen; }
123+
// void ClearSelection() { SelectionStart = SelectionEnd = BufTextLen; }
124+
// bool HasSelection() const { return SelectionStart != SelectionEnd; }
125+
126+
deleteChars(pos: number, bytes_count: number) {
127+
imgui.ImGuiInputTextCallbackData_DeleteChars(this.#self, pos, bytes_count);
128+
}
129+
insertChars(pos: number, text: StringSource) {
130+
imgui.ImGuiInputTextCallbackData_InsertChars(this.#self, pos, cString(text), null);
131+
}
132+
selectAll() {
133+
this.SelectionStart = 0;
134+
this.SelectionEnd = this.BufTextLen;
135+
}
136+
clearSelction() {
137+
this.SelectionStart = this.BufTextLen;
138+
this.SelectionEnd = this.BufTextLen;
139+
}
140+
hasSelection() {
141+
return this.SelectionStart != this.SelectionEnd;
142+
}
119143
}

src/mod.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export * from "./type.ts";
2+
export * from "./enum.ts";
3+
export * from "./call.ts";
4+
export * from "./imgui_font_atlas.ts";
5+
export * from "./imgui_input_text_callback_data.ts";
6+
export * from "./imgui_io.ts";
7+
export * from "./imgui_style.ts";
8+
export * from "./callback.ts";
9+
export { cString, jsString, type StringSource } from "./ffi.ts";

test/test_dwm_window.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@ import {
77
} from "https://deno.land/x/[email protected]/mod.ts";
88
import * as gl from "https://deno.land/x/[email protected]/api/gles23.2.ts";
99
import * as imgui from "../mod.ts";
10-
import { Bool, ImGuiConfigFlagBits } from "../mod.ts";
11-
import { showDemoWindowWidgets } from "./test_demo.ts";
10+
import { Bool, ImGuiConfigFlagBits, showWidgetDemoWindow } from "../mod.ts";
1211

1312
function queryWindowSizeAndFontSize() {
1413
const aspectRatio = 16 / 9;
1514
const lines = 40;
16-
1715
const monitor = getPrimaryMonitor();
1816
const height = Math.ceil(monitor.workArea.height * 0.7);
1917
const width = Math.ceil(height * aspectRatio);
2018
const fontSize = Math.min(32, Math.ceil(height / lines));
21-
2219
return { width, height, fontSize };
2320
}
2421
const windowInfo = queryWindowSizeAndFontSize();
@@ -28,7 +25,6 @@ const window = createWindow({
2825
title: "IMGUI DWM",
2926
width: windowInfo.width,
3027
height: windowInfo.height,
31-
3228
resizable: true,
3329
glVersion: "v3.2",
3430
gles: false,
@@ -98,7 +94,7 @@ await mainloop(() => {
9894
imgui.implGlfwNewFrame();
9995
imgui.newFrame();
10096
showControllWindow();
101-
showDemoWindowWidgets();
97+
showWidgetDemoWindow();
10298
imgui.render();
10399
const drawData = imgui.getDrawData();
104100

test/test_self_window.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@ function getProcAddress(name: string) {
1313
}
1414

1515
function main() {
16-
const window = imgui.glfwCreateWindow(
17-
800,
18-
600,
19-
cString("DwmWindow"),
20-
null,
21-
null,
22-
);
16+
const window = imgui.glfwCreateWindow(800, 600, cString("DwmWindow"), null, null);
2317
if (!window) {
2418
throw new Error("Failed to create window");
2519
}

0 commit comments

Comments
 (0)