Open Wolftronics-SBC opened 6 years ago
We have a API explosion problem, for now I don't think I would add, but I admit it is tempting to sneak them in the DragScalar() SliderScalar() functions since they are fresh.
Later I expect to refactor the internal code to be combineable at a lower level.
Hi sorry to reopen this question. But I would also like to have an integer slider that accepts a step such that it gives only negative numbers.
It's easy enough to simulate steps when the value changes:
static float foobar = 0;
// Slider with a step of 3.0
if (ImGui::SliderFloat("Foobar", &foobar , 0.0f, 15.0f, "%.0f")) {
foobar = std::round(foobar / 3.0f) * 3.0f;
}
however:
If possible support non-constant steps. In one of my use case, I need the values to be divisors of another bigger number (e.g. divisors of 1440 (number of minutes in a day), where values 7, 11, 13, 14, 17, 19, ... are not valid). Maybe a callback function, which could return the preferred value (nearest for mouse drag, next/previous for arrows/gamepad)
Here my hack for a step slider:
ImGui::Dummy(ImVec2(0, 10));
static int width = 512;
int widthSliderStep = 128;
static int widthSliderValue = width / widthSliderStep;
if (ImGui::SliderInt("Width", &widthSliderValue, 1, 8, std::to_string(width).c_str(), ImGuiSliderFlags_NoInput)) {
width = widthSliderValue * widthSliderStep;
}
ImGui::Dummy(ImVec2(0, 10));
static float height = 15;
float heightSliderStep = 1.5;
static int heightSliderValue = height / heightSliderStep;
std::ostringstream ssHeight;
ssHeight << std::fixed << std::setprecision(1) << height;
if (ImGui::SliderInt("Height", &heightSliderValue, 1, 20, ssHeight.str().c_str(), ImGuiSliderFlags_NoInput)) {
height = heightSliderValue * heightSliderStep;
}
ImGui::Dummy(ImVec2(0, 10));
ImGui :: DragScalar and ImGui :: SliderScalar with drag_step and slider_step? did not you want to do that?
as ImGui :: InputScalar
ImGui :: Checkbox ("Show step buttons", & inputs_step); ImGui :: InputScalar ("input s32", ImGuiDataType_S32, & s32_v, inputs_step? & S32_one: NULL, NULL, "% d");