FTXUI
6.1.9
C++ functional terminal UI.
Toggle main menu visibility
Loading...
Searching...
No Matches
collapsible.cpp
Go to the documentation of this file.
1
// Copyright 2021 Arthur Sonzogni. All rights reserved.
2
// Use of this source code is governed by the MIT license that can be found in
3
// the LICENSE file.
4
#include <functional>
// for function
5
#include <utility>
// for move
6
7
#include "
ftxui/component/component.hpp
"
// for Checkbox, Maybe, Make, Vertical, Collapsible
8
#include "
ftxui/component/component_base.hpp
"
// for Component, ComponentBase
9
#include "
ftxui/component/component_options.hpp
"
// for CheckboxOption, EntryState
10
#include "
ftxui/dom/elements.hpp
"
// for operator|=, text, hbox, Element, bold, inverted
11
#include "
ftxui/util/ref.hpp
"
// for Ref, ConstStringRef
12
13
namespace
ftxui
{
14
15
/// @brief A collapsible component. It display a checkbox with an arrow. Once
16
/// activated, the children is displayed.
17
/// @param label The label of the checkbox.
18
/// @param child The children to display.
19
/// @param show Hold the state about whether the children is displayed or not.
20
///
21
/// ### Example
22
/// ```cpp
23
/// auto component = Collapsible("Show details", details);
24
/// ```
25
///
26
/// ### Output
27
/// ```
28
///
29
/// ▼ Show details
30
/// <details component>
31
/// ```
32
// NOLINTNEXTLINE
33
Component
Collapsible
(
ConstStringRef
label,
Component
child,
Ref<bool>
show) {
34
class
Impl :
public
ComponentBase
{
35
public
:
36
Impl(ConstStringRef label, Component child, Ref<bool> show) : show_(show) {
37
CheckboxOption opt;
38
opt.transform = [](EntryState s) {
// NOLINT
39
auto
prefix =
text
(s.state ?
"▼ "
:
"▶ "
);
// NOLINT
40
auto
t =
text
(s.label);
41
if
(s.active) {
42
t |=
bold
;
43
}
44
if
(s.focused) {
45
t |=
inverted
;
46
}
47
return
hbox
({prefix, t});
48
};
49
Add(Container::Vertical({
50
Checkbox
(std::move(label), show_.operator->(), opt),
51
Maybe
(std::move(child), show_.operator->()),
52
}));
53
}
54
Ref<bool> show_;
55
};
56
57
return
Make<Impl>
(std::move(label), std::move(child), show);
58
}
59
60
}
// namespace ftxui
ftxui::ComponentBase
It implement rendering itself as ftxui::Element. It implement keyboard navigation by responding to ft...
Definition
component_base.hpp:30
ftxui::ConstStringRef
An adapter. Own or reference a constant string. For convenience, this class convert multiple immutabl...
Definition
ref.hpp:94
ftxui::Ref
An adapter. Own or reference an mutable object.
Definition
ref.hpp:46
component.hpp
component_base.hpp
component_options.hpp
elements.hpp
ftxui
Definition
animation.hpp:10
ftxui::Maybe
Component Maybe(Component, const bool *show)
Decorate a component |child|. It is shown only when |show| is true.
Definition
maybe.cpp:74
ftxui::Make
std::shared_ptr< T > Make(Args &&... args)
Definition
component.hpp:26
ftxui::bold
Element bold(Element)
Use a bold font, for elements with more emphasis.
Definition
bold.cpp:33
ftxui::hbox
Element hbox(Elements)
A container displaying elements horizontally one by one.
Definition
hbox.cpp:94
ftxui::inverted
Element inverted(Element)
Add a filter that will invert the foreground and the background colors.
Definition
inverted.cpp:34
ftxui::text
Element text(std::wstring text)
Display a piece of unicode text.
Definition
text.cpp:160
ftxui::Checkbox
Component Checkbox(CheckboxOption options)
Draw checkable element.
Definition
checkbox.cpp:108
ftxui::Component
std::shared_ptr< ComponentBase > Component
Definition
component_base.hpp:24
ftxui::Collapsible
Component Collapsible(ConstStringRef label, Component child, Ref< bool > show=false)
ref.hpp