当前位置:网站首页>FTXUI基础笔记(botton按钮组件基础)
FTXUI基础笔记(botton按钮组件基础)
2022-08-10 15:57:00 【zhangrelay】
先看原版示例程序吧:
#include <memory> // for shared_ptr, __shared_ptr_access
#include <string> // for operator+, to_string
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Button, Horizontal, Renderer
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
#include "ftxui/dom/elements.hpp" // for separator, gauge, text, Element, operator|, vbox, border
using namespace ftxui;
int main(int argc, const char* argv[]) {
int value = 50;
// The tree of components. This defines how to navigate using the keyboard.
auto buttons = Container::Horizontal({
Button("计数加1", [&] { value--; }),
Button("计数减1", [&] { value++; }),
});
// Modify the way to render them on screen:
auto component = Renderer(buttons, [&] {
return vbox({
text(" 数值 = " + std::to_string(value)),
separator(),
gauge(value * 0.01f),
separator(),
buttons->Render(),
}) |
border;
});
auto screen = ScreenInteractive::FitComponent();
screen.Loop(component);
return 0;
}
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
默认数值为50。点击按键实现加减1功能。
简要解释一下:
头文件部分
#include <memory> // for shared_ptr, __shared_ptr_access #include <string> // for operator+, to_string #include "ftxui/component/captured_mouse.hpp" // for ftxui #include "ftxui/component/component.hpp" // for Button, Horizontal, Renderer #include "ftxui/component/component_base.hpp" // for ComponentBase #include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive #include "ftxui/dom/elements.hpp" // for separator, gauge, text, Element, operator|, vbox, border
按钮属性,包括点击后功能
// The tree of components. This defines how to navigate using the keyboard. auto buttons = Container::Horizontal({ Button("计数加1", [&] { value--; }), Button("计数减1", [&] { value++; }), });
整体在终端的显示:
// Modify the way to render them on screen: auto component = Renderer(buttons, [&] { return vbox({ text(" 数值 = " + std::to_string(value)), separator(), gauge(value * 0.01f), separator(), buttons->Render(), }) | border; });
程序bug,加减写反了:
自行修订即可。
这个功能太简陋了,原版复杂一些的示例如下:
#include <memory> // for shared_ptr, __shared_ptr_access
#include <string> // for operator+, to_string
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Button, Horizontal, Renderer
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/component_options.hpp" // for ButtonOption
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
#include "ftxui/dom/elements.hpp" // for gauge, separator, text, vbox, operator|, Element, border
#include "ftxui/screen/color.hpp" // for Color, Color::Blue, Color::Green, Color::Red
using namespace ftxui;
int main(int argc, const char* argv[]) {
int value = 50;
// The tree of components. This defines how to navigate using the keyboard.
auto buttons = Container::Horizontal({
Button(
"计数减一", [&] { value--; }, ButtonOption::Animated(Color::Red)),
Button(
"复位(默认50)", [&] { value = 50; }, ButtonOption::Animated(Color::Green)),
Button(
"计数加一", [&] { value++; }, ButtonOption::Animated(Color::Blue)),
});
// Modify the way to render them on screen:
auto component = Renderer(buttons, [&] {
return vbox({
vbox({
text(" 数值 = " + std::to_string(value)),
separator(),
gauge(value * 0.01f),
}) | border,
buttons->Render(),
});
});
auto screen = ScreenInteractive::FitComponent();
screen.Loop(component);
return 0;
}
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
减
复位
加
看起来效果好一些。
改变之处:
// The tree of components. This defines how to navigate using the keyboard. auto buttons = Container::Horizontal({ Button( "计数减一", [&] { value--; }, ButtonOption::Animated(Color::Red)), Button( "复位(默认50)", [&] { value = 50; }, ButtonOption::Animated(Color::Green)), Button( "计数加一", [&] { value++; }, ButtonOption::Animated(Color::Blue)), });
-End-
边栏推荐
- Parse the value of uuid using ABAP regular expressions
- I met a 25k+ from Tencent, he let me see what kind of basic ceiling
- 2022 CCF中国开源大会会议通知(第四轮)
- Scala collections
- 商业版SSL证书
- Colocate Join :ClickHouse的一种高性能分布式join查询模型
- Yann LeCun转推:参数减少50倍,性能还更好,MetaAI推出Atlas信息检索模型
- E-commerce spike project harvest (2)
- Mobileye joins hands with Krypton to open a new chapter in advanced driver assistance through OTA upgrade
- 视频转成gif动图怎么操作?仅需三步在线完成视频转gif
猜你喜欢
Colocate Join :ClickHouse的一种高性能分布式join查询模型
Community News——Congratulations to Dolphin Scheduling China User Group for 9 new "Community Administrators"
I met a 25k+ from Tencent, he let me see what kind of basic ceiling
Exchange Online审计和监控
Kubernetes kube-proxy工作原理
26、压缩及解压缩命令
[FreeRTOS] 13 Dynamic Memory Management
字符串压缩(三)之短字符串压缩
A test tool for ABAP Development Tool custom service endpoint
一个 ABAP 工具,能打印系统里某个用户对 BSP 应用的浏览历史记录
随机推荐
力扣+牛客--刷题记录
【21天学习挑战赛】直接选择排序
FFmpeg 交叉编译
WinUI 3 Fundamentals 5小时教学视频
Community News——Congratulations to Dolphin Scheduling China User Group for 9 new "Community Administrators"
一文带你了解 HONOR Connect
Kubernetes kube-proxy工作原理
IPC:Interrupts and Signals
软件配置 | pip下载第三方库文件及配置pip源的不完全总结
Scala collections
如何将静图变gif动图?教你jpg合成gif的方法
基础填空以及编程题
Taurus.MVC WebAPI 入门开发教程4:控制器方法及参数定义、获取及基础校验属性【Require】。
利用SparkLauncher 提交Job
FP6378AS5CTR SOT - 23-5 effective 1 mhz2a synchronous buck regulator
怎么设计产品手册?用什么设计产品手册?
【Windows】将排除项添加到安全中心以避免exe被系统自动删除
北海 Kraken:基于 Flutter 构建的高性能 Web 渲染引擎
spark面试常问问题
cmake record