FTXUI  0.11.1
C++ functional terminal UI.
maybe.cpp
Go to the documentation of this file.
1 #include <memory> // for make_unique, __shared_ptr_access, __shared_ptr_access<>::element_type, shared_ptr
2 #include <utility> // for move
3 
4 #include "ftxui/component/component.hpp" // for Make, Maybe
5 #include "ftxui/component/component_base.hpp" // for ComponentBase, Component
6 #include "ftxui/component/event.hpp" // for Event
7 #include "ftxui/dom/elements.hpp" // for Element
8 #include "ftxui/dom/node.hpp" // for Node
9 
10 namespace ftxui {
11 
12 Component Maybe(Component child, bool* show) {
13  class Impl : public ComponentBase {
14  public:
15  Impl(bool* show) : show_(show) {}
16 
17  private:
18  Element Render() override {
19  return *show_ ? ComponentBase::Render() : std::make_unique<Node>();
20  }
21  bool Focusable() const override {
22  return *show_ && ComponentBase::Focusable();
23  }
24  bool OnEvent(Event event) override {
25  return *show_ && ComponentBase::OnEvent(event);
26  }
27 
28  bool* show_;
29  };
30 
31  auto maybe = Make<Impl>(show);
32  maybe->Add(std::move(child));
33  return maybe;
34 }
35 
36 } // namespace ftxui
37 
38 // Copyright 2021 Arthur Sonzogni. All rights reserved.
39 // Use of this source code is governed by the MIT license that can be found in
40 // the LICENSE file.
It implement rendering itself as ftxui::Element. It implement keyboard navigation by responding to ft...
virtual bool Focusable() const
Return true when the component contains focusable elements. The non focusable Components will be skip...
Definition: component.cpp:114
virtual Element Render()
Draw the component. Build a ftxui::Element to be drawn on the ftxi::Screen representing this ftxui::C...
Definition: component.cpp:82
virtual bool OnEvent(Event)
Called in response to an event.
Definition: component.cpp:95
std::shared_ptr< Node > Element
Definition: elements.hpp:16
std::shared_ptr< ComponentBase > Component
Component Maybe(Component, bool *show)
Definition: maybe.cpp:12
void Render(Screen &screen, const Element &node)
Display an element on a ftxui::Screen.
Definition: node.cpp:40
Represent an event. It can be key press event, a terminal resize, or more ...
Definition: event.hpp:25