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// このソースコードの使用は、LICENSE ファイルにある MIT ライセンスによって管理されています。
3#include <chrono> // for operator""ms, literals
4#include <memory> // for allocator, shared_ptr, __shared_ptr_access
5#include <string> // for string, operator+, to_string, basic_string
6#include <vector> // for vector
7
8#include "ftxui/component/animation.hpp" // for BackOut, Duration
9#include "ftxui/component/component.hpp" // for Menu, Renderer, Vertical
10#include "ftxui/component/component_base.hpp" // for ComponentBase
11#include "ftxui/component/component_options.hpp" // for MenuOption, UnderlineOption
12#include "ftxui/component/mouse.hpp" // for ftxui
13#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
14#include "ftxui/dom/elements.hpp" // for text, Element, operator|, borderEmpty, inverted
15#include "ftxui/screen/color.hpp" // for Color, Color::Blue, Color::Red
16
17using namespace ftxui;
18
20 return Renderer([id](bool focused) {
21 auto t = text("component " + std::to_string(id));
22 if (focused) {
23 t = t | inverted;
24 }
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("これはメニューコンポーネントを示しています"));
49 container->Add(Menu(&tab_values, &tab_selected, option));
50 }
51
52 {
53 container->Add(Text("アンダーラインの色を青に設定"));
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("アンダーラインのアクティブな色を赤に設定"));
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("アニメーションの継続時間を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("アニメーションイージング関数をバックアウトに設定"));
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("アニメーションの非同期化に遅延を追加"));
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()
ターミナル出力の幅に一致し、描画されるコンポーネントの高さに一致するScreenInteractiveを作成します。
void Add(Component children)
子を追加します。 @param child 添付する子。
Definition component.cpp:69
static MenuOption HorizontalAnimated()
アニメーション付き水平メニューの標準オプション。 これはタブバーの実装に役立ちます。
Component Menu(MenuOption options)
テキストのリスト。フォーカスされた要素が選択されます。
Component Renderer(Component child, std::function< Element()>)
|child|に似ていますが、|render|をComponentRender()イベントとして使用する新しいコンポーネントを返します。
Element inverted(Element)
前景色と背景色を反転させるフィルターを追加します。
Definition inverted.cpp:32
Element text(std::wstring text)
ユニコードテキストを表示します。
Definition text.cpp:160
FTXUI ftxui:: 名前空間
Definition animation.hpp:9
Element borderEmpty(Element)
std::shared_ptr< ComponentBase > Component