FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
button_in_frame.cpp
浏览该文件的文档.
1// 版权所有 2022 Arthur Sonzogni。保留所有权利。
2// 此源代码的使用受 MIT 许可证的管辖,该许可证可在以下文件中找到:
3// LICENSE 文件。
4#include <memory> // 用于 allocator, __shared_ptr_access, shared_ptr
5#include <string> // 用于 to_string, operator+
6
7#include "ftxui/component/captured_mouse.hpp" // 用于 ftxui
8#include "ftxui/component/component.hpp" // 用于 Button, Renderer, Vertical
9#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
10#include "ftxui/component/component_options.hpp" // 用于 ButtonOption
11#include "ftxui/component/screen_interactive.hpp" // 用于 ScreenInteractive
12#include "ftxui/dom/elements.hpp" // 用于 operator|, text, Element, hbox, separator, size, vbox, border, frame, vscroll_indicator, HEIGHT, LESS_THAN
13#include "ftxui/screen/color.hpp" // 用于 Color, Color::Default, Color::GrayDark, Color::White
14
15using namespace ftxui;
16
17int main() {
18 int counter = 0;
19 auto on_click = [&] { counter++; };
20
23
24 auto container = Container::Vertical({});
25 for (int i = 0; i < 30; ++i) {
26 auto button = Button("Button " + std::to_string(i), on_click, style);
27 container->Add(button);
28 }
29
30 auto renderer = Renderer(container, [&] {
31 return vbox({
32 hbox({
33 text("Counter:"),
34 text(std::to_string(counter)),
35 }),
36 separator(),
37 container->Render() | vscroll_indicator | frame |
38 size(HEIGHT, LESS_THAN, 20),
39 }) |
40 border;
41 });
42
43 auto screen = ScreenInteractive::FitComponent();
44 screen.Loop(renderer);
45
46 return 0;
47}
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 上显示元素。
Decorator size(WidthOrHeight, Constraint, int value)
对元素大小应用约束。
Element text(std::wstring text)
显示一段Unicode文本。
Element separator()
在两个其他元素之间绘制垂直或水平分隔线。
Element vbox(Elements)
垂直一个接一个显示元素的容器。
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
Element hbox(Elements)
一个按水平顺序逐一显示元素的容器。