FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
examples/component/input_style.cpp
// Copyright 2020 Arthur Sonzogni. Todos los derechos reservados.
// El uso de este código fuente se rige por la licencia MIT que se puede encontrar en
// el archivo LICENSE.
#include <ftxui/dom/linear_gradient.hpp> // para LinearGradient
#include <ftxui/screen/color.hpp> // para Color, Color::White, Color::Red, Color::Blue, Color::Black, Color::GrayDark, ftxui
#include <functional> // para function
#include <string> // para allocator, string
#include <utility> // para move
#include "ftxui/component/component.hpp" // para Input, Horizontal, Vertical, operator|
#include "ftxui/component/component_base.hpp" // para Component
#include "ftxui/component/component_options.hpp" // para InputState, InputOption
#include "ftxui/component/screen_interactive.hpp" // para ScreenInteractive
#include "ftxui/dom/elements.hpp" // para operator|=, Element, bgcolor, operator|, separatorEmpty, color, borderEmpty, separator, text, center, dim, hbox, vbox, border, borderDouble, borderRounded
int main() {
using namespace ftxui;
InputOption style_1 = InputOption::Default();
InputOption style_2 = InputOption::Spacious();
InputOption style_3 = InputOption::Spacious();
style_3.transform = [](InputState state) {
state.element |= borderEmpty;
if (state.is_placeholder) {
state.element |= dim;
}
if (state.focused) {
state.element |= borderDouble;
state.element |= bgcolor(Color::White);
state.element |= color(Color::Black);
} else if (state.hovered) {
state.element |= borderRounded;
state.element |= bgcolor(LinearGradient(90, Color::Blue, Color::Red));
state.element |= color(Color::White);
} else {
state.element |= border;
state.element |= bgcolor(LinearGradient(0, Color::Blue, Color::Red));
state.element |= color(Color::White);
}
return state.element;
};
InputOption style_4 = InputOption::Spacious();
style_4.transform = [](InputState state) {
state.element = hbox({
text("Theorem") | center | borderEmpty | bgcolor(Color::Red),
separatorEmpty(),
separator() | color(Color::White),
separatorEmpty(),
std::move(state.element),
});
state.element |= borderEmpty;
if (state.is_placeholder) {
state.element |= dim;
}
if (state.focused) {
state.element |= bgcolor(Color::Black);
} else {
state.element |= bgcolor(Color::Blue);
}
if (state.hovered) {
state.element |= bgcolor(Color::GrayDark);
}
return vbox({state.element, separatorEmpty()});
};
auto generateUiFromStyle = [&](InputOption style) {
auto first_name = new std::string(); // Filtrado
auto middle_name = new std::string(); // Filtrado
auto last_name = new std::string(); // Filtrado
return Container::Vertical({
Input(first_name, "first name", style),
Input(middle_name, "middle name", style),
Input(last_name, "last name", style),
}) |
borderEmpty;
};
auto ui = Container::Horizontal({
generateUiFromStyle(style_1),
generateUiFromStyle(style_2),
generateUiFromStyle(style_3),
generateUiFromStyle(style_4),
});
auto screen = ScreenInteractive::TerminalOutput();
screen.Loop(ui);
}
auto screen
std::function< Element(InputState)> transform
Opción para el componente Input.
Element vbox(Elements children)
Un contenedor que muestra elementos verticalmente uno por uno.
Definition vbox.cpp:95
Una clase que representa la configuración para el efecto de color de gradiente lineal.
return hbox({ text(std::to_string(int(progress *100))+"% ")|size(WIDTH, EQUAL, 5), gauge(progress), })
El espacio de nombres ftxui:: de FTXUI.
Definition animation.hpp:10
Usado para definir el estilo del componente Input.