Подпишитесь на наш Telegram-канал, чтобы всегда быть в курсе важных обновлений! Перейти

Вопрос Смена цвета чекбоксов

Начинающий
Начинающий
Статус
Оффлайн
Регистрация
31 Июл 2020
Сообщения
188
Реакции
15
Как поменять у этой штуки цвет?
Код:
Expand Collapse Copy
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(92 / 255.f, 0 / 255.f, 0 / 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 (*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));

    if (*v)
    {
        window->DrawList->AddRectFilled(ImVec2(check_bb.Min.x + 5, check_bb.Min.y + 5), ImVec2(check_bb.Max.x + 10, check_bb.Max.y), GetColorU32(ImVec4(90 / 255.f, 0 / 255.f, 0 / 255.f, it_filled->second)), 12.f * c_menu::get().dpi_scale);
        window->DrawList->AddCircleFilled(ImVec2(check_bb.Min.x + (check_bb.Max.x - check_bb.Min.x) / 2 + 15, check_bb.Min.y + 10), 11 * c_menu::get().dpi_scale, GetColorU32(ImVec4(90 / 255.f, 0 / 255.f, 0 / 255.f, 255.f)), 25 * c_menu::get().dpi_scale);
    }
    else {
        window->DrawList->AddRectFilled(ImVec2(check_bb.Min.x + 5, check_bb.Min.y + 5), ImVec2(check_bb.Max.x + 15, check_bb.Max.y), GetColorU32(ImGuiCol_ButtonActive), 12.f);
        window->DrawList->AddCircleFilled(ImVec2(check_bb.Min.x + (check_bb.Max.x - check_bb.Min.x) / 2 + 5, check_bb.Min.y + 10), 11 * c_menu::get().dpi_scale, GetColorU32(ImGuiCol_ButtonActive), 25 * 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 + 15, check_bb.Min.y + 3 * 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;
}

Я конечно не совсем отбитый (а может и совсем :roflanPominki: ), пытался поменять цвет тут
Код:
Expand Collapse Copy
  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(92 / 255.f, 0 / 255.f, 0 / 255.f, 1.f);
Но результатов это не принесло, сейчас они красные, кто сможет сделайте белые или скажите как поменять
 
and replace ImGuiCol_ButtonActive with the color you want or change it in imgui_draw.cpp
C++:
Expand Collapse Copy
    if (*v)
    {
        window->DrawList->AddRectFilled(ImVec2(check_bb.Min.x + 5, check_bb.Min.y + 5), ImVec2(check_bb.Max.x + 10, check_bb.Max.y), GetColorU32(ImVec4(90 / 255.f, 0 / 255.f, 0 / 255.f, it_filled->second)), 12.f * c_menu::get().dpi_scale);
        window->DrawList->AddCircleFilled(ImVec2(check_bb.Min.x + (check_bb.Max.x - check_bb.Min.x) / 2 + 15, check_bb.Min.y + 10), 11 * c_menu::get().dpi_scale, GetColorU32(ImVec4(90 / 255.f, 0 / 255.f, 0 / 255.f, 255.f)), 25 * c_menu::get().dpi_scale);
    }
    else {
        window->DrawList->AddRectFilled(ImVec2(check_bb.Min.x + 5, check_bb.Min.y + 5), ImVec2(check_bb.Max.x + 15, check_bb.Max.y), GetColorU32(ImGuiCol_ButtonActive), 12.f);
        window->DrawList->AddCircleFilled(ImVec2(check_bb.Min.x + (check_bb.Max.x - check_bb.Min.x) / 2 + 5, check_bb.Min.y + 10), 11 * c_menu::get().dpi_scale, GetColorU32(ImGuiCol_ButtonActive), 25 * c_menu::get().dpi_scale);
    }
the color you changed is for the animation :)
 
Как поменять у этой штуки цвет?
Код:
Expand Collapse Copy
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(92 / 255.f, 0 / 255.f, 0 / 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 (*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));

    if (*v)
    {
        window->DrawList->AddRectFilled(ImVec2(check_bb.Min.x + 5, check_bb.Min.y + 5), ImVec2(check_bb.Max.x + 10, check_bb.Max.y), GetColorU32(ImVec4(90 / 255.f, 0 / 255.f, 0 / 255.f, it_filled->second)), 12.f * c_menu::get().dpi_scale);
        window->DrawList->AddCircleFilled(ImVec2(check_bb.Min.x + (check_bb.Max.x - check_bb.Min.x) / 2 + 15, check_bb.Min.y + 10), 11 * c_menu::get().dpi_scale, GetColorU32(ImVec4(90 / 255.f, 0 / 255.f, 0 / 255.f, 255.f)), 25 * c_menu::get().dpi_scale);
    }
    else {
        window->DrawList->AddRectFilled(ImVec2(check_bb.Min.x + 5, check_bb.Min.y + 5), ImVec2(check_bb.Max.x + 15, check_bb.Max.y), GetColorU32(ImGuiCol_ButtonActive), 12.f);
        window->DrawList->AddCircleFilled(ImVec2(check_bb.Min.x + (check_bb.Max.x - check_bb.Min.x) / 2 + 5, check_bb.Min.y + 10), 11 * c_menu::get().dpi_scale, GetColorU32(ImGuiCol_ButtonActive), 25 * 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 + 15, check_bb.Min.y + 3 * 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;
}

Я конечно не совсем отбитый (а может и совсем :roflanPominki: ), пытался поменять цвет тут
Код:
Expand Collapse Copy
  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(92 / 255.f, 0 / 255.f, 0 / 255.f, 1.f);
Но результатов это не принесло, сейчас они красные, кто сможет сделайте белые или скажите как поменять
чел они и должны быть красные, ты правильно менял. 92 0 0 - красный ( r = 92, g = 0, b = 0 )
 
Назад
Сверху Снизу