ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
61.07k stars 10.29k forks source link

How to set value to DragScalar if it stores some undefined value? #5518

Open DimaKoltun opened 2 years ago

DimaKoltun commented 2 years ago

Version/Branch of Dear ImGui:

Version: 1.88 Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_sdl.cpp + imgui_implopengl3.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();
ocornut commented 2 years ago

For "mixed value" display you can use this WIP feature

PushItemFlag(ImGuiItemFlags_MixedValue, true);
DragFloat(...)
PopItemFloat()
PathogenDavid commented 2 years ago

For "mixed value" display you can use this WIP feature

Isn't this feature currently restricted to checkboxes?

ocornut commented 2 years ago

Hmm you are right, it doesn’t look like I finished the equivalent code for Drag/Sliders.

theOtherMichael commented 2 years ago

Just came across this situation as well -- wanted to comment to indicate my interest in this.

rokups commented 2 years ago

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.

theOtherMichael commented 2 years ago

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.