FTXUI  2.0.0
C++ functional terminal UI.
Loading...
Searching...
No Matches
collapsible.cpp
Go to the documentation of this file.
1#include <string> // for string
2#include <utility> // for move
3
4#include "ftxui/component/component.hpp" // for Checkbox, Maybe, Make, Vertical, Collapsible
5#include "ftxui/component/component_base.hpp" // for Component, ComponentBase
6#include "ftxui/component/component_options.hpp" // for CheckboxOption
7#include "ftxui/util/ref.hpp" // for Ref, ConstStringRef
8
9namespace ftxui {
10
11/// @brief A collapsible component. It display a checkbox with an arrow. Once
12/// activated, the children is displayed.
13/// @params label The label of the checkbox.
14/// @params child The children to display.
15/// @params show Hold the state about whether the children is displayed or not.
16///
17/// ### Example
18/// ```cpp
19/// auto component = Collapsible("Show details", details);
20/// ```
21///
22/// ### Output
23/// ```
24///
25/// ▼ Show details
26/// <details component>
27/// ```
28Component Collapsible(ConstStringRef label, Component child, Ref<bool> show) {
29 class Impl : public ComponentBase {
30 public:
31 Impl(ConstStringRef label, Component child, Ref<bool> show)
32 : label_(label), show_(std::move(show)) {
33 CheckboxOption opt;
34 opt.style_checked = "▼ ";
35 opt.style_unchecked = "▶ ";
36 Add(Container::Vertical({
37 Checkbox(label_, show_.operator->(), opt),
38 Maybe(std::move(child), show_.operator->()),
39 }));
40 }
41 ConstStringRef label_;
42 Ref<bool> show_;
43 };
44
45 return Make<Impl>(label, std::move(child), std::move(show));
46}
47
48} // namespace ftxui
49
50// Copyright 2021 Arthur Sonzogni. All rights reserved.
51// Use of this source code is governed by the MIT license that can be found in
52// the LICENSE file.
Component Checkbox(ConstStringRef label, bool *checked, Ref< CheckboxOption > option={})
Draw checkable element.
Definition checkbox.cpp:117
std::shared_ptr< T > Make(Args &&... args)
Definition component.hpp:25
Component Maybe(Component, const bool *show)
Definition maybe.cpp:12
std::shared_ptr< ComponentBase > Component
Component Collapsible(ConstStringRef label, Component child, Ref< bool > show=false)