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. All rights reserved.
2
// 本原始碼的使用受 MIT 授權條款約束,詳情請參閱 LICENSE 檔案。
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
16
using namespace
ftxui
;
17
18
// 為某些選單項目定義特殊樣式。
19
MenuEntryOption
Colored
(
ftxui::Color
c) {
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
35
int
main
() {
36
auto
screen =
ScreenInteractive::TerminalOutput
();
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
}
captured_mouse.hpp
color.hpp
component.hpp
component_base.hpp
component_options.hpp
elements.hpp
menu
auto menu
Definition
gallery.cpp:39
ftxui::ScreenInteractive::TerminalOutput
static ScreenInteractive TerminalOutput()
Definition
screen_interactive.cpp:331
ftxui::MenuEntryOption::transform
std::function< Element(const EntryState &state)> transform
Definition
component_options.hpp:82
ftxui::MenuEntry
Component MenuEntry(MenuEntryOption options)
一個特定的菜單條目。它們可以放入 Container::Vertical 中以形成菜單。
Definition
src/ftxui/component/menu.cpp:612
ftxui::Renderer
Component Renderer(Component child, std::function< Element()>)
回傳一個新的元件,類似於 |child|,但使用 |render| 作為 Component::Render() 事件。
Definition
src/ftxui/component/renderer.cpp:59
ftxui::MenuEntryOption
MenuEntry 元件的選項。
Definition
component_options.hpp:80
ftxui::Node::Render
virtual void Render(Screen &screen)
ftxui::size
Decorator size(WidthOrHeight, Constraint, int value)
限制元素的大小。
Definition
src/ftxui/dom/size.cpp:88
ftxui::bold
Element bold(Element)
使用粗體字型,用於需要更多強調的元素。
Definition
bold.cpp:33
ftxui::inverted
Element inverted(Element)
添加一個濾鏡,它將反轉前景和背景 顏色。
Definition
inverted.cpp:34
ftxui::text
Element text(std::wstring text)
顯示一段 Unicode 文字。
Definition
text.cpp:160
ftxui::separator
Element separator()
在兩個元素之間繪製垂直或水平分隔線。
Definition
src/ftxui/dom/separator.cpp:133
ftxui::color
Decorator color(Color)
使用前景顏色進行裝飾。
Definition
dom/color.cpp:110
ftxui::vbox
Element vbox(Elements)
一個垂直一個接一個顯示元素的容器。
Definition
vbox.cpp:95
ftxui::Color::Cyan
@ Cyan
Definition
color.hpp:58
ftxui::Color::Yellow
@ Yellow
Definition
color.hpp:55
ftxui::Color::Green
@ Green
Definition
color.hpp:54
ftxui::Color::Red
@ Red
Definition
color.hpp:53
ftxui::Color::Blue
@ Blue
Definition
color.hpp:56
ftxui::Color
Color 是一個在終端使用者介面中表示顏色的類別。
Definition
color.hpp:20
Colored
MenuEntryOption Colored(ftxui::Color c)
Definition
menu_entries.cpp:19
main
int main()
Definition
menu_entries.cpp:35
ftxui
FTXUI 的 ftxui:: 命名空間
Definition
animation.hpp:10
ftxui::HEIGHT
@ HEIGHT
Definition
elements.hpp:158
ftxui::Element
std::shared_ptr< Node > Element
Definition
elements.hpp:22
ftxui::hbox
Element hbox(Elements)
一個逐一水平顯示元素的容器。
Definition
hbox.cpp:94
ftxui::LESS_THAN
@ LESS_THAN
Definition
elements.hpp:159
screen_interactive.hpp
ftxui::EntryState
來自 |ButtonOption|、|CheckboxOption|、 |RadioboxOption|、|MenuEntryOption|、|MenuOption| 的轉換參數。
Definition
component_options.hpp:24