Skip to main content

Overview

This guide covers recommended patterns and practices for building maintainable, performant Dear ImGui applications.

Core Principles

Immediate Mode Paradigm

Dear ImGui uses an immediate mode API where UI is rebuilt every frame:
Unlike retained-mode UIs, you don’t create widgets once and modify them later. Instead, you emit them fresh each frame.

Application Owns Data

ID Management

Understanding IDs

Every interactive widget needs a unique ID. Most common mistake: using duplicate IDs.

ID Stack Tool

Use the built-in tool to debug ID issues:

Window Management

Always Match Begin/End

Begin/End and BeginChild/EndChild must always be paired, unlike other BeginXXX/EndXXX functions.

Window Flags

Use appropriate flags for your use case:

Layout Best Practices

Use GetContentRegionAvail

Proper Spacing

Tables for Complex Layouts

Input Handling

Check WantCapture Flags

Always pass input to ImGui first, then check WantCapture flags before handling in your application.

Style Management

Push/Pop Pattern

Initialize Style Once

Performance

Minimize Window Count

Early Exit for Collapsed Windows

Use ListClipper for Large Lists

Reduce Draw Calls

Error Prevention

Static Buffers for InputText

Static Arrays for Persistent Data

RAII Helpers

Create helpers for automatic cleanup:

Organization

Modular UI Functions

Separate Data from UI

Testing and Debugging

Use Demo Window

Metrics Window

Assert on Errors

Common Pitfalls

Always pair Begin() with End(), even if Begin() returns false.
Most common beginner mistake. Use PushID or ## suffix.
Use PushStyleVar/PushStyleColor for temporary changes, not direct ImGuiStyle modification.
Use u8"" prefix for non-ASCII strings and ensure source files are UTF-8.
Dear ImGui layouts are dynamic. Use GetContentRegionAvail() instead of hardcoded sizes.

See Also