From 7e93e12af7114f8680993f10dc41094430d2744c Mon Sep 17 00:00:00 2001 From: Malkierian Date: Fri, 15 Nov 2024 10:20:27 -0700 Subject: [PATCH] Restored ClampFloat calls, added logging before, during, and after to try to track down platform/hardware differences. --- mm/2s2h/BenGui/UIWidgets.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/mm/2s2h/BenGui/UIWidgets.cpp b/mm/2s2h/BenGui/UIWidgets.cpp index 289cb227c..6e3f288ef 100644 --- a/mm/2s2h/BenGui/UIWidgets.cpp +++ b/mm/2s2h/BenGui/UIWidgets.cpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace UIWidgets { // Automatically adds newlines to break up text longer than a specified number of characters @@ -424,9 +425,14 @@ void ClampFloat(float* value, float min, float max, float step) { *value = max; } else { *value = std::round(*value * factor) / factor; + std::string msg = fmt::format("Value after round: {}", (float)*value); + SPDLOG_ERROR(msg.c_str()); std::stringstream ss; - ss << std::setprecision(ticks) << std::setiosflags(std::ios_base::fixed) << *value; - *value = std::stof(ss.str()); + ss << std::setprecision(ticks) << std::setiosflags(std::ios_base::fixed) << (float)*value; + msg = fmt::format("String value: {}", ss.str()); + SPDLOG_ERROR(msg.c_str()); + float str = std::stof(ss.str()); + *value = str; } } @@ -455,7 +461,7 @@ bool SliderFloat(const char* label, float* value, float min, float max, const Fl if (options.showButtons) { if (Button("-", { .color = options.color, .size = Sizes::Inline }) && *value > min) { *value -= options.step; - // ClampFloat(value, min, max, options.step); + ClampFloat(value, min, max, options.step); Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick(); dirty = true; } @@ -467,7 +473,12 @@ bool SliderFloat(const char* label, float* value, float min, float max, const Fl if (ImGui::SliderScalar(invisibleLabel, ImGuiDataType_Float, &valueToDisplay, &minToDisplay, &maxToDisplay, options.format, options.flags)) { *value = options.isPercentage ? valueToDisplay / 100.0f : valueToDisplay; - // ClampFloat(value, min, max, options.step); + std::string msg = fmt::format("Val: {}; ValDisp: {}; Max: {}; MaxDisp: {}; Min: {}; MinDisp: {}", (float)*value, + valueToDisplay, max, maxToDisplay, min, minToDisplay); + SPDLOG_ERROR(msg.c_str()); + ClampFloat(value, min, max, options.step); + msg = fmt::format("After clamp - Val: {}; Max: {}; Min: {}", (float)*value, max, min); + SPDLOG_ERROR(msg.c_str()); Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick(); dirty = true; } @@ -476,7 +487,7 @@ bool SliderFloat(const char* label, float* value, float min, float max, const Fl ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); if (Button("+", { .color = options.color, .size = Sizes::Inline }) && *value < max) { *value += options.step; - // ClampFloat(value, min, max, options.step); + ClampFloat(value, min, max, options.step); Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick(); dirty = true; }