Most widgets return true when the value has been changed or when pressed/selected.
bool ImGui::Button(const char* label, const ImVec2& size = ImVec2(0, 0))
Standard button widget.
size
const ImVec2&
default:"ImVec2(0, 0)"
Button size. Use 0 for auto-sizing
// Example
if (ImGui::Button("Click Me")) {
// Button was clicked
}
if (ImGui::Button("Wide Button", ImVec2(200, 0))) {
// Custom width
}
bool ImGui::SmallButton(const char* label)
Button with FramePadding.y == 0 to easily embed within text.
// Example
ImGui::Text("Some text ");
ImGui::SameLine();
if (ImGui::SmallButton("x")) {
// Small button clicked
}
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.).
Unique identifier (not displayed)
flags
ImGuiButtonFlags
default:"0"
Button flags (see ImGuiButtonFlags_)
// Example
if (ImGui::InvisibleButton("##clickarea", ImVec2(100, 100))) {
// Invisible button clicked
}
if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("Click me!");
}
bool ImGui::ArrowButton(const char* str_id, ImGuiDir dir)
Square button with an arrow shape.
Arrow direction: ImGuiDir_Left, ImGuiDir_Right, ImGuiDir_Up, ImGuiDir_Down
// 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.
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).
Pointer to flags variable
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).
Pointer to flags variable
True when the value changes
bool ImGui::RadioButton(const char* label, bool active)
Use with e.g. if (RadioButton("one", my_value==1)) { my_value = 1; }
Whether this option is currently selected
// 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;
bool ImGui::RadioButton(const char* label, int* v, int v_button)
Shortcut to handle the radio button pattern when value is an integer.
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);
ProgressBar
void ImGui::ProgressBar(float fraction, const ImVec2& size_arg = ImVec2(-FLT_MIN, 0), const char* overlay = NULL)
Display a progress bar.
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%");
TextLink
bool ImGui::TextLink(const char* label)
Hyperlink text button, return 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.
url
const char*
default:"NULL"
URL to open (uses label if NULL)
// Example
ImGui::TextLinkOpenURL("Visit Website", "https://github.com/ocornut/imgui");
Flags for InvisibleButton().
| Flag | Description |
|---|
ImGuiButtonFlags_None | Default |
ImGuiButtonFlags_MouseButtonLeft | React on left mouse button (default) |
ImGuiButtonFlags_MouseButtonRight | React on right mouse button |
ImGuiButtonFlags_MouseButtonMiddle | React on center mouse button |
ImGuiButtonFlags_EnableNav | Do not disable navigation/tabbing |