mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-28 16:29: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|, reflect, text, Element, hbox, vbox, Elements, focus, nothing, select
|
||||
#include "ftxui/screen/box.hpp" // for Box
|
||||
#include "ftxui/util/ref.hpp" // for Ref, ConstStringListRef
|
||||
#include "ftxui/screen/util.hpp"
|
||||
#include "ftxui/util/ref.hpp" // for Ref, ConstStringListRef
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
@@ -91,7 +92,7 @@ class RadioboxBase : public ComponentBase {
|
||||
if (event == Event::TabReverse && size())
|
||||
hovered_ = (hovered_ + size() - 1) % size();
|
||||
|
||||
hovered_ = std::clamp(hovered_, 0, size() - 1);
|
||||
hovered_ = util::clamp(hovered_, 0, size() - 1);
|
||||
|
||||
if (hovered_ != old_hovered) {
|
||||
focused_entry() = hovered_;
|
||||
@@ -145,7 +146,7 @@ class RadioboxBase : public ComponentBase {
|
||||
if (event.mouse().button == Mouse::WheelDown)
|
||||
(hovered_)++;
|
||||
|
||||
hovered_ = std::clamp(hovered_, 0, size() - 1);
|
||||
hovered_ = util::clamp(hovered_, 0, size() - 1);
|
||||
|
||||
if (hovered_ != old_hovered)
|
||||
option_->on_change();
|
||||
@@ -155,9 +156,9 @@ class RadioboxBase : public ComponentBase {
|
||||
|
||||
void Clamp() {
|
||||
boxes_.resize(size());
|
||||
*selected_ = std::clamp(*selected_, 0, size() - 1);
|
||||
focused_entry() = std::clamp(focused_entry(), 0, size() - 1);
|
||||
hovered_ = std::clamp(hovered_, 0, size() - 1);
|
||||
*selected_ = util::clamp(*selected_, 0, size() - 1);
|
||||
focused_entry() = util::clamp(focused_entry(), 0, size() - 1);
|
||||
hovered_ = util::clamp(hovered_, 0, size() - 1);
|
||||
}
|
||||
|
||||
bool Focusable() const final { return entries_.size(); }
|
||||
|
Reference in New Issue
Block a user