FTXUI 7.0.3
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// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4#include <stdlib.h> // for EXIT_SUCCESS
5#include <memory> // for allocator, __shared_ptr_access
6#include <string> // for string, operator+, basic_string, to_string, char_traits
7#include <vector> // for vector, __alloc_traits<>::value_type
8
9#include "ftxui/component/app.hpp" // for Component, App
10#include "ftxui/component/captured_mouse.hpp" // for ftxui
11#include "ftxui/component/component.hpp" // for Menu, Renderer, Horizontal, Vertical
12#include "ftxui/component/component_base.hpp" // for ComponentBase
13#include "ftxui/dom/elements.hpp" // for text, Element, operator|, window, flex, vbox
14
15using namespace ftxui;
16
17Component Window(std::string title, Component component) {
18 return Renderer(component, [component, title] { //
19 return window(text(title), component->Render()) | flex;
20 });
21}
22
23int main() {
24 int menu_selected[] = {0, 0, 0};
25 std::vector<std::vector<std::string>> menu_entries = {
26 {
27 "Ananas",
28 "Raspberry",
29 "Citrus",
30 },
31 {
32 "Potatoes",
33 "Weat",
34 "Rise",
35 },
36 {
37 "Carrot",
38 "Lettuce",
39 "Tomato",
40 },
41 };
42
43 int menu_selected_global = 0;
44 auto menu_global = Container::Vertical(
45 {
46 Window("Menu 1", Menu(&menu_entries[0], &menu_selected[0])),
47 Window("Menu 2", Menu(&menu_entries[1], &menu_selected[1])),
48 Window("Menu 3", Menu(&menu_entries[2], &menu_selected[2])),
49 },
50 &menu_selected_global);
51
52 auto info = Renderer([&] {
53 int g = menu_selected_global;
54 std::string value = menu_entries[g][menu_selected[g]];
55 return window(text("Content"), //
56 vbox({
57 text("menu_selected_global = " + std::to_string(g)),
58 text("menu_selected[0] = " +
59 std::to_string(menu_selected[0])),
60 text("menu_selected[1] = " +
61 std::to_string(menu_selected[1])),
62 text("menu_selected[2] = " +
63 std::to_string(menu_selected[2])),
64 text("Value = " + value),
65 })) |
66 flex;
67 });
68
69 auto global = Container::Horizontal({
70 menu_global,
71 info,
72 });
73
74 auto screen = App::TerminalOutput();
75 screen.Loop(global);
76 return EXIT_SUCCESS;
77}
Component Renderer(Component child, std::function< Element()>)
|child| に似た、|render| をComponent::Render()イベントとして 使用する新しいComponentを返します。
Component Window(WindowOptions option)
ドラッグ可能/サイズ変更可能なウィンドウ。複数のウィンドウを使用するには、それらを Container::Stacked({...})コンポーネントを使用してスタックする必要があります。
Component Menu(ConstStringListRef entries, int *selected_, MenuOption options=MenuOption::Vertical())
テキストのリスト。フォーカスされた要素が選択されます。
Element window(Element title, Element content, BorderStyle border=ROUNDED)
要素の周囲にタイトルとボーダーを持つウィンドウを描画します。
Element text(std::string_view text)
UTF8エンコードされたユニコードテキストを表示します。
Element flex(Element child)
子要素をコンテナに残されたスペースに比例して拡大させます。
Definition flex.cpp:93
Element vbox(Elements children)
要素を縦に一つずつ表示するコンテナ。
Definition vbox.cpp:95
int main()
FTXUI ftxui::名前空間
Definition animation.hpp:11
int value
Definition elements.hpp:192
std::shared_ptr< ComponentBase > Component
Definition app.hpp:23