FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
examples/component/selection.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 <string> // for char_traits, operator+, string, basic_string
5
6#include "ftxui/component/component.hpp" // for Input, Renderer, Vertical
7#include "ftxui/component/component_base.hpp" // for ComponentBase
8#include "ftxui/component/component_options.hpp" // for InputOption
9#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
10#include "ftxui/dom/elements.hpp" // for text, hbox, separator, Element, operator|, vbox, border
11#include "ftxui/util/ref.hpp" // for Ref
12
13using namespace ftxui;
14
16 return vbox({
17 text("FTXUI: Una potente biblioteca para construir interfaces de usuario."),
18 text("Disfruta de un rico conjunto de componentes y un estilo declarativo."),
19 text("Crea UIs hermosas y responsivas con un mínimo esfuerzo."),
20 text("Únete a la comunidad y experimenta el poder de FTXUI."),
21 });
22}
23
24int main() {
26
27 auto quit =
28 Button("Quit", screen.ExitLoopClosure(), ButtonOption::Animated());
29
30 int selection_change_counter = 0;
31 std::string selection_content = "";
32 screen.SelectionChange([&] {
33 selection_change_counter++;
34 selection_content = screen.GetSelection();
35 });
36
37 // Los componentes:
38 auto renderer = Renderer(quit, [&] {
39 return vbox({
40 text("Selección cambiada: " + std::to_string(selection_change_counter) +
41 " veces"),
42 text("Actualmente seleccionado: "),
43 paragraph(selection_content) | vscroll_indicator | frame | border |
44 size(HEIGHT, EQUAL, 10),
45 window(text("División horizontal"), hbox({
46 LoremIpsum(),
47 separator(),
48 LoremIpsum(),
49 separator(),
50 LoremIpsum(),
51 })),
52 window(text("División vertical"), vbox({
53 LoremIpsum(),
54 separator(),
55 LoremIpsum(),
56 separator(),
57 LoremIpsum(),
58 })),
59 window(text("División en cuadrícula con estilo diferente"),
60 vbox({
61 hbox({
62 LoremIpsum(),
63 separator(),
64 LoremIpsum() //
68 separator(),
70 }),
71 separator(),
72 hbox({
74 separator(),
75 LoremIpsum() | selectionStyle([](Pixel& pixel) {
76 pixel.underlined_double = true;
77 }),
78 separator(),
79 LoremIpsum(),
80 }),
81 })),
82 quit->Render(),
83 });
84 });
85
86 screen.Loop(renderer);
87}
auto screen
Element LoremIpsum()
static ScreenInteractive TerminalOutput()
static ButtonOption Animated()
Component Button(ButtonOption options)
Dibuja un botón. Ejecuta una función al hacer clic.
Component Renderer(Component child, std::function< Element()>)
Retorna un nuevo Componente, similar a |child|, pero usando |render| como el evento Component::Render...
virtual void Render(Screen &screen)
Muestra un elemento en un ftxui::Screen.
Definition node.cpp:59
Element window(Element title, Element content, BorderStyle border=ROUNDED)
Draw window with a title and a border around the element.
Decorator size(WidthOrHeight, Constraint, int value)
Aplica una restricción al tamaño de un elemento.
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.
bool underlined_double
Definition pixel.hpp:34
Un carácter Unicode y su estilo asociado.
Definition pixel.hpp:15
El espacio de nombres ftxui:: de FTXUI.
Definition animation.hpp:10
std::shared_ptr< Node > Element
Definition elements.hpp:22
Decorator selectionStyle(std::function< void(Pixel &)> style)
Establece el estilo de un elemento cuando está seleccionado.
Element hbox(Elements)
Un contenedor que muestra elementos horizontalmente uno por uno.
Definition hbox.cpp:94
Decorator selectionBackgroundColor(Color foreground)
Establece el color de fondo de un elemento cuando está seleccionado. Tenga en cuenta que el estilo se...
Element vbox(Elements)
Decorator selectionColor(Color foreground)
Establece el color de un elemento cuando está seleccionado.
Element selectionStyleReset(Element)
Restablece el estilo de selección de un elemento.
Elements paragraph(std::wstring text)