Fix Clamp crash when entries_ size is zero (#306)

Run ftxui_example_homescreen on Windows, then select compiler tab, crash on origin code.

Co-authored-by: chenpeizhe <peizhe.chen@horizon.ai>
This commit is contained in:
pezy
2022-01-13 08:46:09 +08:00
committed by GitHub
parent 3dc215e6c0
commit feb24b9498
6 changed files with 40 additions and 21 deletions

15
src/ftxui/screen/util.hpp Normal file
View File

@@ -0,0 +1,15 @@
namespace ftxui {
namespace util {
// Similar to std::clamp, but allow hi to be lower than lo.
template <class T>
constexpr const T& clamp(const T& v, const T& lo, const T& hi) {
return v < lo ? lo : hi < v ? hi : v;
}
} // namespace util
} // namespace ftxui
// Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.