Skip to main content
Window utility functions allow you to query window properties, check focus and hover states, and manipulate window positioning, sizing, and scrolling.

Window State Queries

IsWindowFocused

Checks if the current window is focused.

Parameters

ImGuiFocusedFlags
default:"0"
Flags to modify the focus check behavior. Common flags:
  • ImGuiFocusedFlags_ChildWindows - Check child windows too
  • ImGuiFocusedFlags_RootWindow - Check root window instead
  • ImGuiFocusedFlags_AnyWindow - Return true if any window is focused

Returns

bool
True if the current window (or specified scope) is focused.

Example

IsWindowHovered

Checks if the current window is hovered and hoverable.

Parameters

ImGuiHoveredFlags
default:"0"
Flags to modify hover check behavior. Common flags:
  • ImGuiHoveredFlags_ChildWindows - Check child windows too
  • ImGuiHoveredFlags_RootWindow - Check root window instead
  • ImGuiHoveredFlags_AllowWhenBlockedByPopup - Return true even if blocked by popup
  • ImGuiHoveredFlags_AllowWhenBlockedByActiveItem - Return true even if blocked by active item

Returns

bool
True if the current window is hovered and hoverable (not blocked by popup/modal).

Example

If you want to check whether your mouse should be dispatched to ImGui or your application, do not use this function. Use io.WantCaptureMouse instead. See FAQ: “How can I tell whether to dispatch mouse/keyboard to Dear ImGui or my application?”

Window Position & Size Queries

GetWindowPos

Gets the current window position in screen space.

Returns

ImVec2
Current window position in screen coordinates (pixels).

Example

It is unlikely you ever need to use this. Consider using GetCursorScreenPos() and GetContentRegionAvail() instead for layout purposes.

GetWindowSize

Gets the current window size.

Returns

ImVec2
Current window size including decorations (title bar, borders, etc.).

Example

GetWindowWidth / GetWindowHeight

Gets the current window width or height.

Returns

float
Current window width or height in pixels.

Example

Window Manipulation

Prefer using SetNextXXX functions (before Begin()) rather than SetXXX functions (after Begin()). The SetNext functions are cleaner and avoid potential side effects.

SetNextWindowPos

Sets the next window position (call before Begin()).

Parameters

const ImVec2&
required
Position in screen coordinates.
ImGuiCond
default:"0"
Condition for applying position:
  • 0 or ImGuiCond_Always - Always apply
  • ImGuiCond_Once - Apply once per runtime session
  • ImGuiCond_FirstUseEver - Apply only on first use
  • ImGuiCond_Appearing - Apply when window appears
const ImVec2&
default:"ImVec2(0, 0)"
Pivot point: (0,0) = top-left, (0.5,0.5) = center, (1,1) = bottom-right.

Example

SetNextWindowSize

Sets the next window size (call before Begin()).

Parameters

const ImVec2&
required
Window size. Set axis to 0.0f to force auto-fit on that axis.
ImGuiCond
default:"0"
Condition for applying size.

Example

SetNextWindowSizeConstraints

Sets the next window size constraints.

Parameters

const ImVec2&
required
Minimum size. Use 0.0f or FLT_MAX for no limit.
const ImVec2&
required
Maximum size. Use FLT_MAX for no limit. Use -1 for both min and max of same axis to preserve current size.
ImGuiSizeCallback
default:"NULL"
Optional callback for custom programmatic constraints.
void*
default:"NULL"
User data passed to the callback.

Example

Window Scrolling

GetScrollX / GetScrollY

Gets the current scroll position.

Returns

float
Current scroll amount from 0 to GetScrollMaxX() or GetScrollMaxY().

Example

SetScrollX / SetScrollY

Sets the scroll position.

Parameters

float
required
Scroll amount from 0 to GetScrollMaxX().
float
required
Scroll amount from 0 to GetScrollMaxY().

Example

Changes to scroll will be applied at the beginning of the next frame in the first call to Begin(). You can use SetNextWindowScroll() before Begin() to avoid this one-frame delay.

SetScrollHereY

Adjusts scrolling to make the current cursor position visible.

Parameters

float
default:"0.5f"
Position ratio: 0.0 = top, 0.5 = center, 1.0 = bottom.

Example

GetScrollMaxX / GetScrollMaxY

Gets the maximum scroll amount.

Returns

float
Maximum scroll amount ≈ ContentSize - WindowSize - DecorationsSize.

Example

Complete Example: Scrollable Log