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()は、自身の描画のためにラムダ関数をパラメータとして使用するコンポーネントです。
18
19 // 1. フォーカス可能なRendererの例:
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. フォーカス不可能なRendererの例。
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}
FTXUI ftxui::名前空間
Definition animation.hpp:11