FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
toggle.cpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
2// このソースコードの使用は、LICENSEファイルにあるMITライセンスによって管理されています。
3#include <memory> // for allocator, __shared_ptr_access
4#include <string> // for string, basic_string
5#include <vector> // for vector
6
7#include "ftxui/component/captured_mouse.hpp" // for ftxui
8#include "ftxui/component/component.hpp" // for Toggle, Renderer, Vertical
9#include "ftxui/component/component_base.hpp" // for ComponentBase
10#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
11#include "ftxui/dom/elements.hpp" // for text, hbox, vbox, Element
12
13using namespace ftxui;
14
15int main() {
16 std::vector<std::string> toggle_1_entries = {
17 "On",
18 "Off",
19 };
20 std::vector<std::string> toggle_2_entries = {
21 "Enabled",
22 "Disabled",
23 };
24 std::vector<std::string> toggle_3_entries = {
25 "10€",
26 "0€",
27 };
28 std::vector<std::string> toggle_4_entries = {
29 "Nothing",
30 "One element",
31 "Several elements",
32 };
33
34 int toggle_1_selected = 0;
35 int toggle_2_selected = 0;
36 int toggle_3_selected = 0;
37 int toggle_4_selected = 0;
38 Component toggle_1 = Toggle(&toggle_1_entries, &toggle_1_selected);
39 Component toggle_2 = Toggle(&toggle_2_entries, &toggle_2_selected);
40 Component toggle_3 = Toggle(&toggle_3_entries, &toggle_3_selected);
41 Component toggle_4 = Toggle(&toggle_4_entries, &toggle_4_selected);
42
43 auto container = Container::Vertical({
44 toggle_1,
45 toggle_2,
46 toggle_3,
47 toggle_4,
48 });
49
50 auto renderer = Renderer(container, [&] {
51 return vbox({
52 text("Choose your options:"),
53 text(""),
54 hbox(text(" * Poweroff on startup : "), toggle_1->Render()),
55 hbox(text(" * Out of process : "), toggle_2->Render()),
56 hbox(text(" * Price of the information : "), toggle_3->Render()),
57 hbox(text(" * Number of elements : "), toggle_4->Render()),
58 });
59 });
60
62 screen.Loop(renderer);
63}
static ScreenInteractive TerminalOutput()
ターミナル出力の幅に一致し、描画されるコンポーネントの高さに一致するScreenInteractiveを作成します。
Element Render()
コンポーネントを描画します。 このftxui::ComponentBaseを表すftxui::Screen上に描画されるftxui::Elementを構築します。レンダリングを変更するにはOnRende...
Component Toggle(ConstStringListRef entries, int *selected)
要素の水平リスト。ユーザーはこれらを操作できます。
Component Renderer(Component child, std::function< Element()>)
|child|に似ていますが、|render|をComponentRender()イベントとして使用する新しいコンポーネントを返します。
Element text(std::wstring text)
ユニコードテキストを表示します。
Definition text.cpp:160
Element vbox(Elements)
要素を縦に一つずつ表示するコンテナ。
Definition vbox.cpp:94
FTXUI ftxui:: 名前空間
Definition animation.hpp:9
Element hbox(Elements)
要素を水平方向に1つずつ表示するコンテナ。
Definition hbox.cpp:93
std::shared_ptr< ComponentBase > Component
int main()
Definition toggle.cpp:15