FTXUI 7.0.3
C++ functional terminal UI.
Loading...
Searching...
No Matches
composition.cpp
Go to the documentation of this file.
1// Copyright 2021 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 operator+, to_string
6
7#include "ftxui/component/app.hpp" // for App
8#include "ftxui/component/captured_mouse.hpp" // for ftxui
9#include "ftxui/component/component.hpp" // for Button, Horizontal, Renderer
10#include "ftxui/component/component_base.hpp" // for ComponentBase
11#include "ftxui/dom/elements.hpp" // for text, separator, Element, operator|, vbox, border
12
13using namespace ftxui;
14
15// 複数のコンポーネントを1つに合成し、それらのインタラクティブ性を
16// 維持する方法の例。
17int main() {
18 auto left_count = 0;
19 auto right_count = 0;
20
21 auto left_buttons = Container::Horizontal({
22 Button("Decrease", [&] { left_count--; }),
23 Button("Increase", [&] { left_count++; }),
24 });
25
26 auto right_buttons = Container::Horizontal({
27 Button("Decrease", [&] { right_count--; }),
28 Button("Increase", [&] { right_count++; }),
29 });
30
31 // Rendererは、その子を新しいレンダリング関数で装飾します。子がイベントに反応する方法は維持されます。
32 auto leftpane = Renderer(left_buttons, [&] {
33 return vbox({
34 text("This is the left control"),
35 separator(),
36 text("Left button count: " + std::to_string(left_count)),
37 left_buttons->Render(),
38 }) |
39 border;
40 });
41
42 auto rightpane = Renderer(right_buttons, [&] {
43 return vbox({
44 text("This is the right control"),
45 separator(),
46 text("Right button count: " + std::to_string(right_count)),
47 right_buttons->Render(),
48 }) |
49 border;
50 });
51
52 // Containerはコンポーネントをグループ化します。Container::Horizontalを
53 // レンダリングすると、その子を横に並べて表示します。これは子の
54 // インタラクティブ性を維持し、矢印キーを使って1つから別のものへ
55 // 移動するロジックを提供します。
56 auto composition = Container::Horizontal({leftpane, rightpane});
57
58 auto screen = App::FitComponent();
59 screen.Loop(composition);
60 return 0;
61}
62
63// この例を提供してくれたChris Morganに感謝します!
int main()
Component Button(ConstStringRef label, std::function< void()> on_click, ButtonOption options=ButtonOption::Simple())
クリックすると関数を実行するボタンを描画します。
Component Renderer(Component child, std::function< Element()>)
|child| に似た、|render| をComponent::Render()イベントとして 使用する新しいComponentを返します。
Element text(std::string_view text)
UTF8エンコードされたユニコードテキストを表示します。
Element vbox(Elements children)
要素を縦に一つずつ表示するコンテナ。
Definition vbox.cpp:95
FTXUI ftxui::名前空間
Definition animation.hpp:11