FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
examples/component/collapsible.cpp
Go to the documentation of this file.
1// Copyright 2020 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 <memory> // for allocator, make_shared, __shared_ptr_access
5#include <utility> // for move
6#include <vector> // for vector
7
8#include "ftxui/component/captured_mouse.hpp" // for ftxui
9#include "ftxui/component/component.hpp" // for Collapsible, Renderer, Vertical
10#include "ftxui/component/component_base.hpp" // for ComponentBase
11#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
12#include "ftxui/dom/elements.hpp" // for text, hbox, Element
13
14using namespace ftxui;
15
16// Take a list of component, display them vertically, one column shifted to the
17// right.
18Component Inner(std::vector<Component> children) {
19 Component vlist = Container::Vertical(std::move(children));
20 return Renderer(vlist, [vlist] {
21 return hbox({
22 text(" "),
23 vlist->Render(),
24 });
25 });
26}
27
29 return std::make_shared<ComponentBase>();
30}
31
32int main() {
33 auto component =
34 Collapsible("Collapsible 1",
35 Inner({
36 Collapsible("Collapsible 1.1",
37 Inner({
38 Collapsible("Collapsible 1.1.1", Empty()),
39 Collapsible("Collapsible 1.1.2", Empty()),
40 Collapsible("Collapsible 1.1.3", Empty()),
41 })),
42 Collapsible("Collapsible 1.2",
43 Inner({
44 Collapsible("Collapsible 1.2.1", Empty()),
45 Collapsible("Collapsible 1.2.2", Empty()),
46 Collapsible("Collapsible 1.2.3", Empty()),
47 })),
48 Collapsible("Collapsible 1.3",
49 Inner({
50 Collapsible("Collapsible 1.3.1", Empty()),
51 Collapsible("Collapsible 1.3.2", Empty()),
52 Collapsible("Collapsible 1.3.3", Empty()),
53 })),
54 }));
55
57}
Component Inner(std::vector< Component > children)
Component Empty()
Element Render()
Draw the component. Build a ftxui::Element to be drawn on the ftxui::Screen representing this ftxui::...
static ScreenInteractive FitComponent()
void Loop(Component)
Execute the main loop.
Component Renderer(Component child, std::function< Element()>)
Return a new Component, similar to |child|, but using |render| as the Component::Render() event.
Component Vertical(Components children)
A list of components, drawn one by one vertically and navigated vertically using up/down arrow key or...
Element text(std::wstring text)
Display a piece of unicode text.
Definition text.cpp:160
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
Element hbox(Elements)
A container displaying elements horizontally one by one.
Definition hbox.cpp:94
Component Collapsible(ConstStringRef label, Component child, Ref< bool > show=false)
A collapsible component. It displays a checkbox with an arrow. Once activated, the child is displayed...
std::shared_ptr< ComponentBase > Component