FTXUI 7.0.3
C++ functional terminal UI.
Loading...
Searching...
No Matches
examples/component/renderer.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 shared_ptr, allocator, __shared_ptr_access
5
6#include "ftxui/component/app.hpp" // for App
7#include "ftxui/component/captured_mouse.hpp" // for ftxui
8#include "ftxui/component/component.hpp" // for Renderer, Button, Vertical
9#include "ftxui/component/component_base.hpp" // for ComponentBase
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 = App::FitComponent();
16
17 // Renderer() 是一個組件,它使用 lambda 函數作為參數來
18 // 渲染自己。
19 // 1. 可聚焦渲染器的範例:
20
21 // 1. 可取得焦點的 renderer 範例:
22 auto renderer_focusable = Renderer([](bool focused) {
23 if (focused) {
24 return text("FOCUSABLE RENDERER()") | center | bold | border;
25 } else {
26 return text(" Focusable renderer() ") | center | border;
27 }
28 });
29
30 // 2. 不可取得焦點的 renderer 範例。
31 auto renderer_non_focusable = Renderer([&] {
32 return text("~~~~~ Non Focusable renderer() ~~~~~"); //
33 });
34
35 // 3. Renderer 可以包裝其他組件以重新定義它們的 Render() 函數。
36 auto button = Button("Wrapped quit button", screen.ExitLoopClosure());
37 auto renderer_wrap = Renderer(button, [&] {
38 if (button->Focused()) {
39 return button->Render() | bold | color(Color::Red);
40 } else {
41 return button->Render();
42 }
43 });
44
45 // 讓我們渲染每一個:
46 screen.Loop(Container::Vertical({
47 renderer_focusable,
48 renderer_non_focusable,
49 renderer_wrap,
50 }));
51}
FTXUI ftxui:: 命名空間
Definition animation.hpp:11