FTXUI 6.1.9 C++ functional terminal UI.

Loading...
Searching...
No Matches
examples/component/maybe.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 <string> // for string, allocator, basic_string
5#include <vector> // for vector
6
7#include "ftxui/component/captured_mouse.hpp" // for ftxui
8#include "ftxui/component/component.hpp" // for operator|, Maybe, Checkbox, Radiobox, Renderer, Vertical
9#include "ftxui/component/component_base.hpp" // for Component
10#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
11#include "ftxui/dom/elements.hpp" // for Element, border, color, operator|, text
12#include "ftxui/screen/color.hpp" // for Color, Color::Red
13
14 using namespace ftxui;
15
16 int main() {
17 std::vector<std::string> entries = {
18 "entry 1",
19 "entry 2",
20 "entry 3",
21 };
22 int menu_1_selected = 0;
23 int menu_2_selected = 0;
24
25 bool menu_1_show = false;
26 bool menu_2_show = false;
27
28 auto layout = Container::Vertical({
29 Checkbox("Show menu_1", &menu_1_show),
30 Radiobox(&entries, &menu_1_selected) | border | Maybe(&menu_1_show),
31 Checkbox("Show menu_2", &menu_2_show),
32 Radiobox(&entries, &menu_2_selected) | border | Maybe(&menu_2_show),
33
34 Renderer([] {
35 return text("You found the secret combinaison!") | color(Color::Red);
36 }) | Maybe([&] { return menu_1_selected == 1 && menu_2_selected == 2; }),
37 });
38
39 auto screen = ScreenInteractive::TerminalOutput();
40 screen.Loop(layout);
41}
captured_mouse.hpp
color.hpp
component.hpp
component_base.hpp
elements.hpp
main
int main()
Definition examples/component/maybe.cpp:16
ftxui::ScreenInteractive::TerminalOutput
static ScreenInteractive TerminalOutput()
Definition screen_interactive.cpp:410
ftxui::Maybe
Component Maybe(Component, const bool *show)
Decorate a component |child|. It is shown only when |show| is true.
Definition src/ftxui/component/maybe.cpp:74
ftxui::Radiobox
Component Radiobox(RadioboxOption options)
A list of element, where only one can be selected.
Definition src/ftxui/component/radiobox.cpp:204
ftxui::Renderer
Component Renderer(Component child, std::function< Element()>)
Return a new Component, similar to |child|, but using |render| as the Component::Render() event.
Definition src/ftxui/component/renderer.cpp:61
ftxui::Container::Vertical
Component Vertical(Components children)
A list of components, drawn one by one vertically and navigated vertically using up/down arrow key or...
Definition container.cpp:317
ftxui::Checkbox
Component Checkbox(CheckboxOption options)
Draw checkable element.
Definition src/ftxui/component/checkbox.cpp:108
ftxui::text
Element text(std::wstring text)
Display a piece of unicode text.
Definition text.cpp:160
ftxui::color
Decorator color(Color)
Decorate using a foreground color.
Definition dom/color.cpp:110
ftxui::Color::Red
@ Red
Definition color.hpp:55
ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
screen_interactive.hpp