FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
menu_entries.cpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. Todos los derechos reservados.
2// El uso de este código fuente se rige por la licencia MIT que se puede encontrar en
3// el archivo LICENSE.
4#include <functional> // for function
5#include <iostream> // for basic_ostream::operator<<, operator<<, endl, basic_ostream, basic_ostream<>::__ostream_type, cout, ostream
6#include <memory> // for allocator, shared_ptr, __shared_ptr_access
7#include <string> // for char_traits, to_string, operator+, string, basic_string
8
9#include "ftxui/component/captured_mouse.hpp" // for ftxui
10#include "ftxui/component/component.hpp" // for MenuEntry, Renderer, Vertical
11#include "ftxui/component/component_base.hpp" // for ComponentBase
12#include "ftxui/component/component_options.hpp" // for MenuEntryOption
13#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
14#include "ftxui/dom/elements.hpp" // for operator|, Element, separator, text, hbox, size, frame, color, vbox, HEIGHT, LESS_THAN, bold, border, inverted
15#include "ftxui/screen/color.hpp" // for Color, Color::Blue, Color::Cyan, Color::Green, Color::Red, Color::Yellow
16
17using namespace ftxui;
18
19// Define un estilo especial para algunas entradas del menú.
21 MenuEntryOption option;
22 option.transform = [c](EntryState state) {
23 state.label = (state.active ? "> " : " ") + state.label;
24 Element e = text(state.label) | color(c);
25 if (state.focused) {
26 e = e | inverted;
27 }
28 if (state.active) {
29 e = e | bold;
30 }
31 return e;
32 };
33 return option;
34}
35
36int main() {
38
39 int selected = 0;
40 auto menu = Container::Vertical(
41 {
42 MenuEntry(" 1. improve"),
43 MenuEntry(" 2. tolerant"),
44 MenuEntry(" 3. career"),
45 MenuEntry(" 4. cast"),
46 MenuEntry(" 5. question"),
47
48 Renderer([] { return separator(); }),
49
50 MenuEntry(" 6. rear", Colored(Color::Red)),
51 MenuEntry(" 7. drown", Colored(Color::Yellow)),
52 MenuEntry(" 8. nail", Colored(Color::Green)),
53 MenuEntry(" 9. quit", Colored(Color::Cyan)),
54 MenuEntry("10. decorative", Colored(Color::Blue)),
55
56 Renderer([] { return separator(); }),
57
58 MenuEntry("11. costume"),
59 MenuEntry("12. pick"),
60 MenuEntry("13. oral"),
61 MenuEntry("14. minister"),
62 MenuEntry("15. football"),
63 MenuEntry("16. welcome"),
64 MenuEntry("17. copper"),
65 MenuEntry("18. inhabitant"),
66 MenuEntry("19. fortune"),
67 },
68 &selected);
69
70 // Muestra el menú junto con un borde
71 auto renderer = Renderer(menu, [&] {
72 return vbox({
73 hbox(text("selected = "), text(std::to_string(selected))),
74 separator(),
75 menu->Render() | frame | size(HEIGHT, LESS_THAN, 10),
76 }) |
77 border;
78 });
79
80 screen.Loop(renderer);
81
82 std::cout << "Selected element = " << selected << std::endl;
83}
auto screen
static ScreenInteractive TerminalOutput()
std::function< Element(const EntryState &state)> transform
Component MenuEntry(MenuEntryOption options)
Una entrada de menú específica. Se pueden colocar en un Container::Vertical para formar un menú.
Component Renderer(Component child, std::function< Element()>)
Retorna un nuevo Componente, similar a |child|, pero usando |render| como el evento Component::Render...
Opción para el componente MenuEntry.
virtual void Render(Screen &screen)
Muestra un elemento en un ftxui::Screen.
Definition node.cpp:59
Decorator size(WidthOrHeight, Constraint, int value)
Aplica una restricción al tamaño de un elemento.
Element bold(Element)
Utiliza una fuente en negrita, para elementos con más énfasis.
Definition bold.cpp:33
Element inverted(Element)
Agrega un filtro que invertirá los colores de primer plano y de fondo. colores.
Definition inverted.cpp:34
Element text(std::wstring text)
Muestra un fragmento de texto Unicode.
Definition text.cpp:160
Element separator()
Dibuja una separación vertical u horizontal entre otros dos elementos.
Decorator color(Color)
Decora usando un color de primer plano.
Color es una clase que representa un color en la interfaz de usuario de la terminal.
Definition color.hpp:21
MenuEntryOption Colored(ftxui::Color c)
int main()
El espacio de nombres ftxui:: de FTXUI.
Definition animation.hpp:10
std::shared_ptr< Node > Element
Definition elements.hpp:22
Element hbox(Elements)
Un contenedor que muestra elementos horizontalmente uno por uno.
Definition hbox.cpp:94
Element vbox(Elements)
@ LESS_THAN
Definition elements.hpp:162
Argumentos para la transformación de |ButtonOption|, |CheckboxOption|, |RadioboxOption|,...