bool ImGui::Checkbox(const char* label, bool *v)
{
ImVec2 p = ImGui::GetCursorScreenPos();
ImDrawList* draw_list = ImGui::GetWindowDrawList();
float height = ImGui::GetFrameHeight();
float width = ImGui::GetFrameHeight();
ImGui::InvisibleButton(label, ImVec2(width, height));
if (ImGui::IsItemClicked())
*v = !*v;
ImGuiContext& g = *GImGui;
const ImGuiStyle& style = g.Style;
ImGuiWindow* window = ImGui::GetCurrentWindow();
const ImGuiID id = window->GetID(label);
const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
const float square_sz = GetFrameHeight();
const ImVec2 pos = window->DC.CursorPos;
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));
if (!ItemAdd(total_bb, id))
return false;
const ImRect check_bb(pos, pos + ImVec2(square_sz, square_sz));
float t = *v ? 1.0f : 0.0f;
float ANIM_SPEED = 0.30f;
if (g.LastActiveId == g.CurrentWindow->GetID(label))
{
float t_anim = ImSaturate(g.LastActiveIdTimer / ANIM_SPEED);
t = *v ? (t_anim) : (1.0f - t_anim);
}
ImU32 col_bg;
ImU32 checkbg;
ImU32 xbg;
if (ImGui::IsItemHovered())
{
col_bg = ImGui::GetColorU32(ImLerp(ImVec4(0.00f, 0.00f, 0.00f, 1.0f), ImVec4(0.00f, 0.00f, 0.00f, 1.0f), t));
checkbg = ImGui::GetColorU32(ImLerp(ImVec4(0.56f, 0.83f, 0.26f, 0.0f), ImVec4(0.56f, 0.83f, 0.26f, 1.0f), t));
xbg = ImGui::GetColorU32(ImLerp(ImVec4(0.83f, 0.26f, 0.26f, 1.0f), ImVec4(0.56f, 0.83f, 0.26f, 0.0f), t));
}
else
{
col_bg = ImGui::GetColorU32(ImLerp(ImVec4(0.00f, 0.00f, 0.00f, 1.0f), ImVec4(0.00f , 0.00f , 0.00f , 1.00f), t));
checkbg = ImGui::GetColorU32(ImLerp(ImVec4(0.56f, 0.83f, 0.26f, 0.0f), ImVec4(0.56f, 0.83f, 0.26f, 1.0f), t));
xbg = ImGui::GetColorU32(ImLerp(ImVec4(0.83f, 0.26f, 0.26f, 1.0f), ImVec4(0.56f, 0.83f, 0.26f, 0.0f), t));
}
ImVec2 center = check_bb.GetCenter();
center.x = (float)(int)center.x + 0.5f;
center.y = (float)(int)center.y + 0.5f;
const float radius = (square_sz - 1.0f) * 0.5f;
const float pad = ImMax(1.0f, (float)(int)(square_sz / 6.0f));
draw_list->AddRectFilled(p, ImVec2(p.x + width, p.y + height), col_bg, 5);
RenderCheckMark(ImVec2((p.x + width) - 16, (p.y + height) - 16), checkbg, square_sz - pad * 2.0f);
const ImRect bb(p, p + ImVec2(g.FontSize, g.FontSize) + g.Style.FramePadding * 2.0f);
ImVec2 centers = bb.GetCenter();
float cross_extent = g.FontSize * 0.6f * 0.7071f - 1.0f;
centers -= ImVec2(1.5f, 0.2f);
window->DrawList->AddLine(centers + ImVec2(+cross_extent, +cross_extent), centers + ImVec2(-cross_extent, -cross_extent), xbg, 2.0f);
window->DrawList->AddLine(centers + ImVec2(+cross_extent, -cross_extent), centers + ImVec2(-cross_extent, +cross_extent), xbg, 2.0f);
if (label_size.x > 0.0f)
{
RenderText(ImVec2((p.x + width) + 7, (p.y + height) - 16), label);
}
return false;
}