imgui
imgui copied to clipboard
How to set value to DragScalar if it stores some undefined value?
Version/Branch of Dear ImGui:
Version: 1.88 Branch: docking
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_sdl.cpp + imgui_impl_opengl3.cpp (or specify if using a custom engine/back-end) Compiler: XXX (if the question is related to building or platform specific features) Operating System: Windows
My Issue/Question:
I have case, when i want to merge values in control (DragScalar, Slider), if all values is equal i show this value in control, otherwise show "-" that mean that value is mixed. When value is mixed i pass 0 as value to control and pass "-" as format to show it in control. Now we can set any value(through ctrl+click) except 0, because ImGui::TempInputScalar don't set value it it the same. How can i set 0 in this case?
Standalone, minimal, complete and verifiable example: (see https://github.com/ocornut/imgui/issues/2261)
static bool s_mixed = true;
static float s_value = 0.f;
ImGui::Begin("##Window");
if (ImGui::DragFloat("slider", &s_value, 1.f, 0.f, 0.f, s_mixed ? "-" : "%.3f"))
{
s_mixed = false;
}
ImGui::End();
For "mixed value" display you can use this WIP feature
PushItemFlag(ImGuiItemFlags_MixedValue, true);
DragFloat(...)
PopItemFloat()
For "mixed value" display you can use this WIP feature
Isn't this feature currently restricted to checkboxes?
Hmm you are right, it doesn’t look like I finished the equivalent code for Drag/Sliders.
Just came across this situation as well -- wanted to comment to indicate my interest in this.
How can i set 0 in this case?
Do not use 0 for undefined values. In case of floats you can use FLT_MAX
or INFINITY
. In case of integers you can use INT_MAX
(more relevant macros here). It is not ideal, but value like INT_MAX
should be much less commonly used than 0 and thus acceptable workaround for now.
I've made a PR implementing ImGuiItemFlags_MixedValue for DragScalars: https://github.com/ocornut/imgui/pull/5677 It's for the master branch, but the change is simple enough to bring into Docking.