Вопрос Checkbox - Чекбокс

Начинающий
Статус
Оффлайн
Регистрация
25 Май 2021
Сообщения
15
Реакции[?]
0
Поинты[?]
0
Помогите! Не могу понять в чём дело.
Прописываю сам чекбокс в меню(Типо новую функцию)
Создаётся только сам чекбокс, но только без текста.

Код:
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);

    const float square_sz = GetFrameHeight() * 0.7f;
    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;

    float deltatime = 1.5f * ImGui::GetIO().DeltaTime;

    bool hovered, held;
    bool pressed = ButtonBehavior(total_bb, id, &hovered, &held);
    if (pressed)
    {
        *v = !(*v);
        MarkItemEdited(id);
    }

    static std::map<ImGuiID, float> hover_animation;
    auto it_hover = hover_animation.find(id);
    if (it_hover == hover_animation.end())
    {
        hover_animation.insert({ id, 0.f });
        it_hover = hover_animation.find(id);
    }
    if (*v)
        it_hover->second = math::clamp(it_hover->second + (3.f * ImGui::GetIO().DeltaTime * (hovered ? 1.f : -1.f)), 0.0f, 1.f);
    else
        it_hover->second = math::clamp(it_hover->second + (3.f * ImGui::GetIO().DeltaTime), 0.0f, 1.f);

    const ImVec4 text_dis = style.Colors[ImGuiCol_Text];
    const ImVec4 text_act = ImVec4(244 / 255.f, 244 / 255.f, 244 / 255.f, 1.f);

    const ImVec4 hover_act = ImVec4(202 / 255.f, 202 / 255.f, 202 / 255.f, 1.f);
    const ImVec4 hover_dis = ImVec4(126 / 255.f, 131 / 255.f, 219 / 255.f, 1.f);

    static std::map<ImGuiID, ImVec4> hover_color;
    auto it_hcolor = hover_color.find(id);
    if (it_hcolor == hover_color.end())
    {
        hover_color.insert({ id, hover_dis });
        it_hcolor = hover_color.find(id);
    }
    if (*v)
    {
        ImVec4 to = hover_dis;
        if (it_hcolor->second.x != to.x)
        {
            if (it_hcolor->second.x < to.x)
                it_hcolor->second.x = ImMin(it_hcolor->second.x + deltatime, to.x);
            else if (it_hcolor->second.x > to.x)
                it_hcolor->second.x = ImMax(to.x, it_hcolor->second.x - deltatime);
        }

        if (it_hcolor->second.y != to.y)
        {
            if (it_hcolor->second.y < to.y)
                it_hcolor->second.y = ImMin(it_hcolor->second.y + deltatime, to.y);
            else if (it_hcolor->second.y > to.y)
                it_hcolor->second.y = ImMax(to.y, it_hcolor->second.y - deltatime);
        }

        if (it_hcolor->second.z != to.z)
        {
            if (it_hcolor->second.z < to.z)
                it_hcolor->second.z = ImMin(it_hcolor->second.z + deltatime, to.z);
            else if (it_hcolor->second.z > to.z)
                it_hcolor->second.z = ImMax(to.z, it_hcolor->second.z - deltatime);
        }
    }
    else
    {
        ImVec4 to = hovered ? hover_dis : hover_act;
        if (it_hcolor->second.x != to.x)
        {
            if (it_hcolor->second.x < to.x)
                it_hcolor->second.x = ImMin(it_hcolor->second.x + deltatime, to.x);
            else if (it_hcolor->second.x > to.x)
                it_hcolor->second.x = ImMax(to.x, it_hcolor->second.x - deltatime);
        }

        if (it_hcolor->second.y != to.y)
        {
            if (it_hcolor->second.y < to.y)
                it_hcolor->second.y = ImMin(it_hcolor->second.y + deltatime, to.y);
            else if (it_hcolor->second.y > to.y)
                it_hcolor->second.y = ImMax(to.y, it_hcolor->second.y - deltatime);
        }

        if (it_hcolor->second.z != to.z)
        {
            if (it_hcolor->second.z < to.z)
                it_hcolor->second.z = ImMin(it_hcolor->second.z + deltatime, to.z);
            else if (it_hcolor->second.z > to.z)
                it_hcolor->second.z = ImMax(to.z, it_hcolor->second.z - deltatime);
        }
    }

    static std::map<ImGuiID, ImVec4> text_animation;
    auto it_text = text_animation.find(id);
    if (it_text == text_animation.end())
    {
        text_animation.insert({ id, text_dis });
        it_text = text_animation.find(id);
    }
    if (*v)
    {
        ImVec4 to = hovered ? text_dis : text_act;
        if (it_text->second.x != to.x)
        {
            if (it_text->second.x < to.x)
                it_text->second.x = ImMin(it_text->second.x + deltatime, to.x);
            else if (it_text->second.x > to.x)
                it_text->second.x = ImMax(to.x, it_text->second.x - deltatime);
        }

        if (it_text->second.y != to.y)
        {
            if (it_text->second.y < to.y)
                it_text->second.y = ImMin(it_text->second.y + deltatime, to.y);
            else if (it_text->second.y > to.y)
                it_text->second.y = ImMax(to.y, it_text->second.y - deltatime);
        }

        if (it_text->second.z != to.z)
        {
            if (it_text->second.z < to.z)
                it_text->second.z = ImMin(it_text->second.z + deltatime, to.z);
            else if (it_text->second.z > to.z)
                it_text->second.z = ImMax(to.z, it_text->second.z - deltatime);
        }
    }
    else
    {
        ImVec4 to = text_dis;
        if (it_text->second.x != to.x)
        {
            if (it_text->second.x < to.x)
                it_text->second.x = ImMin(it_text->second.x + deltatime, to.x);
            else if (it_text->second.x > to.x)
                it_text->second.x = ImMax(to.x, it_text->second.x - deltatime);
        }

        if (it_text->second.y != to.y)
        {
            if (it_text->second.y < to.y)
                it_text->second.y = ImMin(it_text->second.y + deltatime, to.y);
            else if (it_text->second.y > to.y)
                it_text->second.y = ImMax(to.y, it_text->second.y - deltatime);
        }

        if (it_text->second.z != to.z)
        {
            if (it_text->second.z < to.z)
                it_text->second.z = ImMin(it_text->second.z + deltatime, to.z);
            else if (it_text->second.z > to.z)
                it_text->second.z = ImMax(to.z, it_text->second.z - deltatime);
        }
    }

    static std::map<ImGuiID, float> filled_animation;
    auto it_filled = filled_animation.find(id);
    if (it_filled == filled_animation.end())
    {
        filled_animation.insert({ id, 0.f });
        it_filled = filled_animation.find(id);
    }
    if (hovered && *v && it_filled->second >= 0.5f)
        it_filled->second = math::clamp(it_filled->second - 2.2f * ImGui::GetIO().DeltaTime, 0.5f, 1.f);
    else
        it_filled->second = math::clamp(it_filled->second + (2.2f * ImGui::GetIO().DeltaTime * ((*v) ? 1.f : -1.f)), 0.0f, 1.f);

    const ImRect check_bb(pos, pos + ImVec2(square_sz, square_sz));

    window->DrawList->AddRect(check_bb.Min, check_bb.Max, GetColorU32(ImVec4(it_hcolor->second.x, it_hcolor->second.y, it_hcolor->second.z, it_hover->second)), 2.f * c_menu::get().dpi_scale, 15, 0.7f);

    window->DrawList->AddRectFilled(check_bb.Min, check_bb.Max, GetColorU32(ImVec4(126 / 255.f, 131 / 255.f, 219 / 255.f, it_filled->second)), 2.f * c_menu::get().dpi_scale);


    ImGui::PushStyleColor(ImGuiCol_Text, it_text->second);

    if (label_size.x > 0.0f)
        RenderText(ImVec2(check_bb.Max.x + style.ItemInnerSpacing.x, check_bb.Min.y + 2 * c_menu::get().dpi_scale - (1 * (1.8 - c_menu::get().dpi_scale))), label);

    ImGui::PopStyleColor();

    if (g_cfg.scripts.developer_mode && ImGui::IsItemHovered())
    {
        for (auto& item : cfg_manager->items)
        {
            if (v == item->pointer)
            {
                ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(8.0f, 6.0f));
                ImGui::SetTooltip(item->name.c_str());
                ImGui::PopStyleVar();
                break;
            }
        }
    }

    IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.ItemFlags | ImGuiItemStatusFlags_Checkable | (*v ? ImGuiItemStatusFlags_Checked : 0));
    return pressed;
}
 
Сверху Снизу