FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
modal_dialog.cpp
Go to the documentation of this file.
1// Copyright 2022 Arthur Sonzogni. All rights reserved.
2// このソースコードの使用は、LICENSEファイルにあるMITライセンスに従います。
3#include <ftxui/component/component_options.hpp> // for ButtonOption
4#include <ftxui/component/mouse.hpp> // for ftxui
5#include <functional> // for function
6#include <memory> // for allocator, shared_ptr
7
8#include "ftxui/component/component.hpp" // for Button, operator|=, Renderer, Vertical, Modal
9#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive, Component
10#include "ftxui/dom/elements.hpp" // for operator|, separator, text, size, Element, vbox, border, GREATER_THAN, WIDTH, center, HEIGHT
11
12using namespace ftxui;
13
15
16// メインコンポーネントの定義。詳細は重要ではありません。
17Component MainComponent(std::function<void()> show_modal,
18 std::function<void()> exit) {
19 auto component = Container::Vertical({
20 Button("Show modal", show_modal, button_style),
21 Button("Quit", exit, button_style),
22 });
23 // 2つのボタンの描画を調整します:
24 component |= Renderer([&](Element inner) {
25 return vbox({
26 text("Main component"),
27 separator(),
28 inner,
29 }) //
30 | size(WIDTH, GREATER_THAN, 15) //
31 | size(HEIGHT, GREATER_THAN, 15) //
32 | border //
33 | center; //
34 });
35 return component;
36}
37
38// モーダルコンポーネントの定義。詳細は重要ではありません。
39Component ModalComponent(std::function<void()> do_nothing,
40 std::function<void()> hide_modal) {
41 auto component = Container::Vertical({
42 Button("Do nothing", do_nothing, button_style),
43 Button("Quit modal", hide_modal, button_style),
44 });
45 // 2つのボタンの描画を調整します:
46 component |= Renderer([&](Element inner) {
47 return vbox({
48 text("Modal component "),
49 separator(),
50 inner,
51 }) //
52 | size(WIDTH, GREATER_THAN, 30) //
53 | border; //
54 });
55 return component;
56}
57
58int main(int argc, const char* argv[]) {
60
61 // アプリケーションの状態:
62 bool modal_shown = false;
63
64 // 状態を変更するいくつかのアクション:
65 auto show_modal = [&] { modal_shown = true; };
66 auto hide_modal = [&] { modal_shown = false; };
67 auto exit = screen.ExitLoopClosure();
68 auto do_nothing = [&] {};
69
70 // メインコンポーネントとモーダルコンポーネントをインスタンス化します:
71 auto main_component = MainComponent(show_modal, exit);
72 auto modal_component = ModalComponent(do_nothing, hide_modal);
73
74 // `Modal` 関数を使用して、メインコンポーネントとそのモーダルウィンドウを一緒に使用します。
75 // |modal_shown| ブール値は、モーダルが表示されているかどうかを制御します。
76 main_component |= Modal(modal_component, &modal_shown);
77
78 screen.Loop(main_component);
79 return 0;
80}
static ButtonOption Animated()
アニメーションカラーを使用するButtonOptionを作成します。
static ScreenInteractive TerminalOutput()
ターミナル出力の幅に一致し、描画されるコンポーネントの高さに一致するScreenInteractiveを作成します。
Component Button(ButtonOption options)
Draw a button. Execute a function when clicked. (ja: ボタンを描画します。クリックされたときに機能を実行します。)
Component Modal(Component main, Component modal, const bool *show_modal)
Definition modal.cpp:17
Component Renderer(Component child, std::function< Element()>)
|child|に似ていますが、|render|をComponentRender()イベントとして使用する新しいコンポーネントを返します。
Element center(Element)
要素を水平方向および垂直方向に中央揃えします。
Element text(std::wstring text)
ユニコードテキストを表示します。
Definition text.cpp:160
Element vbox(Elements)
要素を縦に一つずつ表示するコンテナ。
Definition vbox.cpp:94
auto button_style
Component ModalComponent(std::function< void()> do_nothing, std::function< void()> hide_modal)
Component MainComponent(std::function< void()> show_modal, std::function< void()> exit)
FTXUI ftxui:: 名前空間
Definition animation.hpp:9
std::shared_ptr< Node > Element
Definition elements.hpp:21
Element border(Element)
Element separator()
@ GREATER_THAN
Definition elements.hpp:157
std::shared_ptr< ComponentBase > Component
return size
Definition string.cpp:1516