FTXUI 6.1.9
C++ functional terminal UI.
Chargement...
Recherche...
Aucune correspondance
slider_rgb.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
3// dans le fichier LICENSE.
4#include <memory> // pour allocator, shared_ptr, __shared_ptr_access
5#include <string> // pour char_traits, operator+, to_string
6
7#include "ftxui/component/captured_mouse.hpp" // pour ftxui
8#include "ftxui/component/component.hpp" // pour Slider, Renderer, Vertical
9#include "ftxui/component/component_base.hpp" // pour ComponentBase
10#include "ftxui/component/screen_interactive.hpp" // pour ScreenInteractive
11#include "ftxui/dom/elements.hpp" // pour separator, operator|, Element, size, text, vbox, xflex, bgcolor, hbox, GREATER_THAN, WIDTH, border, HEIGHT, LESS_THAN
12#include "ftxui/screen/color.hpp" // pour Color
13
14using namespace ftxui;
15
16Element ColorTile(int red, int green, int blue) {
17 return text("") | size(WIDTH, GREATER_THAN, 14) |
18 size(HEIGHT, GREATER_THAN, 7) | bgcolor(Color::RGB(red, green, blue));
19}
20
21Element ColorString(int red, int green, int blue) {
22 return text("RGB = (" + //
23 std::to_string(red) + "," + //
24 std::to_string(green) + "," + //
25 std::to_string(blue) + ")" //
26 );
27}
28
29int main() {
30 int red = 128;
31 int green = 25;
32 int blue = 100;
33 auto slider_red = Slider("Red :", &red, 0, 255, 1);
34 auto slider_green = Slider("Green:", &green, 0, 255, 1);
35 auto slider_blue = Slider("Blue :", &blue, 0, 255, 1);
36
37 auto container = Container::Vertical({
38 slider_red,
39 slider_green,
40 slider_blue,
41 });
42
43 auto renderer = Renderer(container, [&] {
44 return hbox({
45 ColorTile(red, green, blue),
46 separator(),
47 vbox({
48 slider_red->Render(),
49 separator(),
50 slider_green->Render(),
51 separator(),
52 slider_blue->Render(),
53 separator(),
54 ColorString(red, green, blue),
55 }) | xflex,
56 }) |
57 border | size(WIDTH, LESS_THAN, 80);
58 });
60 screen.Loop(renderer);
61}
auto screen
static ScreenInteractive TerminalOutput()
Component Renderer(Component child, std::function< Element()>)
Renvoie un nouveau composant, similaire à |child|, mais utilisant |render| comme événement Component:...
virtual void Render(Screen &screen)
Decorator bgcolor(Color)
Décore en utilisant une couleur d'arrière-plan.
Decorator size(WidthOrHeight, Constraint, int value)
Applique une contrainte sur la taille d'un élément.
Element text(std::wstring text)
Affiche un morceau de texte unicode.
Definition text.cpp:160
Element separator()
Dessine une séparation verticale ou horizontale entre deux autres éléments.
Element vbox(Elements)
Un conteneur affichant les éléments verticalement un par un.
Definition vbox.cpp:96
static Color RGB(uint8_t red, uint8_t green, uint8_t blue)
Construit une couleur à partir de sa représentation RGB. https://en.wikipedia.org/wiki/RGB_color_mode...
L'espace de noms FTXUI ftxui::
Definition animation.hpp:10
std::shared_ptr< Node > Element
Definition elements.hpp:22
Element hbox(Elements)
Un conteneur affichant les éléments horizontalement un par un.
Definition hbox.cpp:94
Component Slider(SliderOption< T > options)
Un curseur dans n'importe quelle direction.
@ LESS_THAN
Definition elements.hpp:161
@ GREATER_THAN
Definition elements.hpp:161
Element ColorTile(int red, int green, int blue)
Element ColorString(int red, int green, int blue)
int main()