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
14 using namespace ftxui;
15
16 Element 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
21 Element 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
29 int 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 = ScreenInteractive::TerminalOutput();
60 screen.Loop(renderer);
61}
captured_mouse.hpp
color.hpp
component.hpp
component_base.hpp
elements.hpp
ftxui::ScreenInteractive::TerminalOutput
static ScreenInteractive TerminalOutput()
Definition screen_interactive.cpp:410
ftxui::Renderer
Component Renderer(Component child, std::function< Element()>)
Return a new Component, similar to |child|, but using |render| as the Component::Render() event.
Definition src/ftxui/component/renderer.cpp:61
ftxui::Container::Vertical
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
ftxui::Node::Render
virtual void Render(Screen &screen)
Display an element on a ftxui::Screen.
Definition node.cpp:59
ftxui::bgcolor
Decorator bgcolor(Color)
Decorate using a background color.
Definition dom/color.cpp:124
ftxui::size
Decorator size(WidthOrHeight, Constraint, int value)
Apply a constraint on the size of an element.
Definition src/ftxui/dom/size.cpp:89
ftxui::text
Element text(std::wstring text)
Display a piece of unicode text.
Definition text.cpp:160
ftxui::separator
Element separator()
Draw a vertical or horizontal separation in between two other elements.
Definition src/ftxui/dom/separator.cpp:134
ftxui::vbox
Element vbox(Elements)
A container displaying elements vertically one by one.
Definition vbox.cpp:96
ftxui::Color::RGB
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 screen/color.cpp:147
ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
ftxui::HEIGHT
@ HEIGHT
Definition elements.hpp:161
ftxui::WIDTH
@ WIDTH
Definition elements.hpp:161
ftxui::Element
std::shared_ptr< Node > Element
Definition elements.hpp:22
ftxui::hbox
Element hbox(Elements)
A container displaying elements horizontally one by one.
Definition hbox.cpp:94
ftxui::Slider
Component Slider(SliderOption< T > options)
A slider in any direction.
Definition src/ftxui/component/slider.cpp:346
ftxui::LESS_THAN
@ LESS_THAN
Definition elements.hpp:162
ftxui::GREATER_THAN
@ GREATER_THAN
Definition elements.hpp:162
screen_interactive.hpp
ColorTile
Element ColorTile(int red, int green, int blue)
Definition slider_rgb.cpp:16
ColorString
Element ColorString(int red, int green, int blue)
Definition slider_rgb.cpp:21
main
int main()
Definition slider_rgb.cpp:29