mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-01 05:10:41 +00:00
Checkbox widget replacement with better look #3351
Labels
No labels
accidentally closed
android
backends
bug
building
clipper
coloredit
color spaces
cplusplus
data types
demo
disabled
doc
docking
dpi
drag drop
drawing/drawlist
dropped
dx12
enhancement
focus
font/text
gallery
help wanted
idle/power saving
ime
in progress
inputs
inputtext
internals
label/id and id stack
language bindings
layout
linux/bsd
menus
multi-contexts
multi-threading
multi-viewports
nav
news/info
opengl
optimization
osx/ios
overlap
plot/graph
popups
question
scrolling
selection
settings
sliders/drags
style
tables/columns
tabs
test wanted
tools
tooltips
tree
tricks & tips
useful widgets
vulkan
web
window pos/depth
window sizing
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ocornut/imgui#3351
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Version/Branch of Dear ImGui:
Version: 1.78 WIP
Branch: master
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_dx11.cpp
Compiler: MSVC 2019
Operating System: Win10
My Issue/Question:
This is my replacement for built-in checkbox widget. Tri-state is supported. Color is taken from ImGuiCol_Text, with border alpha dimmed down when not hovered.
Screenshots/Video

Standalone, minimal, complete and verifiable example:
Hello @mrduda,
Thanks for submitting this.
You should be able to achieve a similar look by altering border color, frame color, checkmark colors:
(the checkmark shape is a little different, and sorry for blurry upscaled capture)
The aim of styling v2 will be to provide finer control per-widget style so this would be easier to alter the look of this while keeping a different look for other widgets.
Suggestions of things in your code in your widgets can could improved:
#is incorrect and unnecessary. You can call ImGui::RenderText() which will callFindRenderedTextEnd()to do the same in a more correct way.IsItemXXX()function won't be honored on your custom Checkbox.Modelling your code after
Checkbox()would be preferable and will fix all those issues.Thank you for feedback!
The main reason behind this custom checkbox implementation was the size of original checkbox, which can't be decreased in any known way. The rest (color and border) is just a minor issue.
You can modify checkbox size by adjusting style (
ItemInnerSpacing,FramePadding) and font size. Seeocornut/imgui@ab4ef822f0/imgui_widgets.cpp (L1044)Here's another approach, this time I took existing Checkbox() code and modified it only in size, style/color and checkmark parts:
As for ItemInnerSpacing, FramePadding and font size suggestion: have you tried this and it worked, or is it only a guess? I'm not sure it will work as expected because changing font size may result in the incorrect text size calculation for checkbox label.
You should be using
PushStyleVar()/PopStyleVar()orPushStyleColor()/PopStyleColor()instead of copying entire widget code and modifying those values.As I said before, wrapping ImGui::Checkbox() into Push/PopStyleVar/Color doesn't help to achieve desired checkbox size. The method you have shown (by changing font size and other) does not work. Also, checkmark is custom and the color for checkbox border when mouse is over cannot be changed by Push/Pop calls. Anyway, thanks for attention.