Skip to main content

Windows Fundamentals

In Dear ImGui, windows are the primary containers for UI elements. Every piece of UI must be inside a window.

Begin() and End()

The most important functions are Begin() and End():
Critical Rule: Always call End() to match every Begin() call, even if Begin() returns false!

Window Flags

You can customize window behavior with flags:
Common window flags:

Closable Windows

Pass a bool* to create a window with a close button:

Window States and Properties

Checking Window State

Begin() returns false when the window is collapsed. This allows you to skip expensive UI code when the window isn’t visible.

Window Appearance States

Controlling Windows

Setting Window Position and Size

Prefer using SetNextWindow* functions before Begin() rather than SetWindow* functions after Begin().

Window Conditions

Use ImGuiCond to control when to apply settings:

Focusing Windows

Child Windows

Child windows create scrollable regions within parent windows:

Child Window Sizing

Child Window Flags

Layout System

Dear ImGui uses a simple top-to-bottom, left-to-right automatic layout system.

Vertical Layout (Default)

Horizontal Layout

Use SameLine() to place widgets horizontally:

SameLine with Spacing

Spacing and Separators

Cursor Position

The “cursor” is the position where the next widget will be placed.

Getting Cursor Position

Setting Cursor Position

Using SetCursorPos() without placing an item won’t extend parent boundaries! Add Dummy(ImVec2(0,0)) to validate the position:

Dummy Widgets

Use Dummy() to reserve space:

Groups

Groups allow you to treat multiple widgets as a single item:

Indentation

Content Region

Get available space for laying out widgets:

Columns

Columns are a legacy API. For new code, prefer using Tables which are more powerful.

Scrolling

Manual Scrolling

Scrolling to Items

Windows can have menu bars:

Advanced Layout Patterns

Split Layouts

Aligned Buttons

Next Steps