FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
menu_entries.cpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. 無断転載を禁じます。
2// このソースコードの使用は、LICENSEファイルにあるMITライセンスによって管理されています。
3#include <functional> // for function
4#include <iostream> // for basic_ostream::operator<<, operator<<, endl, basic_ostream, basic_ostream<>::__ostream_type, cout, ostream
5#include <memory> // for allocator, shared_ptr, __shared_ptr_access
6#include <string> // for char_traits, to_string, operator+, string, basic_string
7
8#include "ftxui/component/captured_mouse.hpp" // for ftxui
9#include "ftxui/component/component.hpp" // for MenuEntry, Renderer, Vertical
10#include "ftxui/component/component_base.hpp" // for ComponentBase
11#include "ftxui/component/component_options.hpp" // for MenuEntryOption
12#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
13#include "ftxui/dom/elements.hpp" // for operator|, Element, separator, text, hbox, size, frame, color, vbox, HEIGHT, LESS_THAN, bold, border, inverted
14#include "ftxui/screen/color.hpp" // for Color, Color::Blue, Color::Cyan, Color::Green, Color::Red, Color::Yellow
15
16using namespace ftxui;
17
18// 一部のメニューエントリに特別なスタイルを定義します。
20 MenuEntryOption option;
21 option.transform = [c](EntryState state) {
22 state.label = (state.active ? "> " : " ") + state.label;
23 Element e = text(state.label) | color(c);
24 if (state.focused) {
25 e = e | inverted;
26 }
27 if (state.active) {
28 e = e | bold;
29 }
30 return e;
31 };
32 return option;
33}
34
35int main() {
37
38 int selected = 0;
39 auto menu = Container::Vertical(
40 {
41 MenuEntry(" 1. improve"),
42 MenuEntry(" 2. tolerant"),
43 MenuEntry(" 3. career"),
44 MenuEntry(" 4. cast"),
45 MenuEntry(" 5. question"),
46
47 Renderer([] { return separator(); }),
48
49 MenuEntry(" 6. rear", Colored(Color::Red)),
50 MenuEntry(" 7. drown", Colored(Color::Yellow)),
51 MenuEntry(" 8. nail", Colored(Color::Green)),
52 MenuEntry(" 9. quit", Colored(Color::Cyan)),
53 MenuEntry("10. decorative", Colored(Color::Blue)),
54
55 Renderer([] { return separator(); }),
56
57 MenuEntry("11. costume"),
58 MenuEntry("12. pick"),
59 MenuEntry("13. oral"),
60 MenuEntry("14. minister"),
61 MenuEntry("15. football"),
62 MenuEntry("16. welcome"),
63 MenuEntry("17. copper"),
64 MenuEntry("18. inhabitant"),
65 MenuEntry("19. fortune"),
66 },
67 &selected);
68
69 // ボーダー付きのメニューを一緒に表示します。
70 auto renderer = Renderer(menu, [&] {
71 return vbox({
72 hbox(text("selected = "), text(std::to_string(selected))),
73 separator(),
74 menu->Render() | frame | size(HEIGHT, LESS_THAN, 10),
75 }) |
76 border;
77 });
78
79 screen.Loop(renderer);
80
81 std::cout << "Selected element = " << selected << std::endl;
82}
static ScreenInteractive TerminalOutput()
ターミナル出力の幅に一致し、描画されるコンポーネントの高さに一致するScreenInteractiveを作成します。
std::function< Element(const EntryState &state)> transform
Component MenuEntry(MenuEntryOption options)
特定のメニューエントリ。これらはContainer::Verticalに入れてメニューを形成できます。
Component Renderer(Component child, std::function< Element()>)
|child|に似ていますが、|render|をComponentRender()イベントとして使用する新しいコンポーネントを返します。
MenuEntryコンポーネントのオプション。
virtual void Render(Screen &screen)
要素をftxui::Screenに表示します。
Definition node.cpp:59
Element bold(Element)
より強調したい要素に、太字フォントを使用します。
Definition bold.cpp:33
Element inverted(Element)
前景色と背景色を反転させるフィルターを追加します。
Definition inverted.cpp:32
Element text(std::wstring text)
ユニコードテキストを表示します。
Definition text.cpp:160
Decorator color(Color)
前景色を使用して装飾します。
Element vbox(Elements)
要素を縦に一つずつ表示するコンテナ。
Definition vbox.cpp:94
Colorは、ターミナルユーザーインターフェースにおける色を表すクラスです。
Definition color.hpp:25
MenuEntryOption Colored(ftxui::Color c)
int main()
FTXUI ftxui:: 名前空間
Definition animation.hpp:9
std::shared_ptr< Node > Element
Definition elements.hpp:21
Element hbox(Elements)
要素を水平方向に1つずつ表示するコンテナ。
Definition hbox.cpp:93
Element separator()
@ LESS_THAN
Definition elements.hpp:157
return size
Definition string.cpp:1516
|ButtonOption|、|CheckboxOption|、|RadioboxOption|、|MenuEntryOption|、|MenuOption|からの変換の引数。