Skip to main content

Overview

Dear ImGui uses a cursor-based layout system. The cursor represents the current output position where the next widget will be placed. Understanding cursor positioning is fundamental to creating custom layouts.
YOU CAN DO 99% OF WHAT YOU NEED WITH ONLY GetCursorScreenPos() and GetContentRegionAvail().

Coordinate Systems

Dear ImGui uses two coordinate systems:
  • Absolute coordinates: GetCursorScreenPos(), SetCursorScreenPos(), all ImDrawList functions
  • Window-local coordinates: GetCursorPos(), SetCursorPos(), GetCursorStartPos()
We currently have inconsistencies between window-local and absolute positions that will be addressed in future API updates. Prefer using absolute coordinates via GetCursorScreenPos().

Primary Cursor Functions

GetCursorScreenPos

Get cursor position in absolute screen coordinates. This is your best friend.
ImVec2
Current cursor position in absolute screen coordinates
Example:

SetCursorScreenPos

Set cursor position using absolute screen coordinates. This is your best friend.
const ImVec2&
New cursor position in absolute screen coordinates
Example:

GetContentRegionAvail

Get available space from current cursor position. This is your best friend.
ImVec2
Available space in current region
Example:

Window-Local Cursor Functions

These functions use window-local coordinates. Prefer using GetCursorScreenPos() instead.

GetCursorPos

Get cursor position in window-local coordinates.
ImVec2
Cursor position in window-local coordinates

GetCursorPosX / GetCursorPosY

Get X or Y component of cursor position in window-local coordinates.

SetCursorPos

Set cursor position in window-local coordinates.
const ImVec2&
New cursor position in window-local coordinates

SetCursorPosX / SetCursorPosY

Set X or Y component of cursor position in window-local coordinates.
float
New X position in window-local coordinates
float
New Y position in window-local coordinates

GetCursorStartPos

Get initial cursor position in window-local coordinates. Call GetCursorScreenPos() after Begin() to get the absolute coordinates version.
ImVec2
Initial cursor position in window-local coordinates

Conversion

To convert between coordinate systems:
GetWindowPos() is almost only ever useful to convert from window-local to absolute coordinates. Try not to use it.
See also: