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()>)
回傳一個新的 Component,類似 |child|,但使用 |render| 作為 Component::Render() 事件。
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 編碼的 Unicode 文字。
Element flex(Element child)
讓子元素依比例擴展以填滿容器中剩餘的空間。
Definition flex.cpp:94
Element vbox(Elements children)
一個垂直一個接一個顯示元素的容器。
Definition vbox.cpp:96
int main()
FTXUI ftxui:: 命名空間
Definition animation.hpp:11
int value
Definition elements.hpp:192
std::shared_ptr< ComponentBase > Component
Definition app.hpp:23