FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
menu_multiple.cpp
Go to the documentation of this file.
1// 版權所有 2020 Arthur Sonzogni. 保留所有權利。
2// 本原始碼的使用受 MIT 授權條款約束,該條款可在 LICENSE 檔案中找到。
3#include <stdlib.h> // for EXIT_SUCCESS
4#include <memory> // for allocator, __shared_ptr_access
5#include <string> // for string, operator+, basic_string, to_string, char_traits
6#include <vector> // for vector, __alloc_traits<>::value_type
7
8#include "ftxui/component/captured_mouse.hpp" // for ftxui
9#include "ftxui/component/component.hpp" // for Menu, Renderer, Horizontal, Vertical
10#include "ftxui/component/component_base.hpp" // for ComponentBase
11#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
12#include "ftxui/dom/elements.hpp" // for 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}
int menu_selected
Definition gallery.cpp:38
auto component
Definition gallery.cpp:127
static ScreenInteractive TerminalOutput()
Component Menu(MenuOption options)
文字列表。選定的元素會被聚焦。
Component Renderer(Component child, std::function< Element()>)
回傳一個新的元件,類似於 |child|,但使用 |render| 作為 Component::Render() 事件。
Component Window(WindowOptions option)
一個可拖曳/可調整大小的視窗。要使用多個視窗,它們必須透過 Container::Stacked({...}) 元件堆疊。
virtual void Render(Screen &screen)
Element window(Element title, Element content, BorderStyle border=ROUNDED)
繪製帶有標題和邊框的視窗。
Element flex(Element)
使子元素按比例擴展以佔據容器中剩餘的空間。
Definition flex.cpp:140
Element text(std::wstring text)
顯示一段 Unicode 文字。
Definition text.cpp:160
Element vbox(Elements)
一個垂直一個接一個顯示元素的容器。
Definition vbox.cpp:95
int main()
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10
std::shared_ptr< ComponentBase > Component