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
15using namespace ftxui;
16
17Component Window(std::string title, Component component) {
18 return Renderer(component, [component, title] { //
19 return window(text(title), component->Render()) | flex;
20 });
21}
22
23int main() {
24 int menu_selected[] = {0, 0, 0};
25 std::vector<std::vector<std::string>> menu_entries = {
26 {
27 "Piña",
28 "Frambuesa",
29 "Cítricos",
30 },
31 {
32 "Patatas",
33 "Trigo",
34 "Arroz",
35 },
36 {
37 "Zanahoria",
38 "Lechuga",
39 "Tomate",
40 },
41 };
42
43 int menu_selected_global = 0;
44 auto menu_global = Container::Vertical(
45 {
46 Window("Menú 1", Menu(&menu_entries[0], &menu_selected[0])),
47 Window("Menú 2", Menu(&menu_entries[1], &menu_selected[1])),
48 Window("Menú 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("Contenido"), //
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("Valor = " + value),
65 })) |
66 flex;
67 });
68
69 auto global = Container::Horizontal({
70 menu_global,
71 info,
72 });
73
75 screen.Loop(global);
76 return EXIT_SUCCESS;
77}
auto screen
static ScreenInteractive TerminalOutput()
Element Render()
Dibuja el componente. Construye un ftxui::Element para ser dibujado en la ftxui::Screen representando...
Component Menu(MenuOption options)
Una lista de texto. El elemento enfocado es seleccionado.
Component Renderer(Component child, std::function< Element()>)
Retorna un nuevo Componente, similar a |child|, pero usando |render| como el evento Component::Render...
Component Window(WindowOptions option)
Una ventana arrastrable y redimensionable. Para usar varias, deben apilarse usando el componente Cont...
Element window(Element title, Element content, BorderStyle border=ROUNDED)
Draw window with a title and a border around the element.
Element flex(Element)
Hace que un elemento hijo se expanda proporcionalmente al espacio restante en un contenedor.
Definition flex.cpp:123
Element text(std::wstring text)
Muestra un fragmento de texto Unicode.
Definition text.cpp:160
std::string title
int main()
El espacio de nombres ftxui:: de FTXUI.
Definition animation.hpp:10
Element vbox(Elements)
std::shared_ptr< ComponentBase > Component