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 areBegin() and End():
Window Flags
You can customize window behavior with flags:Closable Windows
Pass abool* 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
UseImGuiCond 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
UseSameLine() 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
Dummy Widgets
UseDummy() 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
Menu Bars
Windows can have menu bars:Advanced Layout Patterns
Split Layouts
Footer Pattern
Aligned Buttons
Next Steps
- Learn about The ID Stack for managing widget identity
- Understand Input Handling for mouse and keyboard
- Explore Tables for advanced layouts