FTXUI 6.1.9 C++ functional terminal UI.

Loading...
Searching...
No Matches
menu_multiple.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 <stdlib.h> // for EXIT_SUCCESS
5#include <memory> // for allocator, __shared_ptr_access
6#include <string> // for string, operator+, basic_string, to_string, char_traits
7#include <vector> // for vector, __alloc_traits<>::value_type
8
9#include "ftxui/component/captured_mouse.hpp" // for ftxui
10#include "ftxui/component/component.hpp" // for Menu, Renderer, Horizontal, Vertical
11#include "ftxui/component/component_base.hpp" // for ComponentBase
12#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
13#include "ftxui/dom/elements.hpp" // for text, Element, operator|, window, flex, vbox
14
15 using namespace ftxui;
16
17 Component Window(std::string title, Component component) {
18 return Renderer(component, [component, title] { //
19 return window(text(title), component->Render()) | flex;
20 });
21}
22
23 int main() {
24 int menu_selected[] = {0, 0, 0};
25 std::vector<std::vector<std::string>> menu_entries = {
26 {
27 "Ananas",
28 "Raspberry",
29 "Citrus",
30 },
31 {
32 "Potatoes",
33 "Weat",
34 "Rise",
35 },
36 {
37 "Carrot",
38 "Lettuce",
39 "Tomato",
40 },
41 };
42
43 int menu_selected_global = 0;
44 auto menu_global = Container::Vertical(
45 {
46 Window("Menu 1", Menu(&menu_entries[0], &menu_selected[0])),
47 Window("Menu 2", Menu(&menu_entries[1], &menu_selected[1])),
48 Window("Menu 3", Menu(&menu_entries[2], &menu_selected[2])),
49 },
50 &menu_selected_global);
51
52 auto info = Renderer([&] {
53 int g = menu_selected_global;
54 std::string value = menu_entries[g][menu_selected[g]];
55 return window(text("Content"), //
56 vbox({
57 text("menu_selected_global = " + std::to_string(g)),
58 text("menu_selected[0] = " +
59 std::to_string(menu_selected[0])),
60 text("menu_selected[1] = " +
61 std::to_string(menu_selected[1])),
62 text("menu_selected[2] = " +
63 std::to_string(menu_selected[2])),
64 text("Value = " + value),
65 })) |
66 flex;
67 });
68
69 auto global = Container::Horizontal({
70 menu_global,
71 info,
72 });
73
74 auto screen = ScreenInteractive::TerminalOutput();
75 screen.Loop(global);
76 return EXIT_SUCCESS;
77}
captured_mouse.hpp
component.hpp
component_base.hpp
elements.hpp
ftxui::ScreenInteractive::TerminalOutput
static ScreenInteractive TerminalOutput()
Definition screen_interactive.cpp:410
ftxui::ComponentBase::Render
Element Render()
Draw the component. Build a ftxui::Element to be drawn on the ftxui::Screen representing this ftxui::...
Definition component.cpp:103
ftxui::Container::Horizontal
Component Horizontal(Components children)
A list of components, drawn one by one horizontally and navigated horizontally using left/right arrow...
Definition container.cpp:360
ftxui::Menu
Component Menu(MenuOption options)
A list of text. The focused element is selected.
Definition src/ftxui/component/menu.cpp:512
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::Window
Component Window(WindowOptions option)
A draggeable / resizeable window. To use multiple of them, they must be stacked using Container::Stac...
Definition src/ftxui/component/window.cpp:312
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::window
Element window(Element title, Element content, BorderStyle border=ROUNDED)
Draw window with a title and a border around the element.
Definition src/ftxui/dom/border.cpp:507
ftxui::flex
Element flex(Element)
Make a child element to expand proportionally to the space left in a container.
Definition flex.cpp:123
ftxui::text
Element text(std::wstring text)
Display a piece of unicode text.
Definition text.cpp:160
ftxui::vbox
Element vbox(Elements)
A container displaying elements vertically one by one.
Definition vbox.cpp:96
main
int main()
Definition menu_multiple.cpp:23
ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
ftxui::Component
std::shared_ptr< ComponentBase > Component
Definition component_base.hpp:24
screen_interactive.hpp