FTXUI  5.0.0
C++ functional terminal UI.
examples/component/slider_rgb.cpp
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#include <memory> // for allocator, shared_ptr, __shared_ptr_access
#include <string> // for char_traits, operator+, to_string
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Slider, Renderer, Vertical
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
#include "ftxui/dom/elements.hpp" // for separator, operator|, Element, size, text, vbox, xflex, bgcolor, hbox, GREATER_THAN, WIDTH, border, HEIGHT, LESS_THAN
#include "ftxui/screen/color.hpp" // for Color
using namespace ftxui;
Element ColorTile(int red, int green, int blue) {
return text("") | size(WIDTH, GREATER_THAN, 14) |
size(HEIGHT, GREATER_THAN, 7) | bgcolor(Color::RGB(red, green, blue));
}
Element ColorString(int red, int green, int blue) {
return text("RGB = (" + //
std::to_string(red) + "," + //
std::to_string(green) + "," + //
std::to_string(blue) + ")" //
);
}
int main() {
int red = 128;
int green = 25;
int blue = 100;
auto slider_red = Slider("Red :", &red, 0, 255, 1);
auto slider_green = Slider("Green:", &green, 0, 255, 1);
auto slider_blue = Slider("Blue :", &blue, 0, 255, 1);
auto container = Container::Vertical({
slider_red,
slider_green,
slider_blue,
});
auto renderer = Renderer(container, [&] {
return hbox({
ColorTile(red, green, blue),
vbox({
slider_red->Render(),
slider_green->Render(),
slider_blue->Render(),
ColorString(red, green, blue),
}) | xflex,
}) |
});
screen.Loop(renderer);
}
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.
Definition: color.cpp:139
static ScreenInteractive TerminalOutput()
Component Vertical(Components children)
A list of components, drawn one by one vertically and navigated vertically using up/down arrow key or...
Definition: container.cpp:317
Decorator bgcolor(Color)
Decorate using a background color.
Definition: color.cpp:105
@ HEIGHT
Definition: elements.hpp:150
@ WIDTH
Definition: elements.hpp:150
Element xflex(Element)
Expand/Minimize if possible/needed on the X axis.
Definition: flex.cpp:129
Decorator size(WidthOrHeight, Constraint, int value)
Apply a constraint on the size of an element.
Definition: size.cpp:90
std::shared_ptr< Node > Element
Definition: elements.hpp:23
Component Renderer(Component child, std::function< Element()>)
Return a new Component, similar to |child|, but using |render| as the Component::Render() event.
Definition: renderer.cpp:63
Element hbox(Elements)
A container displaying elements horizontally one by one.
Definition: hbox.cpp:83
std::string to_string(const std::wstring &s)
Convert a UTF8 std::string into a std::wstring.
Definition: string.cpp:1565
Element text(std::wstring text)
Display a piece of unicode text.
Definition: text.cpp:120
Component Slider(SliderOption< T > options)
A slider in any direction.
Definition: slider.cpp:341
Element separator()
Draw a vertical or horizontal separation in between two other elements.
Definition: separator.cpp:132
@ LESS_THAN
Definition: elements.hpp:151
@ GREATER_THAN
Definition: elements.hpp:151
Element border(Element)
Draw a border around the element.
Definition: border.cpp:227
Element vbox(Elements)
A container displaying elements vertically one by one.
Definition: vbox.cpp:83