Skip to main content

Button Functions

Most widgets return true when the value has been changed or when pressed/selected.

Button

bool ImGui::Button(const char* label, const ImVec2& size = ImVec2(0, 0))
Standard button widget.
label
const char*
Button label text
size
const ImVec2&
default:"ImVec2(0, 0)"
Button size. Use 0 for auto-sizing
return
bool
True when clicked
// Example
if (ImGui::Button("Click Me")) {
    // Button was clicked
}

if (ImGui::Button("Wide Button", ImVec2(200, 0))) {
    // Custom width
}

SmallButton

bool ImGui::SmallButton(const char* label)
Button with FramePadding.y == 0 to easily embed within text.
label
const char*
Button label text
return
bool
True when clicked
// Example
ImGui::Text("Some text ");
ImGui::SameLine();
if (ImGui::SmallButton("x")) {
    // Small button clicked
}

InvisibleButton

bool ImGui::InvisibleButton(const char* str_id, const ImVec2& size, ImGuiButtonFlags flags = 0)
Flexible button behavior without the visuals. Frequently useful to build custom behaviors using the public API (along with IsItemActive, IsItemHovered, etc.).
str_id
const char*
Unique identifier (not displayed)
size
const ImVec2&
Button size
flags
ImGuiButtonFlags
default:"0"
Button flags (see ImGuiButtonFlags_)
return
bool
True when clicked
// Example
if (ImGui::InvisibleButton("##clickarea", ImVec2(100, 100))) {
    // Invisible button clicked
}
if (ImGui::IsItemHovered()) {
    ImGui::SetTooltip("Click me!");
}

ArrowButton

bool ImGui::ArrowButton(const char* str_id, ImGuiDir dir)
Square button with an arrow shape.
str_id
const char*
Unique identifier
dir
ImGuiDir
Arrow direction: ImGuiDir_Left, ImGuiDir_Right, ImGuiDir_Up, ImGuiDir_Down
return
bool
True when clicked
// Example
if (ImGui::ArrowButton("left", ImGuiDir_Left)) {
    // Left arrow clicked
}
ImGui::SameLine();
if (ImGui::ArrowButton("right", ImGuiDir_Right)) {
    // Right arrow clicked
}

Checkbox & Radio

Checkbox

bool ImGui::Checkbox(const char* label, bool* v)
Checkbox widget.
label
const char*
Checkbox label
v
bool*
Pointer to boolean value
return
bool
True when the value changes
// Example
static bool show_demo = true;
ImGui::Checkbox("Show Demo Window", &show_demo);

CheckboxFlags (int)

bool ImGui::CheckboxFlags(const char* label, int* flags, int flags_value)
Checkbox for bitflags (int).
label
const char*
Checkbox label
flags
int*
Pointer to flags variable
flags_value
int
Flag bit to toggle
return
bool
True when the value changes
// Example
static int my_flags = 0;
ImGui::CheckboxFlags("Flag 1", &my_flags, 1 << 0);
ImGui::CheckboxFlags("Flag 2", &my_flags, 1 << 1);

CheckboxFlags (unsigned int)

bool ImGui::CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value)
Checkbox for bitflags (unsigned int).
label
const char*
Checkbox label
flags
unsigned int*
Pointer to flags variable
flags_value
unsigned int
Flag bit to toggle
return
bool
True when the value changes

RadioButton (bool)

bool ImGui::RadioButton(const char* label, bool active)
Use with e.g. if (RadioButton("one", my_value==1)) { my_value = 1; }
label
const char*
Radio button label
active
bool
Whether this option is currently selected
return
bool
True when clicked
// Example
static int selected = 0;
if (ImGui::RadioButton("Option 1", selected == 0)) selected = 0;
if (ImGui::RadioButton("Option 2", selected == 1)) selected = 1;
if (ImGui::RadioButton("Option 3", selected == 2)) selected = 2;

RadioButton (int)

bool ImGui::RadioButton(const char* label, int* v, int v_button)
Shortcut to handle the radio button pattern when value is an integer.
label
const char*
Radio button label
v
int*
Pointer to current value
v_button
int
Value for this button
return
bool
True when the value changes
// Example
static int selected = 0;
ImGui::RadioButton("Option 1", &selected, 0);
ImGui::RadioButton("Option 2", &selected, 1);
ImGui::RadioButton("Option 3", &selected, 2);

Other Widgets

ProgressBar

void ImGui::ProgressBar(float fraction, const ImVec2& size_arg = ImVec2(-FLT_MIN, 0), const char* overlay = NULL)
Display a progress bar.
fraction
float
Progress value (0.0f to 1.0f)
size_arg
const ImVec2&
default:"ImVec2(-FLT_MIN, 0)"
Size of the progress bar
overlay
const char*
default:"NULL"
Optional text overlay
// Example
static float progress = 0.0f;
ImGui::ProgressBar(progress);
progress += 0.01f;
if (progress > 1.0f) progress = 0.0f;

ImGui::ProgressBar(0.65f, ImVec2(0.0f, 0.0f), "65%");
bool ImGui::TextLink(const char* label)
Hyperlink text button, return true when clicked.
label
const char*
Link text
return
bool
True when clicked
// Example
if (ImGui::TextLink("Click here")) {
    // Link clicked
}

TextLinkOpenURL

bool ImGui::TextLinkOpenURL(const char* label, const char* url = NULL)
Hyperlink text button, automatically open file/url when clicked.
label
const char*
Link text
url
const char*
default:"NULL"
URL to open (uses label if NULL)
return
bool
True when clicked
// Example
ImGui::TextLinkOpenURL("Visit Website", "https://github.com/ocornut/imgui");

Button Flags

ImGuiButtonFlags_

Flags for InvisibleButton().
FlagDescription
ImGuiButtonFlags_NoneDefault
ImGuiButtonFlags_MouseButtonLeftReact on left mouse button (default)
ImGuiButtonFlags_MouseButtonRightReact on right mouse button
ImGuiButtonFlags_MouseButtonMiddleReact on center mouse button
ImGuiButtonFlags_EnableNavDo not disable navigation/tabbing

Build docs developers (and LLMs) love