FTXUI 6.1.9
C++ functional terminal UI.
Chargement...
Recherche...
Aucune correspondance
dom/color.cpp
Aller à la documentation de ce fichier.
1// Copyright 2020 Arthur Sonzogni. Tous droits réservés.
2// L'utilisation de ce code source est régie par la licence MIT qui peut être trouvée dans
3// le fichier LICENSE.
4#include <memory> // for make_shared
5#include <utility> // for move
6
7#include "ftxui/dom/elements.hpp" // for Element, Decorator, bgcolor, color
8#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
9#include "ftxui/screen/box.hpp" // for Box
10#include "ftxui/screen/color.hpp" // for Color
11#include "ftxui/screen/screen.hpp" // for Pixel, Screen
12
13namespace ftxui {
14
15namespace {
16class BgColor : public NodeDecorator {
17 public:
18 BgColor(Element child, Color color)
19 : NodeDecorator(std::move(child)), color_(color) {}
20
21 void Render(Screen& screen) override {
22 if (color_.IsOpaque()) {
23 for (int y = box_.y_min; y <= box_.y_max; ++y) {
24 for (int x = box_.x_min; x <= box_.x_max; ++x) {
25 screen.PixelAt(x, y).background_color = color_;
26 }
27 }
28 } else {
29 for (int y = box_.y_min; y <= box_.y_max; ++y) {
30 for (int x = box_.x_min; x <= box_.x_max; ++x) {
31 Color& color = screen.PixelAt(x, y).background_color;
32 color = Color::Blend(color, color_);
33 }
34 }
35 }
37 }
38
39 Color color_;
40};
41
42class FgColor : public NodeDecorator {
43 public:
44 FgColor(Element child, Color color)
45 : NodeDecorator(std::move(child)), color_(color) {}
46
47 void Render(Screen& screen) override {
48 if (color_.IsOpaque()) {
49 for (int y = box_.y_min; y <= box_.y_max; ++y) {
50 for (int x = box_.x_min; x <= box_.x_max; ++x) {
51 screen.PixelAt(x, y).foreground_color = color_;
52 }
53 }
54 } else {
55 for (int y = box_.y_min; y <= box_.y_max; ++y) {
56 for (int x = box_.x_min; x <= box_.x_max; ++x) {
57 Color& color = screen.PixelAt(x, y).foreground_color;
58 color = Color::Blend(color, color_);
59 }
60 }
61 }
63 }
64
66};
67
68} // namespace
69
70/// @brief Définit la couleur de premier plan d'un élément.
71/// @param color La couleur de l'élément de sortie.
72/// @param child L'élément d'entrée.
73/// @return L'élément de sortie coloré.
74/// @ingroup dom
75///
76/// ### Exemple
77///
78/// ```cpp
79/// Element document = color(Color::Green, text("Success")),
80/// ```
81Element color(Color color, Element child) {
82 return std::make_shared<FgColor>(std::move(child), color);
83}
84
85/// @brief Définit la couleur d'arrière-plan d'un élément.
86/// @param color La couleur de l'élément de sortie.
87/// @param child L'élément d'entrée.
88/// @return L'élément de sortie coloré.
89/// @ingroup dom
90///
91/// ### Exemple
92///
93/// ```cpp
94/// Element document = bgcolor(Color::Green, text("Success")),
95/// ```
97 return std::make_shared<BgColor>(std::move(child), color);
98}
99
100/// @brief Décore en utilisant une couleur de premier plan.
101/// @param c La couleur de premier plan à appliquer.
102/// @return Le Decorator appliquant la couleur.
103/// @ingroup dom
104///
105/// ### Exemple
106///
107/// ```cpp
108/// Element document = text("red") | color(Color::Red);
109/// ```
111 return [c](Element child) { return color(c, std::move(child)); };
112}
113
114/// @brief Décore en utilisant une couleur d'arrière-plan.
115/// @param color La couleur d'arrière-plan à appliquer.
116/// @return Le Decorator appliquant la couleur.
117/// @ingroup dom
118///
119/// ### Exemple
120///
121/// ```cpp
122/// Element document = text("red") | bgcolor(Color::Red);
123/// ```
125 return [color](Element child) { return bgcolor(color, std::move(child)); };
126}
127
128} // namespace ftxui
auto screen
friend void Render(Screen &screen, Node *node, Selection &selection)
Decorator bgcolor(Color)
Décore en utilisant une couleur d'arrière-plan.
Decorator color(Color)
Décore en utilisant une couleur de premier plan.
static Color Blend(const Color &lhs, const Color &rhs)
Mélange deux couleurs en utilisant le canal alpha.
Color est une classe qui représente une couleur dans l'interface utilisateur du terminal.
Definition color.hpp:21
Color
Color est une énumération qui représente le support des couleurs du terminal.
Definition terminal.hpp:23
L'espace de noms FTXUI ftxui::
Definition animation.hpp:10
std::function< Element(Element)> Decorator
Definition elements.hpp:24
std::shared_ptr< Node > Element
Definition elements.hpp:22
void Render(Screen &screen, const Element &element)