ktsu.ImGuiProvider 1.0.1

ImGuiProvider

A dependency injection wrapper library for ImGui implementations, providing a clean abstraction over ImGui libraries with support for multiple backends.

Features

  • Dependency Injection: Clean DI integration with Microsoft.Extensions.DependencyInjection
  • Provider Abstraction: IImGuiProvider interface allows swapping ImGui implementations
  • Backend Support: Separate interfaces for platform and renderer backends
  • Hexa.NET.ImGui: Built-in implementation using Hexa.NET.ImGui
  • SOLID Principles: Follows SOLID design principles with clear separation of concerns
  • Context Management: High-level context management with lifecycle handling

Installation

<PackageReference Include="ImGuiProvider" Version="1.0.0" />

Quick Start

Basic Setup with Dependency Injection

using ImGuiProvider.Extensions;
using Microsoft.Extensions.DependencyInjection;

// Configure services
var services = new ServiceCollection();
services.AddImGui(); // Uses Hexa.NET.ImGui by default

// Build service provider
var serviceProvider = services.BuildServiceProvider();

// Get ImGui context
var imguiContext = serviceProvider.GetRequiredService<ImGuiContext>();

Advanced Setup with Backends

using ImGuiProvider.Extensions;
using Microsoft.Extensions.DependencyInjection;

var services = new ServiceCollection();

// Add ImGui provider
services.AddImGui();

// Add backends (assumes you have GLFW window handle)
services.AddImGuiGLFWBackend(windowHandle, installCallbacks: true);
services.AddImGuiOpenGL3Backend(glslVersion: "#version 330");

var serviceProvider = services.BuildServiceProvider();

// Initialize and use
var context = serviceProvider.GetRequiredService<ImGuiContext>();
var glfwBackend = serviceProvider.GetRequiredService<IPlatformBackend>();
var openglBackend = serviceProvider.GetRequiredService<IRendererBackend>();

// Initialize context and backends
context.Initialize();
context.AddBackend(glfwBackend);
context.AddBackend(openglBackend);
context.InitializeBackends();

// Main loop
while (running)
{
    // Process events...
    
    context.BeginFrame();
    
    // Your ImGui code here
    var provider = serviceProvider.GetRequiredService<IImGuiProvider>();
    provider.ShowDemoWindow();
    
    context.EndFrame();
    
    // Swap buffers...
}

context.Dispose();

Core Interfaces

IImGuiProvider

The main abstraction over ImGui functionality:

public interface IImGuiProvider : IDisposable
{
    // Context management
    nint CreateContext();
    void SetCurrentContext(nint context);
    nint GetCurrentContext();
    void DestroyContext(nint context);

    // Frame management
    void NewFrame();
    void EndFrame();
    void Render();
    nint GetDrawData();

    // UI methods
    bool Begin(string name);
    void End();
    void Text(string text);
    bool Button(string label);
    void ShowDemoWindow();
    // ... and more
}

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 & IRendererBackend

Specialized backend interfaces:

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

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

Built-in Implementations

HexaNetImGuiProvider

Uses Hexa.NET.ImGui as the underlying implementation:

services.AddImGui(); // Default Hexa.NET implementation

Available Backends

  • HexaNetOpenGL3Backend: OpenGL 3+ renderer using Hexa.NET.ImGui.Backends
  • HexaNetGLFWBackend: GLFW platform backend using Hexa.NET.ImGui.Backends.GLFW

Custom Implementations

Custom Provider

public class MyImGuiProvider : IImGuiProvider
{
    // Implement interface methods
    public nint CreateContext() => /* your implementation */;
    // ... etc
}

// Register custom provider
services.AddImGui<MyImGuiProvider>();

Custom Backend

public class MyCustomBackend : IRendererBackend
{
    public string Name => "My Custom Backend";
    // Implement interface methods
}

// Register custom backend
services.AddImGuiBackend<MyCustomBackend>();

Architecture

The library follows SOLID principles with clear separation:

┌─────────────────┐    ┌─────────────────────┐
│   Application   │────│  ImGuiContext       │
└─────────────────┘    └─────────────────────┘
                              │
                    ┌─────────┴─────────┐
                    │                   │
            ┌───────▼────────┐  ┌───────▼─────────┐
            │ IImGuiProvider │  │ IImGuiBackend   │
            └────────────────┘  └─────────────────┘
                    │                   │
        ┌───────────▼──────────┐       │
        │ HexaNetImGuiProvider │       │
        └──────────────────────┘       │
                               ┌───────▼─────────────┐
                               │ Platform & Renderer │
                               │     Backends        │
                               └─────────────────────┘

Requirements

  • .NET 8.0 or later
  • Hexa.NET.ImGui 2.1.7 or later
  • Microsoft.Extensions.DependencyInjection.Abstractions 8.0.0 or later

License

MIT License

No packages depend on ktsu.ImGuiProvider.

## 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