FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
selection_style.cpp
Go to the documentation of this file.
1// Copyright 2024 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 <memory> // for make_shared
6#include <utility> // for move
7
8#include "ftxui/dom/elements.hpp" // for Element, Decorator, bgcolor, color
9#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
10#include "ftxui/screen/color.hpp" // for Color
11#include "ftxui/screen/pixel.hpp" // for Pixel
12#include "ftxui/screen/screen.hpp" // for Screen
13
14namespace ftxui {
15
16namespace {
17
18class SelectionStyleReset : public NodeDecorator {
19 public:
20 explicit SelectionStyleReset(Element child)
21 : NodeDecorator(std::move(child)) {}
22
23 void Render(Screen& screen) final {
24 auto old_style = screen.GetSelectionStyle();
25 screen.SetSelectionStyle([](Pixel&) {});
27 screen.SetSelectionStyle(old_style);
28 }
29};
30
31class SelectionStyle : public NodeDecorator {
32 public:
33 SelectionStyle(Element child, const std::function<void(Pixel&)>& style)
34 : NodeDecorator(std::move(child)), style_(style) {}
35
36 void Render(Screen& screen) final {
37 auto old_style = screen.GetSelectionStyle();
38 auto new_style = [&, old_style](Pixel& pixel) {
39 old_style(pixel);
40 style_(pixel);
41 };
42 screen.SetSelectionStyle(new_style);
44 screen.SetSelectionStyle(old_style);
45 }
46
47 std::function<void(Pixel&)> style_;
48};
49
50} // namespace
51
52/// @brief Restablece el estilo de selección de un elemento.
53/// @param child El elemento de entrada.
54/// @return El elemento de salida con el estilo de selección restablecido.
56 return std::make_shared<SelectionStyleReset>(std::move(child));
57}
58
59/// @brief Establece el color de fondo de un elemento cuando está seleccionado.
60/// Tenga en cuenta que el estilo se aplica además del estilo existente.
62 return selectionStyle([foreground](Pixel& pixel) { //
63 pixel.background_color = foreground;
64 });
65}
66
67/// @brief Establece el color de primer plano de un elemento cuando está seleccionado.
68/// Tenga en cuenta que el estilo se aplica además del estilo existente.
70 return selectionStyle([foreground](Pixel& pixel) { //
71 pixel.foreground_color = foreground;
72 });
73}
74
75/// @brief Establece el color de un elemento cuando está seleccionado.
76/// @param foreground El color a aplicar.
77/// Tenga en cuenta que el estilo se aplica además del estilo existente.
79 return selectionForegroundColor(foreground);
80}
81
82/// @brief Establece el estilo de un elemento cuando está seleccionado.
83/// @param style El estilo a aplicar.
84/// Tenga en cuenta que el estilo se aplica además del estilo existente.
85// NOLINTNEXTLINE
86Decorator selectionStyle(std::function<void(Pixel&)> style) {
87 return [style](Element child) -> Element {
88 return std::make_shared<SelectionStyle>(std::move(child), style);
89 };
90}
91
92} // namespace ftxui
auto screen
friend void Render(Screen &screen, Node *node, Selection &selection)
Definition node.cpp:96
void Render(Screen &screen, const Element &element)
Muestra un elemento en un ftxui::Screen.
Definition node.cpp:84
Color foreground_color
Definition pixel.hpp:49
Color background_color
Definition pixel.hpp:48
Color es una clase que representa un color en la interfaz de usuario de la terminal.
Definition color.hpp:21
Un carácter Unicode y su estilo asociado.
Definition pixel.hpp:15
El espacio de nombres ftxui:: de FTXUI.
Definition animation.hpp:10
std::function< Element(Element)> Decorator
Definition elements.hpp:24
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.
Decorator selectionForegroundColor(Color foreground)
Establece el color de primer plano de un elemento cuando está seleccionado. Tenga en cuenta que el es...
Decorator selectionBackgroundColor(Color foreground)
Establece el color de fondo de un elemento cuando está seleccionado. Tenga en cuenta que el estilo se...
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.
std::function< void(Pixel &)> style_