FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
examples/component/renderer.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 <memory> // for shared_ptr, allocator, __shared_ptr_access
5
6#include "ftxui/component/captured_mouse.hpp" // for ftxui
7#include "ftxui/component/component.hpp" // for Renderer, Button, Vertical
8#include "ftxui/component/component_base.hpp" // for ComponentBase
9#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
10#include "ftxui/dom/elements.hpp" // for operator|, Element, text, bold, border, center, color
11#include "ftxui/screen/color.hpp" // for Color, Color::Red
12
13int main() {
14 using namespace ftxui;
15 auto screen = ScreenInteractive::FitComponent();
16
17 // Un Renderer() es un componente que utiliza una función lambda como parámetro para
18 // renderizarse a sí mismo.
19
20 // 1. Ejemplo de renderizador enfocable:
21 auto renderer_focusable = Renderer([](bool focused) {
22 if (focused) {
23 return text("FOCUSABLE RENDERER()") | center | bold | border;
24 } else {
25 return text(" Focusable renderer() ") | center | border;
26 }
27 });
28
29 // 2. Ejemplos de renderizador no enfocable.
30 auto renderer_non_focusable = Renderer([&] {
31 return text("~~~~~ Non Focusable renderer() ~~~~~"); //
32 });
33
34 // 3. Renderer puede envolver otros componentes para redefinir su función Render().
35 auto button = Button("Wrapped quit button", screen.ExitLoopClosure());
36 auto renderer_wrap = Renderer(button, [&] {
37 if (button->Focused()) {
38 return button->Render() | bold | color(Color::Red);
39 } else {
40 return button->Render();
41 }
42 });
43
44 // Vamos a renderizar a todos:
45 screen.Loop(Container::Vertical({
46 renderer_focusable,
47 renderer_non_focusable,
48 renderer_wrap,
49 }));
50}
auto screen
El espacio de nombres ftxui:: de FTXUI.
Definition animation.hpp:10