FTXUI 6.1.9
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// このソースコードの使用は、LICENSE ファイルにあるMITライセンスによって管理されています。
3#include <memory> // for allocator, shared_ptr, __shared_ptr_access
4#include <string> // for operator+, to_string
5
6#include "ftxui/component/captured_mouse.hpp" // for ftxui
7#include "ftxui/component/component.hpp" // for Button, Horizontal, Renderer
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 text, separator, Element, operator|, vbox, border
11
12using namespace ftxui;
13
14// 複数のコンポーネントを1つにまとめ、それらの対話性を維持する方法の例。
15int main() {
16 auto left_count = 0;
17 auto right_count = 0;
18
19 auto left_buttons = Container::Horizontal({
20 Button("Decrease", [&] { left_count--; }),
21 Button("Increase", [&] { left_count++; }),
22 });
23
24 auto right_buttons = Container::Horizontal({
25 Button("Decrease", [&] { right_count--; }),
26 Button("Increase", [&] { right_count++; }),
27 });
28
29 // Rendererは、その子を新しいレンダリング関数で装飾します。子がイベントに反応する方法は維持されます。
30 auto leftpane = Renderer(left_buttons, [&] {
31 return vbox({
32 text("This is the left control"),
33 separator(),
34 text("Left button count: " + std::to_string(left_count)),
35 left_buttons->Render(),
36 }) |
37 border;
38 });
39
40 auto rightpane = Renderer(right_buttons, [&] {
41 return vbox({
42 text("This is the right control"),
43 separator(),
44 text("Right button count: " + std::to_string(right_count)),
45 right_buttons->Render(),
46 }) |
47 border;
48 });
49
50 // コンテナはコンポーネントをグループ化します。Container::Horizontalをレンダリングするには、
51 // その子を横並びにレンダリングします。それらの対話性を維持し、矢印キーを使用してコンポーネント間を移動するロジックを提供します。
52 auto composition = Container::Horizontal({leftpane, rightpane});
53
54 auto screen = ScreenInteractive::FitComponent();
55 screen.Loop(composition);
56 return 0;
57}
58
59// この例を提供してくれたChris Morganに感謝します!
int main()
static ScreenInteractive FitComponent()
描画されるコンポーネントの幅と高さに一致するScreenInteractiveを作成します。
Component Button(ButtonOption options)
Draw a button. Execute a function when clicked. (ja: ボタンを描画します。クリックされたときに機能を実行します。)
Component Renderer(Component child, std::function< Element()>)
|child|に似ていますが、|render|をComponentRender()イベントとして使用する新しいコンポーネントを返します。
virtual void Render(Screen &screen)
要素をftxui::Screenに表示します。
Definition node.cpp:59
Element text(std::wstring text)
ユニコードテキストを表示します。
Definition text.cpp:160
Element vbox(Elements)
要素を縦に一つずつ表示するコンテナ。
Definition vbox.cpp:94
FTXUI ftxui:: 名前空間
Definition animation.hpp:9
Element separator()