FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
button_animated.cpp
Go to the documentation of this file.
1// 版權所有 2020 Arthur Sonzogni。保留所有權利。
2// 本原始碼的使用受 MIT 許可證的約束,該許可證可在 LICENSE 文件中找到。
3#include <memory> // 用於 shared_ptr, __shared_ptr_access
4#include <string> // for operator+, to_string
5
6#include "ftxui/component/captured_mouse.hpp" // 用於 ftxui
7#include "ftxui/component/component.hpp" // 用於 Button, Horizontal, Renderer
8#include "ftxui/component/component_base.hpp" // 用於 ComponentBase
9#include "ftxui/component/component_options.hpp" // 用於 ButtonOption
10#include "ftxui/component/screen_interactive.hpp" // 用於 ScreenInteractive
11#include "ftxui/dom/elements.hpp" // 用於 gauge, separator, text, vbox, operator|, Element, border
12#include "ftxui/screen/color.hpp" // 用於 Color, Color::Blue, Color::Green, Color::Red
13
14using namespace ftxui;
15
16int main() {
17 int value = 50;
18
19 // 元件樹。這定義了如何使用鍵盤導航。
20 auto buttons = Container::Horizontal({
21 Button(
22 "Decrease", [&] { value--; }, ButtonOption::Animated(Color::Red)),
23 Button(
24 "Reset", [&] { value = 50; }, ButtonOption::Animated(Color::Green)),
25 Button(
26 "Increase", [&] { value++; }, ButtonOption::Animated(Color::Blue)),
27 });
28
29 // 修改它們在螢幕上的渲染方式:
30 auto component = Renderer(buttons, [&] {
31 return vbox({
32 vbox({
33 text("value = " + std::to_string(value)),
34 separator(),
35 gauge(value * 0.01f),
36 }) | border,
37 buttons->Render(),
38 });
39 });
40
41 auto screen = ScreenInteractive::FitComponent();
42 screen.Loop(component);
43 return 0;
44}
int main()
auto component
Definition gallery.cpp:127
static ButtonOption Animated()
創建一個 ButtonOption,使用動畫顏色。
static ScreenInteractive FitComponent()
Component Button(ButtonOption options)
繪製一個按鈕。點擊時執行一個函數。
Component Renderer(Component child, std::function< Element()>)
回傳一個新的元件,類似於 |child|,但使用 |render| 作為 Component::Render() 事件。
virtual void Render(Screen &screen)
Element text(std::wstring text)
顯示一段 Unicode 文字。
Definition text.cpp:160
Element separator()
在兩個元素之間繪製垂直或水平分隔線。
Element gauge(float progress)
繪製一個高解析度進度條。
Element vbox(Elements)
一個垂直一個接一個顯示元素的容器。
Definition vbox.cpp:95
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10