//simplicity checkboxes
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 ImVec2 label_size = CalcTextSize(label, NULL, true);
static std::map<ImGuiID, float> anim2;
auto checkalpha2 = anim2.find(id);
if (checkalpha2 == anim2.end())
{
anim2.insert({ id, 50.f });
checkalpha2 = anim2.find(id);
}
static std::map<ImGuiID, float> anim;
auto checkalpha = anim.find(id);
if (checkalpha == anim.end())
{
anim.insert({ id, 0.f });
checkalpha = anim.find(id);
}
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));
ItemSize(total_bb, style.FramePadding.y);
if (!ItemAdd(total_bb, id))
return false;
bool hovered, held;
bool pressed = ButtonBehavior(total_bb, id, &hovered, &held);
if (pressed)
{
*v = !(*v);
MarkItemEdited(id);
}
const ImRect check_bb(pos, pos + ImVec2(square_sz, square_sz));
RenderNavHighlight(total_bb, id);
window->DrawList->AddRectFilled(check_bb.Min - ImVec2(3, 3), check_bb.Max + ImVec2(3, 3), ImColor(16, 16, 19), 4, 15);
window->DrawList->AddRect(check_bb.Min - ImVec2(3, 3), check_bb.Max + ImVec2(3, 3), ImColor(41, 41, 50), 4, 15, 2);
ImU32 check_col = GetColorU32(ImGuiCol_CheckMark);
if (window->DC.ItemFlags & ImGuiItemFlags_MixedValue)
{
// Undocumented tristate/mixed/indeterminate checkbox (#2644)
ImVec2 pad(ImMax(1.0f, IM_FLOOR(square_sz / 3.6f)), ImMax(1.0f, IM_FLOOR(square_sz / 3.6f)));
window->DrawList->AddRectFilled(check_bb.Min + pad, check_bb.Max - pad, check_col, style.FrameRounding);
}
else if (*v)
{
if (checkalpha->second < 255)
checkalpha->second += animspeed;
if (checkalpha2->second < 255)
checkalpha2->second += animspeed2;
const float pad = ImMax(1.0f, IM_FLOOR(square_sz / 6.0f));
}
else {
if (checkalpha->second > 0)
checkalpha->second -= animspeed;
}
window->DrawList->AddRectFilled(check_bb.Min - ImVec2(3, 3), check_bb.Max + ImVec2(3, 3), ImColor(40, 38, 48, (int)checkalpha->second), 4, 15);
window->DrawList->AddRectFilled(check_bb.Min + ImVec2(1.5, 1.5), check_bb.Max - ImVec2(1.5, 1.5), ImColor(94, 69, 216, (int)checkalpha->second), 3.5);
if (g.LogEnabled)
LogRenderedText(&total_bb.Min, *v ? "[x]" : "[ ]");
ImGui::PushStyleColor(ImGuiCol_Text, rgb_to_imvec(255, 255, 255, (int)checkalpha2->second));
if (ImGui::IsItemHovered()) {
if (checkalpha2->second < 255)
checkalpha2->second += animspeed2;
}
else {
if (checkalpha2->second > 50)
checkalpha2->second -= animspeed2;
}
window->DrawList->AddRect(check_bb.Min - ImVec2(3, 3), check_bb.Max + ImVec2(3, 3), ImColor(73, 70, 88, (int)checkalpha2->second), 4, 15, 2);
RenderText(ImVec2(check_bb.Max.x + 12, check_bb.Min.y + 1), label);
ImGui::PopStyleColor();
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.ItemFlags | ImGuiItemStatusFlags_Checkable | (*v ? ImGuiItemStatusFlags_Checked : 0));
return pressed;
}