FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
slider_rgb.cpp
Go to the documentation of this file.
1// 版權所有 2020 Arthur Sonzogni. 保留所有權利。
2// 本原始碼的使用受 MIT 授權條款約束,該條款可在 LICENSE 檔案中找到。
3#include <memory> // for allocator, shared_ptr, __shared_ptr_access
4#include <string> // for char_traits, operator+, to_string
5
6#include "ftxui/component/captured_mouse.hpp" // for ftxui
7#include "ftxui/component/component.hpp" // for Slider, Renderer, Vertical
8#include "ftxui/component/component_base.hpp" // for ComponentBase
9#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
10#include "ftxui/dom/elements.hpp" // for separator, operator|, Element, size, text, vbox, xflex, bgcolor, hbox, GREATER_THAN, WIDTH, border, HEIGHT, LESS_THAN
11#include "ftxui/screen/color.hpp" // for Color
12
13using namespace ftxui;
14
15Element ColorTile(int red, int green, int blue) {
16 return text("") | size(WIDTH, GREATER_THAN, 14) |
17 size(HEIGHT, GREATER_THAN, 7) | bgcolor(Color::RGB(red, green, blue));
18}
19
20Element ColorString(int red, int green, int blue) {
21 return text("RGB = (" + //
22 std::to_string(red) + "," + //
23 std::to_string(green) + "," + //
24 std::to_string(blue) + ")" //
25 );
26}
27
28int main() {
29 int red = 128;
30 int green = 25;
31 int blue = 100;
32 auto slider_red = Slider("Red :", &red, 0, 255, 1);
33 auto slider_green = Slider("Green:", &green, 0, 255, 1);
34 auto slider_blue = Slider("Blue :", &blue, 0, 255, 1);
35
36 auto container = Container::Vertical({
37 slider_red,
38 slider_green,
39 slider_blue,
40 });
41
42 auto renderer = Renderer(container, [&] {
43 return hbox({
44 ColorTile(red, green, blue),
45 separator(),
46 vbox({
47 slider_red->Render(),
48 separator(),
49 slider_green->Render(),
50 separator(),
51 slider_blue->Render(),
52 separator(),
53 ColorString(red, green, blue),
54 }) | xflex,
55 }) |
56 border | size(WIDTH, LESS_THAN, 80);
57 });
59 screen.Loop(renderer);
60}
static ScreenInteractive TerminalOutput()
Component Renderer(Component child, std::function< Element()>)
回傳一個新的元件,類似於 |child|,但使用 |render| 作為 Component::Render() 事件。
virtual void Render(Screen &screen)
Decorator bgcolor(Color)
使用背景顏色進行裝飾。
Decorator size(WidthOrHeight, Constraint, int value)
限制元素的大小。
Element text(std::wstring text)
顯示一段 Unicode 文字。
Definition text.cpp:160
Element separator()
在兩個元素之間繪製垂直或水平分隔線。
Element vbox(Elements)
一個垂直一個接一個顯示元素的容器。
Definition vbox.cpp:95
static Color RGB(uint8_t red, uint8_t green, uint8_t blue)
從 RGB 表示建立一個顏色。 https://en.wikipedia.org/wiki/RGB_color_model
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10
std::shared_ptr< Node > Element
Definition elements.hpp:22
Element hbox(Elements)
一個逐一水平顯示元素的容器。
Definition hbox.cpp:94
Component Slider(SliderOption< T > options)
@ LESS_THAN
Definition elements.hpp:159
@ GREATER_THAN
Definition elements.hpp:159
Element ColorTile(int red, int green, int blue)
Element ColorString(int red, int green, int blue)
int main()