mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-29 16:39:34 +08:00
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:
@@ -14,7 +14,8 @@
|
||||
#include "ftxui/component/screen_interactive.hpp" // for Component
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, Element, reflect, text, nothing, select, vbox, Elements, focus
|
||||
#include "ftxui/screen/box.hpp" // for Box
|
||||
#include "ftxui/util/ref.hpp" // for Ref, ConstStringListRef, ConstStringRef
|
||||
#include "ftxui/screen/util.hpp"
|
||||
#include "ftxui/util/ref.hpp" // for Ref, ConstStringListRef, ConstStringRef
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
@@ -74,7 +75,7 @@ class MenuBase : public ComponentBase {
|
||||
if (event == Event::TabReverse && size())
|
||||
*selected_ = (*selected_ + size() - 1) % size();
|
||||
|
||||
*selected_ = std::clamp(*selected_, 0, size() - 1);
|
||||
*selected_ = util::clamp(*selected_, 0, size() - 1);
|
||||
|
||||
if (*selected_ != old_selected) {
|
||||
focused_entry() = *selected_;
|
||||
@@ -131,7 +132,7 @@ class MenuBase : public ComponentBase {
|
||||
if (event.mouse().button == Mouse::WheelDown)
|
||||
(*selected_)++;
|
||||
|
||||
*selected_ = std::clamp(*selected_, 0, size() - 1);
|
||||
*selected_ = util::clamp(*selected_, 0, size() - 1);
|
||||
|
||||
if (*selected_ != old_selected)
|
||||
option_->on_change();
|
||||
@@ -140,8 +141,8 @@ class MenuBase : public ComponentBase {
|
||||
|
||||
void Clamp() {
|
||||
boxes_.resize(size());
|
||||
*selected_ = std::clamp(*selected_, 0, size() - 1);
|
||||
focused_entry() = std::clamp(focused_entry(), 0, size() - 1);
|
||||
*selected_ = util::clamp(*selected_, 0, size() - 1);
|
||||
focused_entry() = util::clamp(focused_entry(), 0, size() - 1);
|
||||
}
|
||||
|
||||
bool Focusable() const final { return entries_.size(); }
|
||||
|
Reference in New Issue
Block a user