FTXUI 7.0.3
C++ functional terminal UI.
Loading...
Searching...
No Matches
slider_rgb.cpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4#include <memory> // for allocator, shared_ptr, __shared_ptr_access
5#include <string> // for char_traits, operator+, to_string
6
7#include "ftxui/component/app.hpp" // for App
8#include "ftxui/component/captured_mouse.hpp" // for ftxui
9#include "ftxui/component/component.hpp" // for Slider, Renderer, Vertical
10#include "ftxui/component/component_base.hpp" // for ComponentBase
11#include "ftxui/dom/elements.hpp" // for separator, operator|, Element, size, text, vbox, xflex, bgcolor, hbox, GREATER_THAN, WIDTH, border, HEIGHT, LESS_THAN
12#include "ftxui/screen/color.hpp" // for 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 });
59 auto screen = App::TerminalOutput();
60 screen.Loop(renderer);
61}
Component Renderer(Component child, std::function< Element()>)
Retourne un nouveau Component, similaire à |child|, mais utilisant |render| comme événement Component...
Element text(std::string_view text)
Affiche un morceau de texte unicode encodé en UTF8.
Decorator size(WidthOrHeight direction, Constraint constraint, int value)
Applique une contrainte sur la taille d'un élément.
Element bgcolor(Color color, Element child)
Définit la couleur d'arrière-plan d'un élément.
Definition dom/color.cpp:96
Element separator()
Dessine une séparation verticale ou horizontale entre deux autres éléments.
Element vbox(Elements children)
Un conteneur affichant les éléments verticalement un par un.
Definition vbox.cpp:96
L'espace de noms FTXUI ftxui::
Definition animation.hpp:11
@ LESS_THAN
Definition elements.hpp:194
@ GREATER_THAN
Definition elements.hpp:194
std::shared_ptr< Node > Element
Definition elements.hpp:25
Element hbox(Elements children)
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.
Element ColorTile(int red, int green, int blue)
Element ColorString(int red, int green, int blue)
int main()