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
14using namespace ftxui;
15
16int 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
40 screen.Loop(layout);
41}
static ScreenInteractive TerminalOutput()
Component Maybe(Component, const bool *show)
Decorate a component |child|. It is shown only when |show| is true.
Component Radiobox(RadioboxOption options)
A list of element, where only one can be selected.
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...
Component Checkbox(CheckboxOption options)
Draw checkable element.
Element text(std::wstring text)
Display a piece of unicode text.
Definition text.cpp:160
Decorator color(Color)
Decorate using a foreground color.
The FTXUI ftxui:: namespace.
Definition animation.hpp:10