FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
button_style.cpp
浏览该文件的文档.
1// 版权所有 2020 Arthur Sonzogni。保留所有权利。
2// 本源代码受 MIT 许可证的约束,可在
3// LICENSE 文件中找到。
4#include <string> // 用于 operator+,to_string
5
6#include "ftxui/component/captured_mouse.hpp" // 用于 ftxui
7#include "ftxui/component/component.hpp" // 用于 Button, Vertical, Renderer, Horizontal, operator|
8#include "ftxui/component/component_base.hpp" // 用于 Component
9#include "ftxui/component/component_options.hpp" // 用于 ButtonOption
10#include "ftxui/component/screen_interactive.hpp" // 用于 ScreenInteractive
11#include "ftxui/dom/elements.hpp" // 用于 Element, separator, text, border
12#include "ftxui/screen/color.hpp" // 用于 Color, Color::Blue, Color::Green, Color::Red
13
14using namespace ftxui;
15
16int main() {
17 int value = 0;
18 auto action = [&] { value++; };
19 auto action_renderer =
20 Renderer([&] { return text("count = " + std::to_string(value)); });
21
22 auto buttons =
23 Container::Vertical({
24 action_renderer,
25 Renderer([] { return separator(); }),
26 Container::Horizontal({
27 Container::Vertical({
28 Button("Ascii 1", action, ButtonOption::Ascii()),
29 Button("Ascii 2", action, ButtonOption::Ascii()),
30 Button("Ascii 3", action, ButtonOption::Ascii()),
31 }),
32 Renderer([] { return separator(); }),
33 Container::Vertical({
34 Button("Simple 1", action, ButtonOption::Simple()),
35 Button("Simple 2", action, ButtonOption::Simple()),
36 Button("Simple 3", action, ButtonOption::Simple()),
37 }),
38 Renderer([] { return separator(); }),
39 Container::Vertical({
40 Button("Animated 1", action, ButtonOption::Animated()),
41 Button("Animated 2", action, ButtonOption::Animated()),
42 Button("Animated 3", action, ButtonOption::Animated()),
43 }),
44 Renderer([] { return separator(); }),
45 Container::Vertical({
46 Button("Animated 4", action,
48 Button("Animated 5", action,
50 Button("Animated 6", action,
52 }),
53 }),
54 }) |
55 border;
56
57 auto screen = ScreenInteractive::FitComponent();
58 screen.Loop(buttons);
59 return 0;
60}
int main()
static ButtonOption Animated()
创建一个使用动画颜色的ButtonOption。
static ScreenInteractive FitComponent()
创建一个 ScreenInteractive,其宽度和高度与正在绘制的组件匹配。
static ButtonOption Simple()
创建一个ButtonOption,聚焦时反转显示。
static ButtonOption Ascii()
创建一个ButtonOption,使用[]字符高亮显示。
Component Button(ButtonOption options)
绘制一个按钮。点击时执行一个函数。
Component Renderer(Component child, std::function< Element()>)
返回一个新组件,类似于 |child|,但使用 |render| 作为 Component::Render() 事件。
Element text(std::wstring text)
显示一段Unicode文本。
Element separator()
在两个其他元素之间绘制垂直或水平分隔线。
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase