mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2024-11-06 18:57:39 +01:00
Fix bugs+move widget
This commit is contained in:
parent
04823abb83
commit
b370eda0d5
23
core/src/gui/widgets/stepped_slider.cpp
Normal file
23
core/src/gui/widgets/stepped_slider.cpp
Normal 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;
|
||||
}
|
||||
}
|
5
core/src/gui/widgets/stepped_slider.h
Normal file
5
core/src/gui/widgets/stepped_slider.h
Normal 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");
|
||||
}
|
@ -481,7 +481,6 @@ namespace ImGui
|
||||
// - CTRL+Click on any slider to turn them into an input box. Manually input values aren't clamped and can go off-bounds.
|
||||
// - Adjust format string to decorate the value with a prefix, a suffix, or adapt the editing and display precision e.g. "%.3f" -> 1.234; "%5.2f secs" -> 01.23 secs; "Biscuit: %.0f" -> Biscuit: 1; etc.
|
||||
IMGUI_API bool SliderFloat(const char* label, float* v, float v_min, float v_max, const char* format = "%.3f", float power = 1.0f); // adjust format to decorate the value with a prefix or a suffix for in-slider labels or unit display. Use power!=1.0 for power curve sliders
|
||||
IMGUI_API bool SliderFloatWithSteps(const char* label, float* v, float v_min, float v_max, float v_step, const char* display_format = "%.3f");
|
||||
IMGUI_API bool SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* format = "%.3f", float power = 1.0f);
|
||||
IMGUI_API bool SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* format = "%.3f", float power = 1.0f);
|
||||
IMGUI_API bool SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* format = "%.3f", float power = 1.0f);
|
||||
|
@ -2702,25 +2702,6 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c
|
||||
return SliderScalar(label, ImGuiDataType_Float, v, &v_min, &v_max, format, power);
|
||||
}
|
||||
|
||||
bool ImGui::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;
|
||||
}
|
||||
|
||||
|
||||
bool ImGui::SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* format, float power)
|
||||
{
|
||||
return SliderScalarN(label, ImGuiDataType_Float, v, 2, &v_min, &v_max, format, power);
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <module.h>
|
||||
#include <gui/gui.h>
|
||||
#include <gui/widgets/stepped_slider.h>
|
||||
#include <signal_path/signal_path.h>
|
||||
#include <SoapySDR/Device.hpp>
|
||||
#include <SoapySDR/Modules.hpp>
|
||||
@ -154,6 +155,7 @@ private:
|
||||
gainList = dev->listGains(SOAPY_SDR_RX, channelId);
|
||||
delete[] uiGains;
|
||||
uiGains = new float[gainList.size()];
|
||||
gainRanges.clear();
|
||||
|
||||
for (auto gain : gainList) {
|
||||
gainRanges.push_back(dev->getGainRange(SOAPY_SDR_RX, channelId, gain));
|
||||
@ -398,10 +400,11 @@ private:
|
||||
ImGui::SetNextItemWidth(menuWidth - gainNameLen);
|
||||
float step = _this->gainRanges[i].step();
|
||||
bool res;
|
||||
if(step == 0.0f)
|
||||
if(step == 0.0f) {
|
||||
res = ImGui::SliderFloat((std::string("##_gain_sel_") + _this->name + gain).c_str(), &_this->uiGains[i], _this->gainRanges[i].minimum(), _this->gainRanges[i].maximum());
|
||||
else
|
||||
} else {
|
||||
res = ImGui::SliderFloatWithSteps((std::string("##_gain_sel_") + _this->name + gain).c_str(), &_this->uiGains[i], _this->gainRanges[i].minimum(), _this->gainRanges[i].maximum(), step);
|
||||
}
|
||||
if(res) {
|
||||
if (_this->running) {
|
||||
_this->dev->setGain(SOAPY_SDR_RX, _this->channelId, gain, _this->uiGains[i]);
|
||||
|
Loading…
Reference in New Issue
Block a user