Make better use of std::clamp

This commit is contained in:
Alexei Dobrohotov 2021-11-06 07:30:28 +03:00
parent b6d2c57de2
commit 7a0c13fcf8
38 changed files with 80 additions and 103 deletions

View file

@ -31,15 +31,11 @@ namespace Gui
}
private:
static int clamp(const int& value, const int& lowBound, const int& highBound)
{
return std::min(std::max(lowBound, value), highBound);
}
std::string getFontSize()
{
// Note: we can not use the FontLoader here, so there is a code duplication a bit.
static const std::string fontSize = std::to_string(clamp(Settings::Manager::getInt("font size", "GUI"), 12, 20));
static const std::string fontSize = std::to_string(std::clamp(Settings::Manager::getInt("font size", "GUI"), 12, 20));
return fontSize;
}
};

View file

@ -31,7 +31,7 @@ namespace Gui
try
{
mValue = std::stoi(newCaption);
int capped = std::min(mMaxValue, std::max(mValue, mMinValue));
int capped = std::clamp(mValue, mMinValue, mMaxValue);
if (capped != mValue)
{
mValue = capped;