FTXUI 6.1.9
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/captured_mouse.hpp" // for ftxui
8#include "ftxui/component/component.hpp" // for Slider, Renderer, Vertical
9#include "ftxui/component/component_base.hpp" // for ComponentBase
10#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
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 });
60 screen.Loop(renderer);
61}
static ScreenInteractive TerminalOutput()
Component Renderer(Component child, std::function< Element()>)
Return a new Component, similar to |child|, but using |render| as the Component::Render() event.
Component Vertical(Components children)
A list of components, drawn one by one vertically and navigated vertically using up/down arrow key or...
virtual void Render(Screen &screen)
Display an element on a ftxui::Screen.
Definition node.cpp:59
Decorator bgcolor(Color)
Decorate using a background color.
Decorator size(WidthOrHeight, Constraint, int value)
Apply a constraint on the size of an element.
Element text(std::wstring text)
Display a piece of unicode text.
Definition text.cpp:160
Element separator()
Draw a vertical or horizontal separation in between two other elements.
Element vbox(Elements)
A container displaying elements vertically one by one.
Definition vbox.cpp:96
static Color RGB(uint8_t red, uint8_t green, uint8_t blue)
Build a Color from its RGB representation. https://en.wikipedia.org/wiki/RGB_color_model.
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
std::shared_ptr< Node > Element
Definition elements.hpp:22
Element hbox(Elements)
A container displaying elements horizontally one by one.
Definition hbox.cpp:94
Component Slider(SliderOption< T > options)
A slider in any direction.
@ LESS_THAN
Definition elements.hpp:162
@ GREATER_THAN
Definition elements.hpp:162
Element ColorTile(int red, int green, int blue)
Element ColorString(int red, int green, int blue)
int main()