FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
examples/component/renderer.cpp
Go to the documentation of this file.
1// 版權所有 2020 Arthur Sonzogni. 保留所有權利。
2// 本原始碼的使用受 MIT 許可證約束,該許可證可在
3// LICENSE 文件中找到。
4#include <memory> // for shared_ptr, allocator, __shared_ptr_access
5
6#include "ftxui/component/captured_mouse.hpp" // for ftxui
7#include "ftxui/component/component.hpp" // for Renderer, Button, 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 operator|, Element, text, bold, border, center, color
11#include "ftxui/screen/color.hpp" // for Color, Color::Red
12
13int main() {
14 using namespace ftxui;
15 auto screen = ScreenInteractive::FitComponent();
16
17 // Renderer() 是一個組件,它使用 lambda 函數作為參數來
18 // 渲染自己。
19 // 1. 可聚焦渲染器的範例:
20 auto renderer_focusable = Renderer([](bool focused) {
21 if (focused) {
22 return text("FOCUSABLE RENDERER()") | center | bold | border;
23 } else {
24 return text(" Focusable renderer() ") | center | border;
25 }
26 });
27
28 // 2. 不可聚焦渲染器的範例。
29 auto renderer_non_focusable = Renderer([&] {
30 return text("~~~~~ Non Focusable renderer() ~~~~~"); //
31 });
32
33 // 3. Renderer 可以包裝其他組件以重新定義它們的 Render() 函數。
34 auto button = Button("Wrapped quit button", screen.ExitLoopClosure());
35 auto renderer_wrap = Renderer(button, [&] {
36 if (button->Focused()) {
37 return button->Render() | bold | color(Color::Red);
38 } else {
39 return button->Render();
40 }
41 });
42
43 // 讓我們渲染所有組件:
44 screen.Loop(Container::Vertical({
45 renderer_focusable,
46 renderer_non_focusable,
47 renderer_wrap,
48 }));
49}
auto button
Definition gallery.cpp:84
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10