From 2fb63b6068264960707d3018fa57145a9f0ff415 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 28 Aug 2014 17:32:03 +0100 Subject: [PATCH] Checkbox() return true when pressed --- imgui.cpp | 13 ++++++++----- imgui.h | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index da69ba37..dedda758 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3495,12 +3495,12 @@ void PlotHistogram(const char* label, const float* values, int values_count, int ImGui::Plot(ImGuiPlotType_Histogram, label, values, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size, stride); } -void Checkbox(const char* label, bool* v) +bool Checkbox(const char* label, bool* v) { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) - return; + return false; const ImGuiStyle& style = g.Style; const ImGuiID id = window->GetID(label); @@ -3516,7 +3516,7 @@ void Checkbox(const char* label, bool* v) const ImGuiAabb total_bb(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max)); if (ClipAdvance(total_bb)) - return; + return false; const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(total_bb); const bool pressed = hovered && g.IO.MouseClicked[0]; @@ -3537,16 +3537,19 @@ void Checkbox(const char* label, bool* v) if (g.LogEnabled) LogText(text_bb.GetTL(), *v ? "[x]" : "[ ]"); RenderText(text_bb.GetTL(), label); + + return pressed; } -void CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value) +bool CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value) { bool v = (*flags & flags_value) ? true : false; - ImGui::Checkbox(label, &v); + bool pressed = ImGui::Checkbox(label, &v); if (v) *flags |= flags_value; else *flags &= ~flags_value; + return pressed; } bool RadioButton(const char* label, bool active) diff --git a/imgui.h b/imgui.h index 5e3ff74b..ee497e73 100644 --- a/imgui.h +++ b/imgui.h @@ -197,8 +197,8 @@ namespace ImGui bool SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format = "%.0f"); void PlotLines(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float)); void PlotHistogram(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float)); - void Checkbox(const char* label, bool* v); - void CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value); + bool Checkbox(const char* label, bool* v); + bool CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value); bool RadioButton(const char* label, bool active); bool RadioButton(const char* label, int* v, int v_button); bool InputFloat(const char* label, float* v, float step = 0.0f, float step_fast = 0.0f, int decimal_precision = -1);