bool ImGui::Checkbox(const char* label, bool* v)
{
ImGuiWindow* window = GetCurrentWindow();
if (window->SkipItems)
return false;
ImGuiContext& g = *GImGui;
const ImGuiStyle& style = g.Style;
const ImGuiID id = window->GetID(label);
const float w = ImGui::CalcItemWidth() + ImGui::CalcItemWidth() * 0.3f;
const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
const float square_sz = ImGui::GetFrameHeight();
const ImVec2 pos = window->DC.CursorPos;
const ImRect total_bb(pos, pos + ImVec2(square_sz + (label_size.x + label_size.x + 15), 15 + 0 + 0));
ItemSize(total_bb, style.FramePadding.y);
ItemAdd(total_bb, id);
bool hovered, held;
bool pressed = ButtonBehavior(total_bb, id, &hovered, &held);
if (hovered || held)
ImGui::SetMouseCursor(0);
if (pressed)
*v = !(*v);
static std::map<ImGuiID, float> filled_anim;
auto it_filled = filled_anim.find(id);
if (it_filled == filled_anim.end())
{
filled_anim.insert({ id, 1.f });
it_filled = filled_anim.find(id);
}
if (*v)
{
if (it_filled->second < 1.f)
it_filled->second += 0.1f;
}
else
{
if (it_filled->second > 0.f)
it_filled->second -= 0.1f;
}
window->DrawList->AddRectFilled(ImVec2(total_bb.Min.x + 0, total_bb.Min.y + 0), ImVec2(total_bb.Min.x + 15, total_bb.Min.y + 15), ImGui::GetColorU32(ImVec4(90 / 255.f, 90 / 255.f, 90 / 255.f, it_filled->second)), 3, 15);
ImGui::RenderCheckMark(window->DrawList, total_bb.Min + ImVec2(3, 1), ImColor(229 / 255.f, 229 / 255.f, 229 / 255.f, it_filled->second), 10);
window->DrawList->AddRect(ImVec2(total_bb.Min.x + 0, total_bb.Min.y + 0), ImVec2(total_bb.Min.x + 15, total_bb.Min.y + 15), ImColor(112, 112, 112, 255), 3, 15, 1.000000);
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(229 / 255.f, 229 / 255.f, 229 / 255.f, 255 / 255.f));
ImGui::RenderText(ImVec2(total_bb.Min.x + style.ItemInnerSpacing.x + 20, total_bb.Min.y + style.FramePadding.y - 0), label);
ImGui::PopStyleColor();
return pressed;
}