FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
menu_multiple.cpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
2// このソースコードの使用は、LICENSEファイルにあるMITライセンスによって管理されています。
3#include <stdlib.h> // EXIT_SUCCESSのため
4#include <memory> // allocator, __shared_ptr_accessのため
5#include <string> // string, operator+, basic_string, to_string, char_traitsのため
6#include <vector> // vector, __alloc_traits<>::value_typeのため
7
8#include "ftxui/component/captured_mouse.hpp" // ftxuiのため
9#include "ftxui/component/component.hpp" // Menu, Renderer, Horizontal, Verticalのため
10#include "ftxui/component/component_base.hpp" // ComponentBaseのため
11#include "ftxui/component/screen_interactive.hpp" // Component, ScreenInteractiveのため
12#include "ftxui/dom/elements.hpp" // text, Element, operator|, window, flex, vboxのため
13
14using namespace ftxui;
15
16Component Window(std::string title, Component component) {
17 return Renderer(component, [component, title] { //
18 return window(text(title), component->Render()) | flex;
19 });
20}
21
22int main() {
23 int menu_selected[] = {0, 0, 0};
24 std::vector<std::vector<std::string>> menu_entries = {
25 {
26 "Ananas",
27 "Raspberry",
28 "Citrus",
29 },
30 {
31 "Potatoes",
32 "Weat",
33 "Rise",
34 },
35 {
36 "Carrot",
37 "Lettuce",
38 "Tomato",
39 },
40 };
41
42 int menu_selected_global = 0;
43 auto menu_global = Container::Vertical(
44 {
45 Window("Menu 1", Menu(&menu_entries[0], &menu_selected[0])),
46 Window("Menu 2", Menu(&menu_entries[1], &menu_selected[1])),
47 Window("Menu 3", Menu(&menu_entries[2], &menu_selected[2])),
48 },
49 &menu_selected_global);
50
51 auto info = Renderer([&] {
52 int g = menu_selected_global;
53 std::string value = menu_entries[g][menu_selected[g]];
54 return window(text("Content"), //
55 vbox({
56 text("menu_selected_global = " + std::to_string(g)),
57 text("menu_selected[0] = " +
58 std::to_string(menu_selected[0])),
59 text("menu_selected[1] = " +
60 std::to_string(menu_selected[1])),
61 text("menu_selected[2] = " +
62 std::to_string(menu_selected[2])),
63 text("Value = " + value),
64 })) |
65 flex;
66 });
67
68 auto global = Container::Horizontal({
69 menu_global,
70 info,
71 });
72
74 screen.Loop(global);
75 return EXIT_SUCCESS;
76}
static ScreenInteractive TerminalOutput()
ターミナル出力の幅に一致し、描画されるコンポーネントの高さに一致するScreenInteractiveを作成します。
Element Render()
コンポーネントを描画します。 このftxui::ComponentBaseを表すftxui::Screen上に描画されるftxui::Elementを構築します。レンダリングを変更するにはOnRende...
Component Menu(MenuOption options)
テキストのリスト。フォーカスされた要素が選択されます。
Component Renderer(Component child, std::function< Element()>)
|child|に似ていますが、|render|をComponentRender()イベントとして使用する新しいコンポーネントを返します。
Component Window(WindowOptions option)
ドラッグ可能/サイズ変更可能なウィンドウ。複数のウィンドウを使用するには、それらを Container::Stacked({...})コンポーネントを使用してスタックする必要があります。
Element flex(Element)
子要素をコンテナに残されたスペースに比例して拡大させます。
Definition flex.cpp:120
Element text(std::wstring text)
ユニコードテキストを表示します。
Definition text.cpp:160
Element vbox(Elements)
要素を縦に一つずつ表示するコンテナ。
Definition vbox.cpp:94
int main()
FTXUI ftxui:: 名前空間
Definition animation.hpp:9
Element window(Element title, Element content, BorderStyle border=ROUNDED)
std::shared_ptr< ComponentBase > Component