Fix: crash when window can't be placed on low resolution screens. (#10932)
Co-authored-by: Jonathan G Rennison <j.g.rennison@gmail.com>
This commit is contained in:
@@ -83,6 +83,32 @@ static inline T Clamp(const T a, const T min, const T max)
|
||||
return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clamp a value between an interval.
|
||||
*
|
||||
* This function returns a value which is between the given interval of
|
||||
* min and max. If the given value is in this interval the value itself
|
||||
* is returned otherwise the border of the interval is returned, according
|
||||
* which side of the interval was 'left'.
|
||||
*
|
||||
* @note If the min value is greater than the max, return value is the average of the min and max.
|
||||
* @param a The value to clamp/truncate.
|
||||
* @param min The minimum of the interval.
|
||||
* @param max the maximum of the interval.
|
||||
* @returns A value between min and max which is closest to a.
|
||||
*/
|
||||
template <typename T>
|
||||
static inline T SoftClamp(const T a, const T min, const T max)
|
||||
{
|
||||
if (min > max) {
|
||||
using U = std::make_unsigned_t<T>;
|
||||
return min - (U(min) - max) / 2;
|
||||
}
|
||||
if (a <= min) return min;
|
||||
if (a >= max) return max;
|
||||
return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clamp an integer between an interval.
|
||||
*
|
||||
|
Reference in New Issue
Block a user