mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-02-07 10:50:29 -05:00
Change precision of float sliders (#1609)
* Change precision of float sliders * Formatting * Don't round non-percentage sliders
This commit is contained in:
parent
677c4845f6
commit
c6a875eb5c
@ -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))
|
||||
{
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user