|
@@ -895,19 +895,11 @@ bool ImGui::Checkbox(const char* label, bool* v)
|
|
const ImGuiID id = window->GetID(label);
|
|
const ImGuiID id = window->GetID(label);
|
|
const ImVec2 label_size = CalcTextSize(label, NULL, true);
|
|
const ImVec2 label_size = CalcTextSize(label, NULL, true);
|
|
|
|
|
|
- const ImRect check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(label_size.y + style.FramePadding.y*2, label_size.y + style.FramePadding.y*2)); // We want a square shape to we use Y twice
|
|
|
|
- ItemSize(check_bb, style.FramePadding.y);
|
|
|
|
-
|
|
|
|
- ImRect total_bb = check_bb;
|
|
|
|
- if (label_size.x > 0)
|
|
|
|
- SameLine(0, style.ItemInnerSpacing.x);
|
|
|
|
- const ImRect text_bb(window->DC.CursorPos + ImVec2(0,style.FramePadding.y), window->DC.CursorPos + ImVec2(0,style.FramePadding.y) + label_size);
|
|
|
|
- if (label_size.x > 0)
|
|
|
|
- {
|
|
|
|
- ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()), style.FramePadding.y);
|
|
|
|
- total_bb = ImRect(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ const float square_sz = GetFrameHeight();
|
|
|
|
+ const ImVec2 pos = window->DC.CursorPos;
|
|
|
|
+ const ImRect check_bb(pos, pos + ImVec2(square_sz, square_sz));
|
|
|
|
+ const ImRect total_bb(pos, pos + ImVec2(square_sz + (label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f), label_size.y + style.FramePadding.y * 2.0f));
|
|
|
|
+ ItemSize(total_bb, style.FramePadding.y);
|
|
if (!ItemAdd(total_bb, id))
|
|
if (!ItemAdd(total_bb, id))
|
|
return false;
|
|
return false;
|
|
|
|
|
|
@@ -923,15 +915,14 @@ bool ImGui::Checkbox(const char* label, bool* v)
|
|
RenderFrame(check_bb.Min, check_bb.Max, GetColorU32((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), true, style.FrameRounding);
|
|
RenderFrame(check_bb.Min, check_bb.Max, GetColorU32((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), true, style.FrameRounding);
|
|
if (*v)
|
|
if (*v)
|
|
{
|
|
{
|
|
- const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight());
|
|
|
|
- const float pad = ImMax(1.0f, (float)(int)(check_sz / 6.0f));
|
|
|
|
- RenderCheckMark(check_bb.Min + ImVec2(pad,pad), GetColorU32(ImGuiCol_CheckMark), check_bb.GetWidth() - pad*2.0f);
|
|
|
|
|
|
+ const float pad = ImMax(1.0f, (float)(int)(square_sz / 6.0f));
|
|
|
|
+ RenderCheckMark(check_bb.Min + ImVec2(pad, pad), GetColorU32(ImGuiCol_CheckMark), square_sz - pad*2.0f);
|
|
}
|
|
}
|
|
|
|
|
|
if (g.LogEnabled)
|
|
if (g.LogEnabled)
|
|
- LogRenderedText(&text_bb.Min, *v ? "[x]" : "[ ]");
|
|
|
|
|
|
+ LogRenderedText(&total_bb.Min, *v ? "[x]" : "[ ]");
|
|
if (label_size.x > 0.0f)
|
|
if (label_size.x > 0.0f)
|
|
- RenderText(text_bb.Min, label);
|
|
|
|
|
|
+ RenderText(ImVec2(check_bb.Max.x + style.ItemInnerSpacing.x, check_bb.Min.y + style.FramePadding.y), label);
|
|
|
|
|
|
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.ItemFlags | ImGuiItemStatusFlags_Checkable | (*v ? ImGuiItemStatusFlags_Checked : 0));
|
|
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.ItemFlags | ImGuiItemStatusFlags_Checkable | (*v ? ImGuiItemStatusFlags_Checked : 0));
|
|
return pressed;
|
|
return pressed;
|
|
@@ -963,26 +954,18 @@ bool ImGui::RadioButton(const char* label, bool active)
|
|
const ImGuiID id = window->GetID(label);
|
|
const ImGuiID id = window->GetID(label);
|
|
const ImVec2 label_size = CalcTextSize(label, NULL, true);
|
|
const ImVec2 label_size = CalcTextSize(label, NULL, true);
|
|
|
|
|
|
- const ImRect check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(label_size.y + style.FramePadding.y*2-1, label_size.y + style.FramePadding.y*2-1));
|
|
|
|
- ItemSize(check_bb, style.FramePadding.y);
|
|
|
|
-
|
|
|
|
- ImRect total_bb = check_bb;
|
|
|
|
- if (label_size.x > 0)
|
|
|
|
- SameLine(0, style.ItemInnerSpacing.x);
|
|
|
|
- const ImRect text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + label_size);
|
|
|
|
- if (label_size.x > 0)
|
|
|
|
- {
|
|
|
|
- ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()), style.FramePadding.y);
|
|
|
|
- total_bb.Add(text_bb);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ const float square_sz = GetFrameHeight();
|
|
|
|
+ const ImVec2 pos = window->DC.CursorPos;
|
|
|
|
+ const ImRect check_bb(pos, pos + ImVec2(square_sz, square_sz));
|
|
|
|
+ const ImRect total_bb(pos, pos + ImVec2(square_sz + (label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f), label_size.y + style.FramePadding.y * 2.0f));
|
|
|
|
+ ItemSize(total_bb, style.FramePadding.y);
|
|
if (!ItemAdd(total_bb, id))
|
|
if (!ItemAdd(total_bb, id))
|
|
return false;
|
|
return false;
|
|
|
|
|
|
ImVec2 center = check_bb.GetCenter();
|
|
ImVec2 center = check_bb.GetCenter();
|
|
center.x = (float)(int)center.x + 0.5f;
|
|
center.x = (float)(int)center.x + 0.5f;
|
|
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 = (square_sz - 1.0f) * 0.5f;
|
|
|
|
|
|
bool hovered, held;
|
|
bool hovered, held;
|
|
bool pressed = ButtonBehavior(total_bb, id, &hovered, &held);
|
|
bool pressed = ButtonBehavior(total_bb, id, &hovered, &held);
|
|
@@ -993,21 +976,20 @@ bool ImGui::RadioButton(const char* label, bool active)
|
|
window->DrawList->AddCircleFilled(center, radius, GetColorU32((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), 16);
|
|
window->DrawList->AddCircleFilled(center, radius, GetColorU32((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), 16);
|
|
if (active)
|
|
if (active)
|
|
{
|
|
{
|
|
- const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight());
|
|
|
|
- const float pad = ImMax(1.0f, (float)(int)(check_sz / 6.0f));
|
|
|
|
- window->DrawList->AddCircleFilled(center, radius-pad, GetColorU32(ImGuiCol_CheckMark), 16);
|
|
|
|
|
|
+ const float pad = ImMax(1.0f, (float)(int)(square_sz / 6.0f));
|
|
|
|
+ window->DrawList->AddCircleFilled(center, radius - pad, GetColorU32(ImGuiCol_CheckMark), 16);
|
|
}
|
|
}
|
|
|
|
|
|
if (style.FrameBorderSize > 0.0f)
|
|
if (style.FrameBorderSize > 0.0f)
|
|
{
|
|
{
|
|
- window->DrawList->AddCircle(center+ImVec2(1,1), radius, GetColorU32(ImGuiCol_BorderShadow), 16, style.FrameBorderSize);
|
|
|
|
|
|
+ window->DrawList->AddCircle(center + ImVec2(1,1), radius, GetColorU32(ImGuiCol_BorderShadow), 16, style.FrameBorderSize);
|
|
window->DrawList->AddCircle(center, radius, GetColorU32(ImGuiCol_Border), 16, style.FrameBorderSize);
|
|
window->DrawList->AddCircle(center, radius, GetColorU32(ImGuiCol_Border), 16, style.FrameBorderSize);
|
|
}
|
|
}
|
|
|
|
|
|
if (g.LogEnabled)
|
|
if (g.LogEnabled)
|
|
- LogRenderedText(&text_bb.Min, active ? "(x)" : "( )");
|
|
|
|
|
|
+ LogRenderedText(&total_bb.Min, active ? "(x)" : "( )");
|
|
if (label_size.x > 0.0f)
|
|
if (label_size.x > 0.0f)
|
|
- RenderText(text_bb.Min, label);
|
|
|
|
|
|
+ RenderText(ImVec2(check_bb.Max.x + style.ItemInnerSpacing.x, check_bb.Min.y + style.FramePadding.y), label);
|
|
|
|
|
|
return pressed;
|
|
return pressed;
|
|
}
|
|
}
|