Merge pull request #9 from mhristov/master

Checkbox & radio button improvements
This commit is contained in:
Omar C 2014-08-11 23:37:53 +01:00
commit 2a1ba33263
2 changed files with 14 additions and 7 deletions

View File

@ -226,6 +226,7 @@ ImGuiStyle::ImGuiStyle()
Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.40f, 0.40f, 0.80f, 0.40f); Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.40f, 0.40f, 0.80f, 0.40f);
Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 0.40f); Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 0.40f);
Colors[ImGuiCol_ComboBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.99f); Colors[ImGuiCol_ComboBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.99f);
Colors[ImGuiCol_CheckHovered] = ImVec4(0.60f, 0.40f, 0.40f, 1.00f);
Colors[ImGuiCol_CheckActive] = ImVec4(0.90f, 0.90f, 0.90f, 0.50f); Colors[ImGuiCol_CheckActive] = ImVec4(0.90f, 0.90f, 0.90f, 0.50f);
Colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f); Colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f);
Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f); Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f);
@ -2173,6 +2174,7 @@ const char* GetStyleColorName(ImGuiCol idx)
case ImGuiCol_ScrollbarGrabHovered: return "ScrollbarGrabHovered"; case ImGuiCol_ScrollbarGrabHovered: return "ScrollbarGrabHovered";
case ImGuiCol_ScrollbarGrabActive: return "ScrollbarGrabActive"; case ImGuiCol_ScrollbarGrabActive: return "ScrollbarGrabActive";
case ImGuiCol_ComboBg: return "ComboBg"; case ImGuiCol_ComboBg: return "ComboBg";
case ImGuiCol_CheckHovered: return "CheckHovered";
case ImGuiCol_CheckActive: return "CheckActive"; case ImGuiCol_CheckActive: return "CheckActive";
case ImGuiCol_SliderGrab: return "SliderGrab"; case ImGuiCol_SliderGrab: return "SliderGrab";
case ImGuiCol_SliderGrabActive: return "SliderGrabActive"; case ImGuiCol_SliderGrabActive: return "SliderGrabActive";
@ -3306,12 +3308,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); 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())); 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; return;
RenderFrame(check_bb.Min, check_bb.Max, window->Color(ImGuiCol_FrameBg)); const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(total_bb);
const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(check_bb);
const bool pressed = hovered && g.IO.MouseClicked[0]; const bool pressed = hovered && g.IO.MouseClicked[0];
if (hovered) if (hovered)
g.HoveredId = id; g.HoveredId = id;
@ -3321,6 +3323,8 @@ void Checkbox(const char* label, bool* v)
g.ActiveId = 0; // Clear focus g.ActiveId = 0; // Clear focus
} }
RenderFrame(check_bb.Min, check_bb.Max, window->Color(hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg));
if (*v) if (*v)
{ {
window->DrawList->AddRectFilled(check_bb.Min+ImVec2(4,4), check_bb.Max-ImVec2(4,4), window->Color(ImGuiCol_CheckActive)); window->DrawList->AddRectFilled(check_bb.Min+ImVec2(4,4), check_bb.Max-ImVec2(4,4), window->Color(ImGuiCol_CheckActive));
@ -3360,7 +3364,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); 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())); 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; return false;
ImVec2 center = check_bb.GetCenter(); ImVec2 center = check_bb.GetCenter();
@ -3368,12 +3374,12 @@ bool RadioButton(const char* label, bool active)
center.y = (float)(int)center.y + 0.5f; center.y = (float)(int)center.y + 0.5f;
const float radius = check_bb.GetHeight() * 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]; const bool pressed = hovered && g.IO.MouseClicked[0];
if (hovered) if (hovered)
g.HoveredId = id; g.HoveredId = id;
window->DrawList->AddCircleFilled(center, radius, window->Color(ImGuiCol_FrameBg), 16); window->DrawList->AddCircleFilled(center, radius, window->Color(hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg), 16);
if (active) if (active)
window->DrawList->AddCircleFilled(center, radius-2, window->Color(ImGuiCol_CheckActive), 16); window->DrawList->AddCircleFilled(center, radius-2, window->Color(ImGuiCol_CheckActive), 16);

View File

@ -302,6 +302,7 @@ enum ImGuiCol_
ImGuiCol_ScrollbarGrabHovered, ImGuiCol_ScrollbarGrabHovered,
ImGuiCol_ScrollbarGrabActive, ImGuiCol_ScrollbarGrabActive,
ImGuiCol_ComboBg, ImGuiCol_ComboBg,
ImGuiCol_CheckHovered,
ImGuiCol_CheckActive, ImGuiCol_CheckActive,
ImGuiCol_SliderGrab, ImGuiCol_SliderGrab,
ImGuiCol_SliderGrabActive, ImGuiCol_SliderGrabActive,