FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
menu_underline_animated_gallery.cpp
浏览该文件的文档.
1// 版权所有 2020 Arthur Sonzogni。保留所有权利。
2// 本源代码的使用受 MIT 许可证的约束,该许可证可在以下文件中找到:
3// LICENSE 文件。
4#include <chrono> // for operator""ms, literals
5#include <memory> // for allocator, shared_ptr, __shared_ptr_access
6#include <string> // for string, operator+, to_string, basic_string
7#include <vector> // for vector
8
9#include "ftxui/component/animation.hpp" // for BackOut, Duration
10#include "ftxui/component/component.hpp" // for Menu, Renderer, Vertical
11#include "ftxui/component/component_base.hpp" // for ComponentBase
12#include "ftxui/component/component_options.hpp" // for MenuOption, UnderlineOption
13#include "ftxui/component/mouse.hpp" // for ftxui
14#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
15#include "ftxui/dom/elements.hpp" // for text, Element, operator|, borderEmpty, inverted
16#include "ftxui/screen/color.hpp" // for Color, Color::Blue, Color::Red
17
18using namespace ftxui;
19
21 return Renderer([id](bool focused) {
22 auto t = text("component " + std::to_string(id));
23 if (focused) {
24 t = t | inverted;
25 }
26 return t;
27 });
28}
29
30Component Text(const std::string& t) {
31 return Renderer([t] { return text(t) | borderEmpty; });
32}
33
34int main() {
35 using namespace std::literals;
36 std::vector<std::string> tab_values{
37 "Tab 1", "Tab 2", "Tab 3", "A very very long tab", "탭",
38 };
39 int tab_selected = 0;
40
41 auto container = Container::Vertical({});
42
43 int frame_count = 0;
44 container->Add(Renderer(
45 [&] { return text("Frame count: " + std::to_string(frame_count++)); }));
46
47 {
48 auto option = MenuOption::HorizontalAnimated();
49 container->Add(Text("This demonstrate the Menu component"));
50 container->Add(Menu(&tab_values, &tab_selected, option));
51 }
52
53 {
54 container->Add(Text("Set underline color to blue"));
55 auto option = MenuOption::HorizontalAnimated();
56 option.underline.color_inactive = Color::Blue;
57 container->Add(Menu(&tab_values, &tab_selected, option));
58 }
59
60 {
61 container->Add(Text("Set underline active color to red"));
62 auto option = MenuOption::HorizontalAnimated();
63 option.underline.color_active = Color::Red;
64 container->Add(Menu(&tab_values, &tab_selected, option));
65 }
66
67 {
68 container->Add(Text("Set animation duration to 0ms"));
69 auto option = MenuOption::HorizontalAnimated();
70 option.underline.SetAnimationDuration(0ms);
71 container->Add(Menu(&tab_values, &tab_selected, option));
72 }
73
74 {
75 container->Add(Text("Set animation easing function to back-out"));
76 auto option = MenuOption::HorizontalAnimated();
77 option.underline.SetAnimationFunction(animation::easing::BackOut);
78 option.underline.SetAnimationDuration(350ms);
79 container->Add(Menu(&tab_values, &tab_selected, option));
80 }
81
82 // option.underline_animation_follower_delay = 250ms
83 {
84 container->Add(Text("Add delay to desynchronize animation"));
85 auto option = MenuOption::HorizontalAnimated();
86 option.underline.follower_delay = 250ms;
87 container->Add(Menu(&tab_values, &tab_selected, option));
88 }
89
90 container->SetActiveChild(container->ChildAt(2));
91
93 screen.Loop(container);
94}
static ScreenInteractive TerminalOutput()
void Add(Component children)
添加一个子项。 @param child 要附加的子项。
static MenuOption HorizontalAnimated()
动画水平菜单的标准选项。 这对于实现选项卡栏非常有用。
Component Menu(MenuOption options)
文本列表。選定的元素是焦點。
Component Renderer(Component child, std::function< Element()>)
返回一个新组件,类似于 |child|,但使用 |render| 作为 Component::Render() 事件。
Element inverted(Element)
添加一个过滤器,用于反转前景色和背景色。
Element text(std::wstring text)
显示一段Unicode文本。
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
Element borderEmpty(Element)
std::shared_ptr< ComponentBase > Component