FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
menu_underline_animated_gallery.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 <chrono> // for operator""ms, literals
5#include <memory> // for allocator, shared_ptr, __shared_ptr_access
6#include <string> // for string, operator+, to_string, basic_string
7#include <vector> // for vector
8
9#include "ftxui/component/animation.hpp" // for BackOut, Duration
10#include "ftxui/component/component.hpp" // for Menu, Renderer, Vertical
11#include "ftxui/component/component_base.hpp" // for ComponentBase
12#include "ftxui/component/component_options.hpp" // for MenuOption, UnderlineOption
13#include "ftxui/component/mouse.hpp" // for ftxui
14#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
15#include "ftxui/dom/elements.hpp" // for text, Element, operator|, borderEmpty, inverted
16#include "ftxui/screen/color.hpp" // for Color, Color::Blue, Color::Red
17
18using namespace ftxui;
19
21 return Renderer([id](bool focused) {
22 auto t = text("component " + std::to_string(id));
23 if (focused) {
24 t = t | inverted;
25 }
26 return t;
27 });
28}
29
30Component Text(const std::string& t) {
31 return Renderer([t] { return text(t) | borderEmpty; });
32}
33
34int main() {
35 using namespace std::literals;
36 std::vector<std::string> tab_values{
37 "Tab 1", "Tab 2", "Tab 3", "A very very long tab", "탭",
38 };
39 int tab_selected = 0;
40
41 auto container = Container::Vertical({});
42
43 int frame_count = 0;
44 container->Add(Renderer(
45 [&] { return text("Frame count: " + std::to_string(frame_count++)); }));
46
47 {
48 auto option = MenuOption::HorizontalAnimated();
49 container->Add(Text("Esto demuestra el componente Menu"));
50 container->Add(Menu(&tab_values, &tab_selected, option));
51 }
52
53 {
54 container->Add(Text("Establecer color de subrayado en azul"));
55 auto option = MenuOption::HorizontalAnimated();
56 option.underline.color_inactive = Color::Blue;
57 container->Add(Menu(&tab_values, &tab_selected, option));
58 }
59
60 {
61 container->Add(Text("Establecer color activo de subrayado en rojo"));
62 auto option = MenuOption::HorizontalAnimated();
63 option.underline.color_active = Color::Red;
64 container->Add(Menu(&tab_values, &tab_selected, option));
65 }
66
67 {
68 container->Add(Text("Establecer duración de la animación en 0ms"));
69 auto option = MenuOption::HorizontalAnimated();
70 option.underline.SetAnimationDuration(0ms);
71 container->Add(Menu(&tab_values, &tab_selected, option));
72 }
73
74 {
75 container->Add(Text("Establecer función de aceleración de animación a back-out"));
76 auto option = MenuOption::HorizontalAnimated();
77 option.underline.SetAnimationFunction(animation::easing::BackOut);
78 option.underline.SetAnimationDuration(350ms);
79 container->Add(Menu(&tab_values, &tab_selected, option));
80 }
81
82 // option.underline_animation_follower_delay = 250ms
83 {
84 container->Add(Text("Añadir retraso para desincronizar la animación"));
85 auto option = MenuOption::HorizontalAnimated();
86 option.underline.follower_delay = 250ms;
87 container->Add(Menu(&tab_values, &tab_selected, option));
88 }
89
90 container->SetActiveChild(container->ChildAt(2));
91
93 screen.Loop(container);
94}
auto screen
static ScreenInteractive TerminalOutput()
void Add(Component children)
Agrega un hijo. @param child El hijo a adjuntar.
Definition component.cpp:70
static MenuOption HorizontalAnimated()
Opciones estándar para un menú horizontal animado. Esto puede ser útil para implementar una barra de ...
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...
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 borderEmpty(Element)
Draw an empty border around the element.
El espacio de nombres ftxui:: de FTXUI.
Definition animation.hpp:10
std::shared_ptr< ComponentBase > Component