Improve ComponentBase and Container::Tab Focusable implementations (#341)

- Provide better defaults for ComponentBase `Focusable()` and
  `ActiveChild()` methods. This resolves:
  https://github.com/ArthurSonzogni/FTXUI/issues/335

- Implement `Container::Tab` 's  `Focusable()` methods. This prevents
  the users to navigate into a tab with no interactivity.
This commit is contained in:
Arthur Sonzogni
2022-02-19 11:49:12 +01:00
committed by GitHub
parent f95ed885bb
commit 20f16b3984
5 changed files with 62 additions and 3 deletions

View File

@@ -3,6 +3,7 @@
#include <memory> // for shared_ptr, __shared_ptr_access, allocator, make_shared
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Make
#include "ftxui/component/component_base.hpp" // for ComponentBase, Component
#include "gtest/gtest_pred_impl.h" // for EXPECT_EQ, Test, SuiteApiResolver, TEST, TestFactoryImpl
@@ -155,6 +156,22 @@ TEST(ContainerTest, ChildAt) {
EXPECT_EQ(parent->ChildAt(0u), child_2);
}
TEST(ComponentTest, NonFocusableAreNotFocused) {
class NonFocusable : public ComponentBase {
bool Focusable() const override { return false; }
};
auto root = Make<NonFocusable>();
EXPECT_FALSE(root->Focused());
EXPECT_EQ(root->ActiveChild(), nullptr);
auto child = Make<NonFocusable>();
root->Add(child);
EXPECT_FALSE(root->Focused());
EXPECT_FALSE(child->Focused());
EXPECT_EQ(root->ActiveChild(), nullptr);
EXPECT_EQ(child->ActiveChild(), nullptr);
}
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.