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

Support for a real Checkmark in the Checkbox? #593

Closed
volcoma opened this issue Apr 16, 2016 · 6 comments
Closed

Support for a real Checkmark in the Checkbox? #593

volcoma opened this issue Apr 16, 2016 · 6 comments

Comments

@volcoma
Copy link

volcoma commented Apr 16, 2016

I was wondering if an actual checkmark will be added to the checkbox? Is there a reason it was not added in the first place? Its pretty easy to do so. Here is an example code that replaces the exsisting part in the code

if (*v)
    {
        const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight());
        const float pad = ImMax(1.0f, (float)(int)(check_sz / 6.0f));
        //window->DrawList->AddRectFilled(check_bb.Min+ImVec2(pad,pad), check_bb.Max-ImVec2(pad,pad), GetColorU32(ImGuiCol_CheckMark), style.FrameRounding);
        const ImRect check_mark_bb(check_bb.Min + ImVec2(pad, pad), check_bb.Max - ImVec2(pad, pad));
        const ImVec2 poitns[3] = { ImVec2(check_mark_bb.GetCenter().x - check_mark_bb.GetWidth()/2, check_mark_bb.GetCenter().y), ImVec2(check_mark_bb.GetCenter().x, check_mark_bb.GetCenter().y + check_mark_bb.GetHeight() / 2), ImVec2(check_mark_bb.GetTR()) };
        window->DrawList->AddPolyline(poitns, 3, GetColorU32(ImGuiCol_CheckMark), false, 3.0f, true);
    }

And here is how it looks:
checkmark

@ratchetfreak
Copy link

FYI if you use 3 "`" you can keep the formatting:

if (*v) { 
    const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight()); 
    const float pad = ImMax(1.0f, (float)(int)(check_sz / 6.0f)); 
    //window->DrawList->AddRectFilled(check_bb.Min+ImVec2(pad,pad), check_bb.Max-ImVec2(pad,pad), GetColorU32(ImGuiCol_CheckMark), style.FrameRounding); 
    const ImRect check_mark_bb(check_bb.Min + ImVec2(pad, pad), check_bb.Max - ImVec2(pad, pad)); 
    const ImVec2 poitns[3] = { ImVec2(check_mark_bb.GetCenter().x - check_mark_bb.GetWidth()/2, check_mark_bb.GetCenter().y), ImVec2(check_mark_bb.GetCenter().x, check_mark_bb.GetCenter().y + check_mark_bb.GetHeight() / 2), ImVec2(check_mark_bb.GetTR()) }; 
    window->DrawList->AddPolyline(poitns, 3, GetColorU32(ImGuiCol_CheckMark), false, 3.0f, true);
}

You can even set it to add higlighting by adding the language

@ocornut
Copy link
Owner

ocornut commented Apr 17, 2016

I didn't have thick polyline with proper connections back then.
The other reason is that I didn't want 1-pixel thin shapes that looked like fonts but when wouldn't match variety of fonts. So I went for a square.

There's still a bug with thick polyline normal merging in the non-antialiased path which would need to be fixed before we can use that (see it here: #288 (comment) )

Ideally we'd want a) a symbol library b) those would rasterized in the font atlas so they would cost 2 triangles, same principle would apply for rounded corners which is the primary reason for rasterizing stuff into the atlas. Of course we don't need to do any of that to add that check symbol, just need to fix the non-AA path to match the normal merging of the AA-path.

@ocornut
Copy link
Owner

ocornut commented Apr 17, 2016

You can see the bug easily in the Custom Rendering demo if you disable anti-aliasing:
capture

@dougbinks
Copy link
Contributor

FYI if you're prepared to load a font like Font Awesome you can use the CheckBoxTick from this gist: https://gist.github.com/dougbinks/8089b4bbaccaaf6fa204236978d165a9

@franciscod
Copy link
Contributor

This is already merged on bf778eb -- unless I'm missing something of course :)

@ocornut
Copy link
Owner

ocornut commented Nov 20, 2017

Correct, it's now in imgui (with the exact issue I described if anti-aliasing is disabled, need to fix the non-AA path). I'll close this issue as it is in the TODO to fix them and notably RenderCheckmark().

Down the line, the imgui_internal.h functions such as RenderCheckMark(), RenderTriangle(dir), RenderBullet() should be refactored as e.g. RenderSymbol(enum). Would like to see how we could leverage the recent CustomRect API of ImFontAtlas to have an already-rasterized path for them too.

@ocornut ocornut closed this as completed Nov 20, 2017
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

5 participants