FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
button_animated.cpp
浏览该文件的文档.
1// 版权所有 2020 Arthur Sonzogni. 保留所有权利。
2// 此源代码的使用受 MIT 许可的约束,MIT 许可可在
3// LICENSE 文件中找到。
4#include <memory> // for shared_ptr, __shared_ptr_access
5#include <string> // for operator+, to_string
6
7#include "ftxui/component/captured_mouse.hpp" // for ftxui
8#include "ftxui/component/component.hpp" // for Button, Horizontal, Renderer
9#include "ftxui/component/component_base.hpp" // for ComponentBase
10#include "ftxui/component/component_options.hpp" // for ButtonOption
11#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
12#include "ftxui/dom/elements.hpp" // for gauge, separator, text, vbox, operator|, Element, border
13#include "ftxui/screen/color.hpp" // for Color, Color::Blue, Color::Green, Color::Red
14
15using namespace ftxui;
16
17int main() {
18 int value = 50;
19
20 // 组件树。这定义了如何使用键盘进行导航。
21 auto buttons = Container::Horizontal({
22 Button(
23 "Decrease", [&] { value--; }, ButtonOption::Animated(Color::Red)),
24 Button(
25 "Reset", [&] { value = 50; }, ButtonOption::Animated(Color::Green)),
26 Button(
27 "Increase", [&] { value++; }, ButtonOption::Animated(Color::Blue)),
28 });
29
30 // 修改它们在屏幕上的渲染方式:
31 auto component = Renderer(buttons, [&] {
32 return vbox({
33 vbox({
34 text("value = " + std::to_string(value)),
35 separator(),
36 gauge(value * 0.01f),
37 }) | border,
38 buttons->Render(),
39 });
40 });
41
42 auto screen = ScreenInteractive::FitComponent();
43 screen.Loop(component);
44 return 0;
45}
static ButtonOption Animated()
创建一个使用动画颜色的ButtonOption。
static ScreenInteractive FitComponent()
创建一个 ScreenInteractive,其宽度和高度与正在绘制的组件匹配。
Component Button(ButtonOption options)
绘制一个按钮。点击时执行一个函数。
Component Renderer(Component child, std::function< Element()>)
返回一个新组件,类似于 |child|,但使用 |render| 作为 Component::Render() 事件。
virtual void Render(Screen &screen)
在 ftxui::Screen 上显示元素。
Element text(std::wstring text)
显示一段Unicode文本。
Element separator()
在两个其他元素之间绘制垂直或水平分隔线。
Element vbox(Elements)
垂直一个接一个显示元素的容器。
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
Element gauge(float progress)
绘制一个高清进度条。