Change precision of float sliders (#1609)

* Change precision of float sliders

* Formatting

* Don't round non-percentage sliders
This commit is contained in:
GaryOderNichts 2022-09-28 01:30:50 +02:00 committed by GitHub
parent 677c4845f6
commit c6a875eb5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 13 deletions

View File

@ -301,10 +301,11 @@ namespace UIWidgets {
void EnhancementSliderFloat(const char* text, const char* id, const char* cvarName, float min, float max, const char* format, float defaultValue, bool isPercentage, bool PlusMinusButton) {
float val = CVar_GetFloat(cvarName, defaultValue);
if (!isPercentage)
if (!isPercentage) {
ImGui::Text(text, val);
else
} else {
ImGui::Text(text, static_cast<int>(100 * val));
}
Spacer(0);
@ -312,10 +313,11 @@ namespace UIWidgets {
std::string MinusBTNName = " - ##";
MinusBTNName += cvarName;
if (ImGui::Button(MinusBTNName.c_str())) {
if (!isPercentage)
if (!isPercentage) {
val -= 0.1f;
else
} else {
val -= 0.01f;
}
CVar_SetFloat(cvarName, val);
SohImGui::RequestCvarSaveOnNextTick();
}
@ -331,9 +333,12 @@ namespace UIWidgets {
ImGui::PushItemWidth(ImGui::GetWindowSize().x - 79.0f);
#endif
}
if (ImGui::SliderFloat(id, &val, min, max, format))
{
CVar_SetFloat(cvarName, val);
if (ImGui::SliderFloat(id, &val, min, max, format)) {
if (isPercentage) {
CVar_SetFloat(cvarName, roundf(val * 100) / 100);
} else {
CVar_SetFloat(cvarName, val);
}
SohImGui::RequestCvarSaveOnNextTick();
}
if (PlusMinusButton) {
@ -345,24 +350,23 @@ namespace UIWidgets {
ImGui::SameLine();
ImGui::SetCursorPosX(ImGui::GetCursorPosX() - 7.0f);
if (ImGui::Button(PlusBTNName.c_str())) {
if (!isPercentage)
if (!isPercentage) {
val += 0.1f;
else
} else {
val += 0.01f;
}
CVar_SetFloat(cvarName, val);
SohImGui::RequestCvarSaveOnNextTick();
}
}
if (val < min)
{
if (val < min) {
val = min;
CVar_SetFloat(cvarName, val);
SohImGui::RequestCvarSaveOnNextTick();
}
if (val > max)
{
if (val > max) {
val = max;
CVar_SetFloat(cvarName, val);
SohImGui::RequestCvarSaveOnNextTick();