From 1b330f420e5138dbd24049daa4c115f3959e68ec Mon Sep 17 00:00:00 2001 From: Mirolyub Hristov Date: Mon, 11 Aug 2014 21:43:48 +0200 Subject: [PATCH] Checkboxes and radio buttons can be clicked on their labels as well as their icon --- imgui.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 4f342814..3e6ce077 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3303,10 +3303,12 @@ void Checkbox(const char* label, bool* v) const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0,style.FramePadding.y), window->DC.CursorPos + ImVec2(0,style.FramePadding.y) + text_size); ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight())); - if (ClipAdvance(check_bb)) + const ImGuiAabb total_bb(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max)); + + if (ClipAdvance(total_bb)) return; - const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(check_bb); + const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(total_bb); const bool pressed = hovered && g.IO.MouseClicked[0]; if (hovered) g.HoveredId = id; @@ -3357,7 +3359,9 @@ bool RadioButton(const char* label, bool active) const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + text_size); ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight())); - if (ClipAdvance(check_bb)) + const ImGuiAabb total_bb(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max)); + + if (ClipAdvance(total_bb)) return false; ImVec2 center = check_bb.GetCenter(); @@ -3365,7 +3369,7 @@ bool RadioButton(const char* label, bool active) center.y = (float)(int)center.y + 0.5f; const float radius = check_bb.GetHeight() * 0.5f; - const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(check_bb); + const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(total_bb); const bool pressed = hovered && g.IO.MouseClicked[0]; if (hovered) g.HoveredId = id;