Merge pull request #55 from cropinghigh/master

Stepped sliders+bandwidth
This commit is contained in:
AlexandreRouma
2020-12-28 14:40:30 +01:00
committed by GitHub
3 changed files with 124 additions and 6 deletions

View File

@ -0,0 +1,23 @@
#include <gui/widgets/stepped_slider.h>
#include <imgui.h>
#include <imgui_internal.h>
namespace ImGui {
bool SliderFloatWithSteps(const char* label, float* v, float v_min, float v_max, float v_step, const char* display_format) {
if (!display_format) {
display_format = "%.3f";
}
char text_buf[64] = {};
ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), display_format, *v);
// Map from [v_min,v_max] to [0,N]
const int countValues = int((v_max-v_min)/v_step);
int v_i = int((*v - v_min)/v_step);
const bool value_changed = ImGui::SliderInt(label, &v_i, 0, countValues, text_buf);
// Remap from [0,N] to [v_min,v_max]
*v = v_min + float(v_i) * v_step;
return value_changed;
}
}

View File

@ -0,0 +1,5 @@
#pragma once
namespace ImGui {
bool SliderFloatWithSteps(const char* label, float* v, float v_min, float v_max, float v_step, const char* display_format = "%.3f");
}