FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
menu_underline_animated_gallery.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 <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 return t;
26 });
27}
28
29Component Text(const std::string& t) {
30 return Renderer([t] { return text(t) | borderEmpty; });
31}
32
33int main() {
34 using namespace std::literals;
35 std::vector<std::string> tab_values{
36 "Tab 1", "Tab 2", "Tab 3", "A very very long tab", "탭",
37 };
38 int tab_selected = 0;
39
40 auto container = Container::Vertical({});
41
42 int frame_count = 0;
43 container->Add(Renderer(
44 [&] { return text("Frame count: " + std::to_string(frame_count++)); }));
45
46 {
47 auto option = MenuOption::HorizontalAnimated();
48 container->Add(Text("This demonstrate the Menu component"));
49 container->Add(Menu(&tab_values, &tab_selected, option));
50 }
51
52 {
53 container->Add(Text("Set underline color to blue"));
54 auto option = MenuOption::HorizontalAnimated();
55 option.underline.color_inactive = Color::Blue;
56 container->Add(Menu(&tab_values, &tab_selected, option));
57 }
58
59 {
60 container->Add(Text("Set underline active color to red"));
61 auto option = MenuOption::HorizontalAnimated();
62 option.underline.color_active = Color::Red;
63 container->Add(Menu(&tab_values, &tab_selected, option));
64 }
65
66 {
67 container->Add(Text("Set animation duration to 0ms"));
68 auto option = MenuOption::HorizontalAnimated();
69 option.underline.SetAnimationDuration(0ms);
70 container->Add(Menu(&tab_values, &tab_selected, option));
71 }
72
73 {
74 container->Add(Text("Set animation easing function to back-out"));
75 auto option = MenuOption::HorizontalAnimated();
76 option.underline.SetAnimationFunction(animation::easing::BackOut);
77 option.underline.SetAnimationDuration(350ms);
78 container->Add(Menu(&tab_values, &tab_selected, option));
79 }
80
81 // option.underline_animation_follower_delay = 250ms
82 {
83 container->Add(Text("Add delay to desynchronize animation"));
84 auto option = MenuOption::HorizontalAnimated();
85 option.underline.follower_delay = 250ms;
86 container->Add(Menu(&tab_values, &tab_selected, option));
87 }
88
89 container->SetActiveChild(container->ChildAt(2));
90
92 screen.Loop(container);
93}
static ScreenInteractive TerminalOutput()
void Add(Component children)
Add a child. @param child The child to be attached.
Definition component.cpp:70
static MenuOption HorizontalAnimated()
Standard options for an animated horizontal menu. This can be useful to implement a tab bar.
Component Menu(MenuOption options)
A list of text. The focused element is selected.
Component Renderer(Component child, std::function< Element()>)
Return a new Component, similar to |child|, but using |render| as the Component::Render() event.
Component Vertical(Components children)
A list of components, drawn one by one vertically and navigated vertically using up/down arrow key or...
Element inverted(Element)
Add a filter that will invert the foreground and the background colors.
Definition inverted.cpp:34
Element text(std::wstring text)
Display a piece of unicode text.
Definition text.cpp:160
Element borderEmpty(Element)
Draw an empty border around the element.
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
std::shared_ptr< ComponentBase > Component