FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
toggle.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, __shared_ptr_access
5#include <string> // for string, basic_string
6#include <vector> // for vector
7
8#include "ftxui/component/captured_mouse.hpp" // for ftxui
9#include "ftxui/component/component.hpp" // for Toggle, 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, vbox, Element
13
14using namespace ftxui;
15
16int main() {
17 std::vector<std::string> toggle_1_entries = {
18 "On",
19 "Off",
20 };
21 std::vector<std::string> toggle_2_entries = {
22 "Enabled",
23 "Disabled",
24 };
25 std::vector<std::string> toggle_3_entries = {
26 "10€",
27 "0€",
28 };
29 std::vector<std::string> toggle_4_entries = {
30 "Nothing",
31 "One element",
32 "Several elements",
33 };
34
35 int toggle_1_selected = 0;
36 int toggle_2_selected = 0;
37 int toggle_3_selected = 0;
38 int toggle_4_selected = 0;
39 Component toggle_1 = Toggle(&toggle_1_entries, &toggle_1_selected);
40 Component toggle_2 = Toggle(&toggle_2_entries, &toggle_2_selected);
41 Component toggle_3 = Toggle(&toggle_3_entries, &toggle_3_selected);
42 Component toggle_4 = Toggle(&toggle_4_entries, &toggle_4_selected);
43
44 auto container = Container::Vertical({
45 toggle_1,
46 toggle_2,
47 toggle_3,
48 toggle_4,
49 });
50
51 auto renderer = Renderer(container, [&] {
52 return vbox({
53 text("Choose your options:"),
54 text(""),
55 hbox(text(" * Poweroff on startup : "), toggle_1->Render()),
56 hbox(text(" * Out of process : "), toggle_2->Render()),
57 hbox(text(" * Price of the information : "), toggle_3->Render()),
58 hbox(text(" * Number of elements : "), toggle_4->Render()),
59 });
60 });
61
63 screen.Loop(renderer);
64}
static ScreenInteractive TerminalOutput()
Element Render()
Draw the component. Build a ftxui::Element to be drawn on the ftxui::Screen representing this ftxui::...
Component Toggle(ConstStringListRef entries, int *selected)
An horizontal list of elements. The user can navigate through them.
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
Element vbox(Elements)
A container displaying elements vertically one by one.
Definition vbox.cpp:96
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
Element hbox(Elements)
A container displaying elements horizontally one by one.
Definition hbox.cpp:94
std::shared_ptr< ComponentBase > Component
int main()
Definition toggle.cpp:16