FTXUI 7.0.3
C++ functional terminal UI.
Loading...
Searching...
No Matches
menu_entries_animated.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 <iostream> // for basic_ostream::operator<<, operator<<, endl, basic_ostream, basic_ostream<>::__ostream_type, cout, ostream
5#include <memory> // for shared_ptr, __shared_ptr_access
6#include <string> // for to_string, allocator
7
8#include "ftxui/component/app.hpp" // for App
9#include "ftxui/component/captured_mouse.hpp" // for ftxui
10#include "ftxui/component/component.hpp" // for MenuEntryAnimated, Renderer, Vertical
11#include "ftxui/component/component_base.hpp" // for ComponentBase
12#include "ftxui/component/component_options.hpp" // for MenuEntryAnimated
13#include "ftxui/dom/elements.hpp" // for operator|, separator, Element, Decorator, color, text, hbox, size, bold, frame, inverted, vbox, HEIGHT, LESS_THAN, border
14#include "ftxui/screen/color.hpp" // for Color, Color::Blue, Color::Cyan, Color::Green, Color::Red, Color::Yellow
15
16using namespace ftxui;
17
18// いくつかのメニューエントリに特別なスタイルを定義します。
19MenuEntryOption Colored(ftxui::Color c) {
20 MenuEntryOption option;
21 option.animated_colors.foreground.enabled = true;
22 option.animated_colors.background.enabled = true;
23 option.animated_colors.background.active = c;
24 option.animated_colors.background.inactive = Color::Black;
25 option.animated_colors.foreground.active = Color::White;
26 option.animated_colors.foreground.inactive = c;
27 return option;
28}
29
30int main() {
31 auto screen = App::TerminalOutput();
32
33 int selected = 0;
34 auto menu = Container::Vertical(
35 {
36 MenuEntry(" 1. rear", Colored(Color::Red)),
37 MenuEntry(" 2. drown", Colored(Color::Yellow)),
38 MenuEntry(" 3. nail", Colored(Color::Green)),
39 MenuEntry(" 4. quit", Colored(Color::Cyan)),
40 MenuEntry(" 5. decorative", Colored(Color::Blue)),
41 MenuEntry(" 7. costume"),
42 MenuEntry(" 8. pick"),
43 MenuEntry(" 9. oral"),
44 MenuEntry("11. minister"),
45 MenuEntry("12. football"),
46 MenuEntry("13. welcome"),
47 MenuEntry("14. copper"),
48 MenuEntry("15. inhabitant"),
49 },
50 &selected);
51
52 // メニューと枠線を一緒に表示します
53 auto renderer = Renderer(menu, [&] {
54 return vbox({
55 hbox(text("selected = "), text(std::to_string(selected))),
56 separator(),
57 menu->Render() | frame,
58 }) |
59 border | bgcolor(Color::Black);
60 });
61
62 screen.Loop(renderer);
63
64 std::cout << "Selected element = " << selected << std::endl;
65}
Component Renderer(Component child, std::function< Element()>)
|child| に似た、|render| をComponent::Render()イベントとして 使用する新しいComponentを返します。
Component MenuEntry(ConstStringRef label, MenuEntryOption options={})
特定のメニューエントリ。Container::Verticalに入れることで メニューを形成できます。
Element text(std::string_view text)
UTF8エンコードされたユニコードテキストを表示します。
Element bgcolor(Color color, Element child)
要素の背景色を設定します。
Definition dom/color.cpp:96
Element vbox(Elements children)
要素を縦に一つずつ表示するコンテナ。
Definition vbox.cpp:95
MenuEntryOption Colored(ftxui::Color c)
FTXUI ftxui::名前空間
Definition animation.hpp:11
Element hbox(Elements children)
要素を水平方向に1つずつ表示するコンテナ。
Definition hbox.cpp:93
Element frame(Element child)
要素を「仮想」領域内に表示できるようにします。そのサイズはコンテナよりも大きくすることができます。 この場合、より小さい部分のみが表示されます。フォーカスされた要素を表示するためにビューはスクロール可能...
Definition frame.cpp:117