Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color too dark custom checkbox color fill #7603

Closed
Raplhs opened this issue May 18, 2024 · 3 comments
Closed

Color too dark custom checkbox color fill #7603

Raplhs opened this issue May 18, 2024 · 3 comments

Comments

@Raplhs
Copy link

Raplhs commented May 18, 2024

Version/Branch of Dear ImGui:

Version 1.96, Branch: master

Back-ends:

imgui_widgets.cpp

Compiler, OS:

Windows 10

Full config/build information:

No response

Details:

My issue:
I have a custom filled checkbox instead of default, it fills with a color when clicked.

However the color I defined is clearly green, but when I compile and click the box, it is more DARK green.
I don't know if this can be changed, or imgui colors have to be improved.

Please if there is a better option to make this checkbox the real proper green and not dark green, tell me.

Screenshots/Video:

dark green problem
clicked1

the value I defined
gren color

the real color brightness of the value
real gren

Minimal, Complete and Verifiable Example code:

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.5f; // Half the usual size
    const float vertical_alignment = (label_size.y - square_sz) * 0.5f; // Calculate alignment to center checkbox with text
    const ImVec2 pos = window->DC.CursorPos + ImVec2(0, vertical_alignment); // Adjust position for vertical alignment
    const ImRect total_bb(pos, pos + ImVec2(square_sz + style.ItemInnerSpacing.x + label_size.x, label_size.y + style.FramePadding.y * 2.0f)); // Adjusted size for proper alignment
    ItemSize(total_bb, style.FramePadding.y);
    if (!ItemAdd(total_bb, id))
    {
        IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags | ImGuiItemStatusFlags_Checkable | (*v ? ImGuiItemStatusFlags_Checked : 0));
        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);
    ImU32 check_col = *v ? IM_COL32(0, 255, 0, 255) : IM_COL32(0, 0, 0, 0); // Brightest red color
    window->DrawList->AddRectFilled(check_bb.Min, check_bb.Max, check_col, style.FrameRounding); // Fill the checkbox with color

    // Remove the conditional rendering based on hovered or held
    RenderFrame(check_bb.Min, check_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding);

    ImVec2 label_pos = ImVec2(check_bb.Max.x + style.ItemInnerSpacing.x, pos.y - vertical_alignment); // Adjusted position for vertical alignment
    if (g.LogEnabled)
        LogRenderedText(&label_pos, *v ? "[x]" : "[ ]");
    if (label_size.x > 0.0f)
        RenderText(label_pos, label);

    IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags | ImGuiItemStatusFlags_Checkable | (*v ? ImGuiItemStatusFlags_Checked : 0));
    return pressed;
}
@Raplhs
Copy link
Author

Raplhs commented May 18, 2024

if the green is not a good representation, here are some more screenshots for a bright pink, but comes out as purple.

coded rgb value
another value

the real color
the real color

the color on imgui
the problem

@ruby3141
Copy link

It seems you're drawing something over the color-filled rectangle.

// Remove the conditional rendering based on hovered or held
RenderFrame(check_bb.Min, check_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding);

Can you remove corresponding line and see if the color is still darker?

p.s. Imgui recommends not to use RenderFrame() on user code.

imgui/imgui_internal.h

Lines 3409 to 3417 in aa5a609

// Render helpers
// AVOID USING OUTSIDE OF IMGUI.CPP! NOT FOR PUBLIC CONSUMPTION. THOSE FUNCTIONS ARE A MESS. THEIR SIGNATURE AND BEHAVIOR WILL CHANGE, THEY NEED TO BE REFACTORED INTO SOMETHING DECENT.
// NB: All position are in absolute pixels coordinates (we are never using window coordinates internally)
IMGUI_API void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true);
IMGUI_API void RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width);
IMGUI_API void RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& align = ImVec2(0, 0), const ImRect* clip_rect = NULL);
IMGUI_API void RenderTextClippedEx(ImDrawList* draw_list, const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& align = ImVec2(0, 0), const ImRect* clip_rect = NULL);
IMGUI_API void RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, const ImVec2& pos_max, float clip_max_x, float ellipsis_max_x, const char* text, const char* text_end, const ImVec2* text_size_if_known);
IMGUI_API void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f);

@ocornut
Copy link
Owner

ocornut commented May 23, 2024

It seems you're drawing something over the color-filled rectangle.
RenderFrame(check_bb.Min, check_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding)

Correct, thanks for spotting that.

(also technically color space depends on your backend, swap-chain and other esoteric features that may be part of your app or driver so it's a wider issue and there's no such thing as a "real" color. But here your issue is clearly that you are drawing something over your color anyhow)

@ocornut ocornut closed this as completed May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants