ocornut / imgui

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

How to use Slider1 to set value1 and Slider2 to set value2, then Slider3(label, &value, value1, value2, format) #8120

Closed GrouchoChaplin closed 2 hours ago

GrouchoChaplin commented 2 hours ago

Version/Branch of Dear ImGui:

Version 1.62

Back-ends:

imgui_impl_opengl3.cpp

Compiler, OS:

Linux GCC 4.8.5

Full config/build information:

Custom, compiled by our project

Details:

My Issue/Question:

I want to create a SliderFloat, where the min and max values are set by other slider floats. Is this possible? Advisable? Is there a better way? I thought maybe just input the end min/max using input widgets but using sliders allow me to see the resulting effects on my scene in realtime.

So what I think I could do is something like this:


float minMin = 1.0;
float maxMin = 10.0;
float minValue = 1.0;
SliderFloat("MinValue", &minValue, minMin, maxMin, format = "%.3f");

float minMax = minValue;
float maxMax = minValue * 10.0;
float maxValue = maxMax;
SliderFloat("MinValue", &maxValue, v_min, v_max, format = "%.3f");

float endValue = minValue + (maxValue - minValue)/2.0;
SliderFloat("EndValue", &endValue, minValue, maxValue, format = "%.3f");

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

// Here's some code anyone can copy and paste to reproduce your issue
ImGui::Begin("SliderSliderSlider");
float minMin = 1.0;
float maxMin = 10.0;
float minValue = 1.0;
SliderFloat("MinValue", &minValue, minMin, maxMin, format = "%.3f");

float minMax = minValue;
float maxMax = minValue * 10.0;
float maxValue = maxMax;
SliderFloat("MinValue", &maxValue, v_min, v_max, format = "%.3f");

float endValue = minValue + (maxValue - minValue)/2.0;
SliderFloat("EndValue", &endValue, minValue, maxValue, format = "%.3f");

ImGui::End();
ocornut commented 2 hours ago

Hello,

You seem to have answered your own question. I don't understand what else you are asking for? If that does what you want you can use that.

Is this possible?

Yes.

Advisable?

Depends what you want to do with them. Why not.

Is there a better way?

A better way to do what? Your code does exactly what you said you wanted to do.

Version 1.62

Note that this is an extremely old version (more than 6 years old) it is expected to be unsupported.

GrouchoChaplin commented 2 hours ago

Thanks for the (very) fast reply. I guess the question really should have been "does this do what I want it to do".