From a09ebcc4422f0f07910bb41dd755c1edf6f7b3ab Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Fri, 17 Apr 2020 01:15:17 +0200 Subject: [PATCH] Fix bug with container on Windows. This fix the bug from: https://github.com/ArthurSonzogni/FTXUI/pull/11 About: ~~~ Bug: Focus handling not working in the examples (e.g. checkbox.cpp) I can toggle the individual checkboxes but I cannot move between items, I tried to understand the focus implementation but am I unsure which keypresses would move focus between different components ~~~ --- include/ftxui/component/container.hpp | 2 +- src/ftxui/component/container.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/ftxui/component/container.hpp b/include/ftxui/component/container.hpp index 97c6d20..51395ed 100644 --- a/include/ftxui/component/container.hpp +++ b/include/ftxui/component/container.hpp @@ -37,7 +37,7 @@ class Container : public Component { RenderHandler render_handler_; int selected_ = 0; - int* selector_ = &selected_; + int* selector_ = nullptr; }; } // namespace ftxui diff --git a/src/ftxui/component/container.cpp b/src/ftxui/component/container.cpp index b9743c4..b4b26c5 100644 --- a/src/ftxui/component/container.cpp +++ b/src/ftxui/component/container.cpp @@ -42,7 +42,9 @@ bool Container::OnEvent(Event event) { Component* Container::ActiveChild() { if (children_.size() == 0) return nullptr; - return children_[*selector_ % children_.size()]; + + int selected = selector_ ? *selector_ : selected_; + return children_[selected % children_.size()]; } bool Container::VerticalEvent(Event event) {