Skip to content

Commit

Permalink
reorganize exports & change README
Browse files Browse the repository at this point in the history
  • Loading branch information
djfos committed Mar 11, 2023
1 parent 869cdc9 commit 7eea4c5
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 46 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@
# Status

> Not ready for use
> For now, only build on windows with opengl backend.
# Usage

```typescript
// TODO
```

# Contribute

```bash
# build
# build the shared library
deno task build

# generate cimgui ffi symbols
# generate cimgui ffi symbols and many draft to copy
deno task gen
# test for window created by imgui.dll
deno task test-self
# test for window created by dwm
deno task test-dwm
# test for window created by embeded glfw
deno task test-self
```
2 changes: 1 addition & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
]
}
}
}
}
5 changes: 2 additions & 3 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from "./src/type.ts";
export * from "./src/enum.ts";
export * from "./src/call.ts";
export * from "./src/mod.ts";
export * from "./src/demo.ts";
1 change: 1 addition & 0 deletions script/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function embed(): void {
const binFile = join(binPath, getBinFileName());
const outFile = join(distPath, getOutFileName());

// deno-lint-ignore no-explicit-any
const encode = (Deno as any)[(Deno as any).internal]
.core
.ops.op_base64_encode;
Expand Down
2 changes: 1 addition & 1 deletion script/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const DIMGUI_VERSION = "0.1.1";
export const DIMGUI_VERSION = "0.2.0";
7 changes: 0 additions & 7 deletions src/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -814,13 +814,6 @@ export function getColorU32_U32(col: ImU32): ImU32 {
return imgui.igGetColorU32_U32(col);
}

// export function getStyleColorVec4(idx: ImGuiCol): ImVec4 {
// TODO editable ImVec4
// const vec4 = new ImVec4();
// return imgui.igGetStyleColorVec4(idx);
// return vec4;
// }

// // Cursor / Layout
// // - By "cursor" we mean the current output position.
// // - The typical widget behavior is to output themselves at the current cursor position, then move the cursor one line down.
Expand Down
26 changes: 12 additions & 14 deletions test/test_demo.ts → src/demo.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
import * as imgui from "../mod.ts";
import * as imgui from "./mod.ts";
import {
Bool,
Double,
Float,
ImGuiCol,
ImGuiColorEditFlagBits,
ImGuiComboFlagBits,
ImGuiCond,
ImGuiDir,
ImGuiDragDropFlagBits,
ImGuiFocusedFlagBits,
ImGuiHoveredFlagBits,
ImGuiInputTextCallbackData,
ImGuiInputTextFlagBits,
ImGuiKey,
ImGuiPayloadType,
ImGuiSelectableFlagBits,
ImGuiSliderFlagBits,
ImGuiStyleVar,
ImGuiTabBarFlagBits,
ImGuiTabItemFlagBits,
ImGuiTableFlagBits,
ImGuiTreeNodeFlagBits,
ImVec2,
ImVec4,
Int32,
Utf8Array,
} from "../mod.ts";
import {
ImGuiColorEditFlagBits,
ImGuiDragDropFlagBits,
ImGuiFocusedFlagBits,
ImGuiInputTextFlagBits,
ImGuiPayloadType,
ImGuiStyleVar,
ImGuiTabBarFlagBits,
ImGuiTabItemFlagBits,
} from "../src/enum.ts";
import { ImGuiInputTextCallbackData } from "../src/imgui_input_text_callback_data.ts";
} from "./mod.ts";

/**
* Helper to display a little (?) mark which shows a tooltip when hovered.
Expand Down Expand Up @@ -2307,7 +2305,7 @@ function demoQueryingWindow() {
* The Checkbox for that is inside the "Disabled" section at the bottom
*/
const disable_all = Bool.of(false);
export function showDemoWindowWidgets() {
export function showWidgetDemoWindow() {
// Most "big" widgets share a common width settings by default. See 'Demo->Layout->Widgets Width' for details.
// e.g. Use 2/3 of the space for widgets and 1/3 for labels (right align)
//ImGui::PushItemWidth(-ImGui::GetWindowWidth() * 0.35f);
Expand Down
26 changes: 25 additions & 1 deletion src/imgui_input_text_callback_data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ImGuiKey } from "./enum.ts";
import { ImGuiInputTextFlags, ImWchar } from "./type.ts";
import { ffi as imgui } from "./ffi.ts";
import { cString, ffi as imgui, StringSource } from "./ffi.ts";

/**
* Shared state of InputText() when using
Expand Down Expand Up @@ -116,4 +116,28 @@ export class ImGuiInputTextCallbackData {
set SelectionEnd(value: number) {
imgui.DImGuiInputTextCallbackDataSetSelectionEnd(this.#self, value);
}

// IMGUI_API void DeleteChars(int pos, int bytes_count);
// IMGUI_API void InsertChars(int pos, const char* text, const char* text_end = NULL);
// void SelectAll() { SelectionStart = 0; SelectionEnd = BufTextLen; }
// void ClearSelection() { SelectionStart = SelectionEnd = BufTextLen; }
// bool HasSelection() const { return SelectionStart != SelectionEnd; }

deleteChars(pos: number, bytes_count: number) {
imgui.ImGuiInputTextCallbackData_DeleteChars(this.#self, pos, bytes_count);
}
insertChars(pos: number, text: StringSource) {
imgui.ImGuiInputTextCallbackData_InsertChars(this.#self, pos, cString(text), null);
}
selectAll() {
this.SelectionStart = 0;
this.SelectionEnd = this.BufTextLen;
}
clearSelction() {
this.SelectionStart = this.BufTextLen;
this.SelectionEnd = this.BufTextLen;
}
hasSelection() {
return this.SelectionStart != this.SelectionEnd;
}
}
9 changes: 9 additions & 0 deletions src/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export * from "./type.ts";
export * from "./enum.ts";
export * from "./call.ts";
export * from "./imgui_font_atlas.ts";
export * from "./imgui_input_text_callback_data.ts";
export * from "./imgui_io.ts";
export * from "./imgui_style.ts";
export * from "./callback.ts";
export { cString, jsString, type StringSource } from "./ffi.ts";
8 changes: 2 additions & 6 deletions test/test_dwm_window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@ import {
} from "https://deno.land/x/[email protected]/mod.ts";
import * as gl from "https://deno.land/x/[email protected]/api/gles23.2.ts";
import * as imgui from "../mod.ts";
import { Bool, ImGuiConfigFlagBits } from "../mod.ts";
import { showDemoWindowWidgets } from "./test_demo.ts";
import { Bool, ImGuiConfigFlagBits, showWidgetDemoWindow } from "../mod.ts";

function queryWindowSizeAndFontSize() {
const aspectRatio = 16 / 9;
const lines = 40;

const monitor = getPrimaryMonitor();
const height = Math.ceil(monitor.workArea.height * 0.7);
const width = Math.ceil(height * aspectRatio);
const fontSize = Math.min(32, Math.ceil(height / lines));

return { width, height, fontSize };
}
const windowInfo = queryWindowSizeAndFontSize();
Expand All @@ -28,7 +25,6 @@ const window = createWindow({
title: "IMGUI DWM",
width: windowInfo.width,
height: windowInfo.height,

resizable: true,
glVersion: "v3.2",
gles: false,
Expand Down Expand Up @@ -98,7 +94,7 @@ await mainloop(() => {
imgui.implGlfwNewFrame();
imgui.newFrame();
showControllWindow();
showDemoWindowWidgets();
showWidgetDemoWindow();
imgui.render();
const drawData = imgui.getDrawData();

Expand Down
8 changes: 1 addition & 7 deletions test/test_self_window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ function getProcAddress(name: string) {
}

function main() {
const window = imgui.glfwCreateWindow(
800,
600,
cString("DwmWindow"),
null,
null,
);
const window = imgui.glfwCreateWindow(800, 600, cString("DwmWindow"), null, null);
if (!window) {
throw new Error("Failed to create window");
}
Expand Down

0 comments on commit 7eea4c5

Please sign in to comment.