Skip to content

Commit

Permalink
Restored ClampFloat calls, added logging before, during, and after to…
Browse files Browse the repository at this point in the history
… try to track down platform/hardware differences.
  • Loading branch information
Malkierian committed Nov 15, 2024
1 parent 76fda38 commit 7e93e12
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions mm/2s2h/BenGui/UIWidgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string>
#include <unordered_map>
#include <libultraship/libultra/types.h>
#include <fmt/format.h>

namespace UIWidgets {
// Automatically adds newlines to break up text longer than a specified number of characters
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 7e93e12

Please sign in to comment.