imgui icon indicating copy to clipboard operation
imgui copied to clipboard

Add small checkboxes

Open KellanClark opened this issue 2 years ago • 1 comments

I recently ran into a use case where I wanted a checkbox, but the vertical size needed messed with the space between lines. I looked around the demo and found ImGui::SmallButton() covered a similar case, so I reused its code to make a smaller checkbox.

My usecase in a very WIP debugger window showing what a SmallCheckbox() looks like compared to a Checkbox(). Screenshot 2023-06-16 183041

In the middle of text as shown in the demo window. Screenshot 2023-06-16 184127

I understand if the need for this is too rare to justify a new widget and PR. Feel free to reject it.

KellanClark avatar Jun 16 '23 22:06 KellanClark

Hello Kellan,

Thanks for the PR. Although this is no doubt useful, presently I would prefer to avoid adding those variants as they tend to easily multiply.

Note that the API design using a namespace means you can add this function (with same ImGui::SmallCheckbox() name) in your own source file so presently given the low complexity of that function I'd recommend people to do that.

One small tangential thing is that I've been considering adding X/Y variant of style variables, e.g. ImGuiStyleVar_FramePaddingY so people inclined to use public Push/Pop API can perform an Y only override more easily. (Practically speaking, I do prefer the approach of backuping old value on the stack as this tends to be simpler and faster when done in a helper function like this).

Good luck on the emulators :)

ocornut avatar Jun 19 '23 08:06 ocornut

Closing this as discussed. Note that since bf75504 i have added PushStyleVarX(), PushStyleVarY() helpers to make it even to modify a single component of a style variable. So this becomes equivalent to doing:

PushStyleVarY(ImGuiStyleVar_FramePadding, 0.0f);
CheckBox(...);
PopStyleVar();

And I don't believe needs its own entry point. Thanks for the suggestion!

ocornut avatar Aug 23 '24 12:08 ocornut