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 }
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)
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