Checkbox() return true when pressed

This commit is contained in:
ocornut 2014-08-28 17:32:03 +01:00
parent cd3d027df0
commit 2fb63b6068
2 changed files with 10 additions and 7 deletions

View File

@ -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)

View File

@ -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);