Skip to content

Commit 94908a2

Browse files
committed
Overhaul the library with autogenerated code.
This change overhauls ImGui.NET to be almost entirely auto-generated. It parses data files from cimgui, which contain pre-processed information about Dear ImGui's structures, enums, and functions. The code generator spits out identical C# types and functions, and also generates a safe, friendly wrapper layer. --- This is a combination of 22 commits. --- Initial attempt at auto-generating the native bindings. More WIP generator stuff. Mostly-working bindings with some TODO's left. More WIP stuff for safe wrappers and bindings. WIP Update cimgui definitions and even better safe wrappers. Fix "nonUDT" overloads and add a "RangeAccessor" struct. Remove constructor methods from wrapper types. More WIP Grab latest structs_and_enums.json file Attempted improvements Very good state, everything working. Correct cimgui.dll (win-x64) Rework how ref/out parameters are marshalled. Remove problematic string begin/end parameter pairs. Update native deps to 1.0.65, update ImGui.NET.csproj. Fix sample program compilation. Fix up XNA sample program with new binding changes. Add several more manual ImGui overloads to ease the upgrade. Add [Flags] to flags enums. Change version to 1.65.0. Capitalize "Dear ImGui".
1 parent b5407ee commit 94908a2

File tree

118 files changed

+28448
-5440
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+28448
-5440
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,7 @@ Session.vim
256256
*.VC.db
257257

258258
# Rider/Jetbrains IDEs
259-
.idea
259+
.idea
260+
261+
# download dir
262+
deps/

deps/cimgui/linux-x64/cimgui.so

54.1 KB
Binary file not shown.

deps/cimgui/osx-x64/cimgui.dylib

47.4 KB
Binary file not shown.

deps/cimgui/win-x64/cimgui.dll

37 KB
Binary file not shown.

deps/cimgui/win-x86/cimgui.dll

25 KB
Binary file not shown.

download-native-deps.ps1

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
param (
2+
[Parameter(Mandatory=$true)][string]$tag
3+
)
4+
5+
Write-Host Downloading native binaries from GitHub Releases...
6+
7+
if (Test-Path $PSScriptRoot\deps\cimgui\)
8+
{
9+
Remove-Item $PSScriptRoot\deps\cimgui\ -Force -Recurse | Out-Null
10+
}
11+
New-Item -ItemType Directory -Force -Path $PSScriptRoot\deps\cimgui\linux-x64 | Out-Null
12+
New-Item -ItemType Directory -Force -Path $PSScriptRoot\deps\cimgui\osx-x64 | Out-Null
13+
New-Item -ItemType Directory -Force -Path $PSScriptRoot\deps\cimgui\win-x86 | Out-Null
14+
New-Item -ItemType Directory -Force -Path $PSScriptRoot\deps\cimgui\win-x64 | Out-Null
15+
16+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
17+
18+
$client = New-Object System.Net.WebClient
19+
$client.DownloadFile(
20+
"https://github.com/mellinoe/imgui.net-nativebuild/releases/download/$tag/cimgui.win-x86.dll",
21+
"$PSScriptRoot/deps/cimgui/win-x86/cimgui.dll")
22+
if( -not $? )
23+
{
24+
$msg = $Error[0].Exception.Message
25+
Write-Error "Couldn't download x86 cimgui.dll. This most likely indicates the Windows native build failed."
26+
exit
27+
}
28+
29+
Write-Host "- cimgui.dll (x86)"
30+
31+
$client.DownloadFile(
32+
"https://github.com/mellinoe/imgui.net-nativebuild/releases/download/$tag/cimgui.win-x64.dll",
33+
"$PSScriptRoot/deps/cimgui/win-x64/$configuration/cimgui.dll")
34+
if( -not $? )
35+
{
36+
$msg = $Error[0].Exception.Message
37+
Write-Error "Couldn't download x64 cimgui.dll. This most likely indicates the Windows native build failed."
38+
exit
39+
}
40+
41+
Write-Host "- cimgui.dll (x64)"
42+
43+
$client.DownloadFile(
44+
"https://github.com/mellinoe/imgui.net-nativebuild/releases/download/$tag/cimgui.so",
45+
"$PSScriptRoot/deps/cimgui/linux-x64/cimgui.so")
46+
if( -not $? )
47+
{
48+
$msg = $Error[0].Exception.Message
49+
Write-Error "Couldn't download cimgui.so. This most likely indicates the Linux native build failed."
50+
exit
51+
}
52+
53+
Write-Host - cimgui.so
54+
55+
$client.DownloadFile(
56+
"https://github.com/mellinoe/imgui.net-nativebuild/releases/download/$tag/cimgui.dylib",
57+
"$PSScriptRoot/deps/cimgui/osx-x64/cimgui.dylib")
58+
if( -not $? )
59+
{
60+
$msg = $Error[0].Exception.Message
61+
Write-Error "Couldn't download cimgui.dylib. This most likely indicates the macOS native build failed."
62+
exit
63+
}
64+
65+
Write-Host - cimgui.dylib

src/CodeGenerator/CSharpCodeWriter.cs

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Text;
5+
6+
namespace CodeGenerator
7+
{
8+
class CSharpCodeWriter : IDisposable
9+
{
10+
private readonly StreamWriter _sw;
11+
private int _indentLevel = 0;
12+
13+
public CSharpCodeWriter(string outputPath)
14+
{
15+
_sw = File.CreateText(outputPath);
16+
}
17+
18+
public void Using(string ns)
19+
{
20+
WriteIndented($"using {ns};");
21+
}
22+
23+
public void PushBlock(string blockHeader)
24+
{
25+
WriteIndented(blockHeader);
26+
WriteIndented("{");
27+
_indentLevel += 4;
28+
}
29+
30+
public void PopBlock()
31+
{
32+
_indentLevel -= 4;
33+
WriteIndented("}");
34+
}
35+
36+
public void WriteLine(string text)
37+
{
38+
WriteIndented(text);
39+
}
40+
41+
private void WriteIndented(string text)
42+
{
43+
for (int i = 0; i < _indentLevel; i++)
44+
{
45+
_sw.Write(' ');
46+
}
47+
_sw.WriteLine(text);
48+
}
49+
50+
public void Dispose()
51+
{
52+
_sw.Dispose();
53+
}
54+
}
55+
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<Content Include="structs_and_enums.json" CopyToOutputDirectory="PreserveNewest" />
10+
<Content Include="definitions.json" CopyToOutputDirectory="PreserveNewest" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
15+
</ItemGroup>
16+
17+
</Project>

0 commit comments

Comments
 (0)