Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
JunaMeinhold committed Aug 18, 2024
2 parents 930b006 + e131df7 commit 1f22794
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 8 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/cimgui-android-cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Build cimgui Libraries (Android)

on: [workflow_dispatch]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
arch: x86_64
steps:
- uses: actions/checkout@v4.1.7
with:
repository: 'cimgui/cimgui'
path: 'cimgui'
submodules: true

- name: Install dependencies on Ubuntu
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake ninja-build
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17

- name: Setup Android SDK
uses: android-actions/setup-android@v2.0.10

- name: Install Android NDK
run: sdkmanager --install "ndk-bundle"

- name: Build for arm64-v8a
run: |
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_ANDROID_NDK=$ANDROID_NDK_HOME \
-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \
-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang \
-DCMAKE_ANDROID_STL_TYPE=c++_shared \
-DCMAKE_ANDROID_API=21 \
-S cimgui \
-B cimgui/build/arm64-v8a
cmake --build cimgui/build/arm64-v8a --config Release
- name: Build for x86_64
run: |
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_ANDROID_NDK=$ANDROID_NDK_HOME \
-DCMAKE_ANDROID_ARCH_ABI=x86_64 \
-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang \
-DCMAKE_ANDROID_STL_TYPE=c++_shared \
-DCMAKE_ANDROID_API=21 \
-S cimgui \
-B cimgui/build/x86_64
cmake --build cimgui/build/x86_64 --config Release
- name: Upload Artifacts
uses: actions/upload-artifact@v4.3.4
with:
name: ${{ matrix.os }}-${{ matrix.arch }}-artifacts
path: |
cimgui/build/arm64-v8a/*.so
cimgui/build/x86_64/*.so
if-no-files-found: ignore # 'warn' or 'ignore' or 'error'
66 changes: 66 additions & 0 deletions .github/workflows/cimgui-cmake-dbg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Build cimgui Libraries (Debug config)

on: [workflow_dispatch]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
arch: x86_64
- os: ubuntu-latest
arch: arm64
- os: windows-latest
arch: x86_64
- os: windows-latest
arch: x86
- os: windows-latest
arch: arm64
- os: macos-latest
arch: x86_64
- os: macos-latest
arch: arm64
steps:
- uses: actions/checkout@v4.1.7
with:
repository: 'cimgui/cimgui'
path: 'cimgui'
submodules: true

- name: Install dependencies on Ubuntu
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake
- name: Install dependencies on macOS
if: matrix.os == 'macos-latest'
run: |
brew update
brew install cmake
- name: Install dependencies on Windows
if: matrix.os == 'windows-latest'
run: |
choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System'
- name: Configure cimgui with CMake for macOS ARM64
if: matrix.arch == 'arm64' && matrix.os == 'macos-latest'
run: cmake -S cimgui -B cimgui/build -DCMAKE_OSX_ARCHITECTURES=arm64

- name: Configure cimgui with CMake
if: matrix.arch != 'arm64' || matrix.os != 'macos-latest'
run: cmake -S cimgui -B cimgui/build

- name: Build cimgui
run: cmake --build cimgui/build --config Debug

- name: Upload Artifacts
uses: actions/upload-artifact@v4.3.4
with:
name: ${{ matrix.os }}-${{ matrix.arch }}-artifacts
path: |
cimgui/build/
if-no-files-found: ignore # 'warn' or 'ignore' or 'error'
4 changes: 2 additions & 2 deletions ExampleFramework/ImGuiDemo/ImGuiSDL2Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ public static unsafe void Shutdown()
if (bd->ClipboardTextData != null)
sdl.Free(bd->ClipboardTextData);
for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor.Count; cursor_n++)
sdl.Free(bd->MouseCursors[(int)cursor_n]);
sdl.FreeCursor(bd->MouseCursors[(int)cursor_n]);
Free(bd->MouseCursors);
CloseGamepads();

Expand Down Expand Up @@ -1051,4 +1051,4 @@ private static void ShutdownPlatformInterface()
ImGui.DestroyPlatformWindows();
}
}
}
}
37 changes: 31 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Hexa.NET.ImGui

Hexa.NET.ImGui is a .NET wrapper for the Dear ImGui (1.90.9) library, including support for internal components and popular addons like ImGuizmo, ImNodes, and ImPlot. This wrapper allows developers to leverage the powerful and flexible Dear ImGui library within the .NET ecosystem.
Welcome to Hexa.NET.ImGui! This custom wrapper is designed to be a high-performance, API-compatible alternative to ImGuiNET, offering enhanced speed, additional functionality, and comprehensive access to ImGui's internal structures. With optimizations that bring near C performance and significantly reduced startup times, Hexa.NET.ImGui provides the best of both worlds: the power of C and the productivity of C#.

#### The code generator in use [HexaGen](https://github.com/HexaEngine/HexaGen).

## Features

Expand All @@ -12,6 +14,7 @@ Hexa.NET.ImGui is a .NET wrapper for the Dear ImGui (1.90.9) library, including
- **Access to Internals**: Allows users to access Dear ImGui internals for advanced customization and functionality.
- **Drop in replacement for ImGuiNET** Adapt to the library with minimal effort by simply changing the namespace.
- **High performance** Using a static VTable, all API calls are faster and startup time is reduced.
- **Optimized String Handling**: Overloads that bypass UTF-8 encoding and avoid allocations.

## Packages

Expand Down Expand Up @@ -64,18 +67,40 @@ For a comprehensive example of how to use the library, refer to the [ExampleD3D1

For details on how to set up the library, check the [ImGuiManager.cs](https://github.com/HexaEngine/Hexa.NET.ImGui/blob/master/ExampleD3D11/ImGuiDemo/ImGuiManager.cs) file in the ExampleD3D11 project.

### Using the Flexible and Optimized API

Hexa.NET.ImGui supports both safe and unsafe API calls, along with optimized string handling to bypass UTF-8 encoding and avoid allocations. Here are some examples:

1. Safe API Call:

```cs
ImGui.Text("A normal C# string");
```

2. Unsafe API Call:
```cs
unsafe
{
byte* pText = (byte*)Marshal.StringToHGlobalAnsi("A string from an unsafe pointer").ToPointer();
ImGui.Text(pText);
Marshal.FreeHGlobal((IntPtr)pText);
}
```
3. Optimized String Handling:
```cs
ImGui.Text("A C# string"u8);
```
**This overload bypasses UTF-8 encoding and avoids allocations, providing a highly optimized way to render text.**
## Projects Using Hexa.NET.ImGui
[HexaEngine](https://github.com/HexaEngine/HexaEngine)
<img src="https://github.com/user-attachments/assets/b54145fe-5bd5-4998-b36f-24efe8345aba" alt="HexaEngine Editor" width="400"/>
## TODO

- **Refactor the generator**: Improve the code generation process for better performance and maintainability.
- **More demos**: Add additional demo applications to showcase various features and use cases.

## Screenshots
### Main Interface
Expand Down

0 comments on commit 1f22794

Please sign in to comment.