Skip to main content

Spacing Functions

Spacing

Add vertical spacing between widgets. Example:

Dummy

Add a dummy item of given size. Unlike InvisibleButton(), Dummy() won’t take mouse clicks or be navigable.
const ImVec2&
Size of the dummy item in pixels
Example:

NewLine

Undo a SameLine() or force a new line when in a horizontal-layout context. Example:

Horizontal Layout

SameLine

Call between widgets or groups to layout them horizontally. X position given in window coordinates.
float
default:"0.0f"
Absolute X position from left of window. Use 0.0f to use current position.
float
default:"-1.0f"
Spacing from previous widget. Use -1.0f to use default spacing (style.ItemInnerSpacing.x).
Example:

Indentation

Indent

Move content position toward the right, by indent_w, or style.IndentSpacing if indent_w <= 0.
float
default:"0.0f"
Indentation width in pixels. Use 0.0f or negative for default style.IndentSpacing.
Example:

Unindent

Move content position back to the left, by indent_w, or style.IndentSpacing if indent_w <= 0.
float
default:"0.0f"
Indentation width in pixels. Use 0.0f or negative for default style.IndentSpacing.

Alignment

AlignTextToFramePadding

Vertically align upcoming text baseline to FramePadding.y so that it will align properly to regularly framed items (call if you have text on a line before a framed item). Example:

Separator

Separator

Horizontal separator line. Inside a menu bar or in horizontal layout mode, this becomes a vertical separator. Example:

SeparatorText

Currently: formatted text with a horizontal line.
const char*
Text to display on the separator
Example:

Measurement Functions

GetTextLineHeight

Get height of a single line of text. Approximately equals FontSize.
float
Height in pixels

GetTextLineHeightWithSpacing

Get height of a line plus spacing. Equals FontSize + style.ItemSpacing.y (distance in pixels between 2 consecutive lines of text).
float
Height with spacing in pixels

GetFrameHeight

Get height of a framed item. Approximately equals FontSize + style.FramePadding.y * 2.
float
Frame height in pixels

GetFrameHeightWithSpacing

Get height of a framed item plus spacing. Equals FontSize + style.FramePadding.y * 2 + style.ItemSpacing.y (distance in pixels between 2 consecutive lines of framed widgets).
float
Frame height with spacing in pixels

Common Patterns

Right-Aligned Widgets

Centered Widget

Uniform Grid Layout