FTXUI
6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
menu_entries.cpp
浏览该文件的文档.
1
// 版权所有 2020 Arthur Sonzogni. 保留所有权利。
2
// 此源代码的使用受 MIT 许可证的约束,该许可证可在
3
// LICENSE 文件中找到。
4
#include <functional>
// for function
5
#include <iostream>
// for basic_ostream::operator<<, operator<<, endl, basic_ostream, basic_ostream<>::__ostream_type, cout, ostream
6
#include <memory>
// for allocator, shared_ptr, __shared_ptr_access
7
#include <string>
// for char_traits, to_string, operator+, string, basic_string
8
9
#include "
ftxui/component/captured_mouse.hpp
"
// for ftxui
10
#include "
ftxui/component/component.hpp
"
// for MenuEntry, Renderer, Vertical
11
#include "
ftxui/component/component_base.hpp
"
// for ComponentBase
12
#include "
ftxui/component/component_options.hpp
"
// for MenuEntryOption
13
#include "
ftxui/component/screen_interactive.hpp
"
// for ScreenInteractive
14
#include "
ftxui/dom/elements.hpp
"
// for operator|, Element, separator, text, hbox, size, frame, color, vbox, HEIGHT, LESS_THAN, bold, border, inverted
15
#include "
ftxui/screen/color.hpp
"
// for Color, Color::Blue, Color::Cyan, Color::Green, Color::Red, Color::Yellow
16
17
using namespace
ftxui
;
18
19
// 为某些菜单项定义特殊样式。
20
MenuEntryOption
Colored
(
ftxui::Color
c) {
21
MenuEntryOption
option;
22
option.
transform
= [c](
EntryState
state) {
23
state.label = (state.active ?
"> "
:
" "
) + state.label;
24
Element
e =
text
(state.label) |
color
(c);
25
if
(state.focused) {
26
e = e |
inverted
;
27
}
28
if
(state.active) {
29
e = e |
bold
;
30
}
31
return
e;
32
};
33
return
option;
34
}
35
36
int
main
() {
37
auto
screen =
ScreenInteractive::TerminalOutput
();
38
39
int
selected = 0;
40
auto
menu = Container::Vertical(
41
{
42
MenuEntry
(
" 1. improve"
),
43
MenuEntry
(
" 2. tolerant"
),
44
MenuEntry
(
" 3. career"
),
45
MenuEntry
(
" 4. cast"
),
46
MenuEntry
(
" 5. question"
),
47
48
Renderer
([] {
return
separator
(); }),
49
50
MenuEntry
(
" 6. rear"
,
Colored
(
Color::Red
)),
51
MenuEntry
(
" 7. drown"
,
Colored
(
Color::Yellow
)),
52
MenuEntry
(
" 8. nail"
,
Colored
(
Color::Green
)),
53
MenuEntry
(
" 9. quit"
,
Colored
(
Color::Cyan
)),
54
MenuEntry
(
"10. decorative"
,
Colored
(
Color::Blue
)),
55
56
Renderer
([] {
return
separator
(); }),
57
58
MenuEntry
(
"11. costume"
),
59
MenuEntry
(
"12. pick"
),
60
MenuEntry
(
"13. oral"
),
61
MenuEntry
(
"14. minister"
),
62
MenuEntry
(
"15. football"
),
63
MenuEntry
(
"16. welcome"
),
64
MenuEntry
(
"17. copper"
),
65
MenuEntry
(
"18. inhabitant"
),
66
MenuEntry
(
"19. fortune"
),
67
},
68
&selected);
69
70
// 将菜单与边框一起显示
71
auto
renderer
=
Renderer
(menu, [&] {
72
return
vbox
({
73
hbox
(
text
(
"selected = "
),
text
(std::to_string(selected))),
74
separator
(),
75
menu->
Render
() | frame |
size
(
HEIGHT
,
LESS_THAN
, 10),
76
}) |
77
border;
78
});
79
80
screen.Loop(
renderer
);
81
82
std::cout <<
"Selected element = "
<< selected << std::endl;
83
}
captured_mouse.hpp
color.hpp
component.hpp
component_base.hpp
component_options.hpp
elements.hpp
ftxui::ScreenInteractive::TerminalOutput
static ScreenInteractive TerminalOutput()
定义
screen_interactive.cpp:330
ftxui::MenuEntryOption::transform
std::function< Element(const EntryState &state)> transform
定义
component_options.hpp:81
ftxui::MenuEntry
Component MenuEntry(MenuEntryOption options)
一個特定的菜單條目。它們可以放入 Container::Vertical 中形成一個菜單。
定义
src/ftxui/component/menu.cpp:612
ftxui::Renderer
Component Renderer(Component child, std::function< Element()>)
返回一个新组件,类似于 |child|,但使用 |render| 作为 Component::Render() 事件。
定义
src/ftxui/component/renderer.cpp:61
ftxui::MenuEntryOption
MenuEntry 组件的选项。
定义
component_options.hpp:79
ftxui::Node::Render
virtual void Render(Screen &screen)
在 ftxui::Screen 上显示元素。
定义
node.cpp:59
ftxui::size
Decorator size(WidthOrHeight, Constraint, int value)
对元素大小应用约束。
定义
src/ftxui/dom/size.cpp:89
ftxui::bold
Element bold(Element)
使用粗体字体,用于强调元素。
定义
bold.cpp:33
ftxui::inverted
Element inverted(Element)
添加一个过滤器,用于反转前景色和背景色。
定义
inverted.cpp:33
ftxui::text
Element text(std::wstring text)
显示一段Unicode文本。
定义
text.cpp:160
ftxui::separator
Element separator()
在两个其他元素之间绘制垂直或水平分隔线。
定义
src/ftxui/dom/separator.cpp:132
ftxui::color
Decorator color(Color)
使用前景色进行装饰。
定义
dom/color.cpp:110
ftxui::vbox
Element vbox(Elements)
垂直一个接一个显示元素的容器。
定义
vbox.cpp:96
ftxui::Color::Cyan
@ Cyan
定义
color.hpp:58
ftxui::Color::Yellow
@ Yellow
定义
color.hpp:55
ftxui::Color::Green
@ Green
定义
color.hpp:54
ftxui::Color::Red
@ Red
定义
color.hpp:53
ftxui::Color::Blue
@ Blue
定义
color.hpp:56
ftxui::Color
Color 是一个表示终端用户界面中颜色的类。
定义
color.hpp:20
Colored
MenuEntryOption Colored(ftxui::Color c)
定义
menu_entries.cpp:20
main
int main()
定义
menu_entries.cpp:36
ftxui
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
定义
animation.hpp:9
ftxui::HEIGHT
@ HEIGHT
定义
elements.hpp:157
ftxui::Element
std::shared_ptr< Node > Element
定义
elements.hpp:22
ftxui::hbox
Element hbox(Elements)
一个按水平顺序逐一显示元素的容器。
定义
hbox.cpp:94
ftxui::LESS_THAN
@ LESS_THAN
定义
elements.hpp:158
screen_interactive.hpp
ftxui::EntryState
来自 |ButtonOption|、|CheckboxOption|、 |RadioboxOption|、|MenuEntryOption|、|MenuOption| 的转换参数。
定义
component_options.hpp:23
renderer
auto renderer
定义
with_restored_io.cpp:37