FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
menu_entries_animated.cpp
浏览该文件的文档.
1// 版权所有 2020 Arthur Sonzogni. 保留所有权利。
2// 此源代码的使用受 MIT 许可证的约束,该许可证可在以下文件中找到:
3// LICENSE 文件。
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/captured_mouse.hpp" // for ftxui
9#include "ftxui/component/component.hpp" // for MenuEntryAnimated, Renderer, Vertical
10#include "ftxui/component/component_base.hpp" // for ComponentBase
11#include "ftxui/component/component_options.hpp" // for MenuEntryAnimated
12#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
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// 为某些菜单项定义特殊样式。
29
30int main() {
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 // Display together the menu with a border
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}
static ScreenInteractive TerminalOutput()
AnimatedColorsOption animated_colors
Component MenuEntry(MenuEntryOption options)
一個特定的菜單條目。它們可以放入 Container::Vertical 中形成一個菜單。
Component Renderer(Component child, std::function< Element()>)
返回一个新组件,类似于 |child|,但使用 |render| 作为 Component::Render() 事件。
MenuEntry 组件的选项。
virtual void Render(Screen &screen)
在 ftxui::Screen 上显示元素。
Decorator bgcolor(Color)
使用背景色进行装饰。
Element text(std::wstring text)
显示一段Unicode文本。
Element separator()
在两个其他元素之间绘制垂直或水平分隔线。
Element vbox(Elements)
垂直一个接一个显示元素的容器。
Color 是一个表示终端用户界面中颜色的类。
MenuEntryOption Colored(ftxui::Color c)
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
Element hbox(Elements)
一个按水平顺序逐一显示元素的容器。
Element frame(Element)
允许元素显示在“虚拟”区域内。其大小可以 大于其容器。在这种情况下,只显示较小的部分。 视图是可滚动的,以使获得焦点的元素可见。