ktsu.ImGuiProvider 1.0.2

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

dotnet add package ktsu.ImGuiProvider

Quick Start

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<ImGuiContext>();

Usage with Backends

var services = new ServiceCollection();
services.AddImGui();
services.AddImGuiBackend<MyPlatformBackend>();
services.AddImGuiBackend<MyRendererBackend>();

var serviceProvider = services.BuildServiceProvider();
var context = serviceProvider.GetRequiredService<ImGuiContext>();

// Resolve and attach backends
var platformBackend = serviceProvider.GetRequiredService<IPlatformBackend>();
var rendererBackend = serviceProvider.GetRequiredService<IRendererBackend>();

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

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

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

    context.EndFrame();
}

context.Dispose();

Core Interfaces

IImGuiProvider

The main abstraction over ImGui functionality:

public interface IImGuiProvider : IDisposable
{
    nint CreateContext();
    void SetCurrentContext(nint context);
    nint GetCurrentContext();
    void DestroyContext(nint context);
    void NewFrame();
    void EndFrame();
    void Render();
    nint GetDrawData();
    bool Begin(string name);
    void End();
    void Text(string text);
    bool Button(string label);
    void ShowDemoWindow();
    // ... 160+ methods covering the full ImGui API
}

IImGuiBackend

Base interface for all backends:

public interface IImGuiBackend : IDisposable
{
    string Name { get; }
    bool Initialize();
    void Shutdown();
    void NewFrame();
    void RenderDrawData(nint drawData);
    void SetCurrentContext(nint context);
}

IPlatformBackend and IRendererBackend

Specialized backend interfaces:

public interface IPlatformBackend : IImGuiBackend
{
    void ProcessEvents();
}

public interface IRendererBackend : IImGuiBackend
{
    bool CreateDeviceObjects();
    void InvalidateDeviceObjects();
}

Custom Implementations

Custom Provider

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

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

Custom Backend

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<MyBackend>();

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

No packages depend on ktsu.ImGuiProvider.

## v1.0.2 (patch) Changes since v1.0.1: - docs: update documentation for clarity and add testing instructions ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.0.1 (patch) Changes since v1.0.0: - chore: remove unused package versions from Directory.Packages.props ([@matt-edmondson](https://github.com/matt-edmondson)) - test: add ImGuiContext lifecycle tests with Moq ([@matt-edmondson](https://github.com/matt-edmondson)) - test: add ServiceCollectionExtensions DI registration tests ([@matt-edmondson](https://github.com/matt-edmondson)) - chore: remove examples from library (examples are in README) ([@matt-edmondson](https://github.com/matt-edmondson)) - fix: use standard ktsu.Sdk pattern in csproj to fix build ([@matt-edmondson](https://github.com/matt-edmondson)) - chore: add API compat suppression file for Polyfill multi-targeting ([@matt-edmondson](https://github.com/matt-edmondson)) - Add CLAUDE.md for project guidance and architecture overview ([@matt-edmondson](https://github.com/matt-edmondson)) - feat: add MSTest project with Moq for unit testing ([@matt-edmondson](https://github.com/matt-edmondson)) - Remove .github\workflows\project.yml ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.0.0 (major) - Initial commit: Add project structure with essential configuration files, including .editorconfig, .gitattributes, .gitignore, and CI/CD workflows. Introduce PowerShell build automation module (PSBuild) and related scripts for .NET applications. Include licensing, authorship, and changelog files for project documentation. ([@matt-edmondson](https://github.com/matt-edmondson)) - Add drawing API methods to IImGuiProvider and HexaNetImGuiProvider for low-level rendering operations. Implemented methods for drawing lines, rectangles, circles, triangles, and text, enhancing the rendering capabilities of the library. ([@matt-edmondson](https://github.com/matt-edmondson)) - Refactor HexaNetImGuiProvider to enhance context management and expand window handling capabilities. Updated methods to utilize new ImGuiContextPtr and added overloads for window creation with flags. Introduced additional methods for child windows and improved documentation for existing methods in IImGuiProvider interface. ([@matt-edmondson](https://github.com/matt-edmondson)) - Implement Image and ImageButton methods in HexaNetImGuiProvider with default parameter handling and appropriate overloads for ImGui usage. Enhance functionality by creating ImTextureRef from textureId and setting default values for UV coordinates, tint, and background colors. ([@matt-edmondson](https://github.com/matt-edmondson)) - Initial implementation of ImGuiProvider library, including core interfaces, context management, and backend implementations for Hexa.NET. Added project and solution files for Visual Studio, along with dependency injection support for ImGui services and OpenGL/GLFW backends. ([@matt-edmondson](https://github.com/matt-edmondson)) - Update ImGuiProvider library with new dependencies, improved context management, and added README documentation. Updated Hexa.NET.ImGui version to 2.2.8.4, introduced Microsoft.Extensions.DependencyInjection packages, and removed obsolete backend implementations. Added examples for basic and advanced usage. ([@matt-edmondson](https://github.com/matt-edmondson)) - Update Microsoft.Extensions.DependencyInjection packages to version 9.0.7 in Directory.Packages.props for improved dependency management. ([@matt-edmondson](https://github.com/matt-edmondson))

Version Downloads Last updated
1.0.5 0 02/16/2026
1.0.5-pre.1 2 02/16/2026
1.0.4 15 02/14/2026
1.0.3 15 02/14/2026
1.0.2 53 02/10/2026
1.0.1 51 02/10/2026