An open API service indexing awesome lists of open source software.

https://github.com/ktsu-dev/imguiprovider

A dependency injection abstraction layer over ImGui implementations for .NET.
https://github.com/ktsu-dev/imguiprovider

abstraction backend-abstraction csharp dear-imgui dependency-injection dotnet hexa-net imgui-provider provider-pattern rendering windowing

Last synced: 11 days ago
JSON representation

A dependency injection abstraction layer over ImGui implementations for .NET.

Awesome Lists containing this project

README

          

# ImGuiProvider

A dependency injection abstraction layer over ImGui implementations for .NET, providing clean interfaces and swappable backends.

## Features

- **Dependency Injection** - Clean integration with `Microsoft.Extensions.DependencyInjection`
- **Provider Abstraction** - `IImGuiProvider` interface wrapping 160+ ImGui methods allows swapping implementations
- **Backend Support** - Separate `IPlatformBackend` and `IRendererBackend` interfaces for windowing and rendering
- **Context Management** - `ImGuiContext` handles the full frame lifecycle (initialize, begin frame, end frame, dispose)
- **Built-in Implementation** - Ships with `HexaNetImGuiProvider` wrapping Hexa.NET.ImGui

## Installation

```bash
dotnet add package ktsu.ImGuiProvider
```

## Quick Start

```csharp
using ImGuiProvider.Extensions;
using ImGuiProvider.Services;
using Microsoft.Extensions.DependencyInjection;

var services = new ServiceCollection();
services.AddImGui(); // Registers HexaNetImGuiProvider as singleton

var serviceProvider = services.BuildServiceProvider();
var context = serviceProvider.GetRequiredService();
```

## Usage with Backends

```csharp
var services = new ServiceCollection();
services.AddImGui();
services.AddImGuiBackend();
services.AddImGuiBackend();

var serviceProvider = services.BuildServiceProvider();
var context = serviceProvider.GetRequiredService();

// Resolve and attach backends
var platformBackend = serviceProvider.GetRequiredService();
var rendererBackend = serviceProvider.GetRequiredService();

context.Initialize();
context.AddBackend(platformBackend);
context.AddBackend(rendererBackend);
context.InitializeBackends();

// Render loop
while (running)
{
context.BeginFrame();

// Your ImGui code here
var provider = serviceProvider.GetRequiredService();
provider.ShowDemoWindow();

context.EndFrame();
}

context.Dispose();
```

## Custom Implementations

### Custom Provider

```csharp
public class MyProvider : IImGuiProvider
{
// Implement all IImGuiProvider methods
}

services.AddImGui();
// Or with a factory:
services.AddImGui(sp => new MyProvider());
```

### Custom Backend

```csharp
public class MyBackend : IRendererBackend
{
public string Name => "My Backend";
public bool Initialize() => true;
public void Shutdown() { }
public void NewFrame() { }
public void RenderDrawData(nint drawData) { }
public void SetCurrentContext(nint context) { }
public bool CreateDeviceObjects() => true;
public void InvalidateDeviceObjects() { }
public void Dispose() { }
}

services.AddImGuiBackend();
```

## Requirements

- .NET 8.0, 9.0, or 10.0
- Hexa.NET.ImGui 2.2.8.4
- Microsoft.Extensions.DependencyInjection.Abstractions 9.0.7

## License

MIT License