当前位置:网站首页>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-
边栏推荐
猜你喜欢

嵌入式开发:嵌入式基础——使用指针数组映射外设

秒杀项目收获

数据治理项目成功的要点,企业培养数据要把握好关键环节

【FreeRTOS】13 动态内存管理

商业智能BI行业分析思维框架:铅酸蓄电池行业(二)

如何将jpg静图做成gif动图?教你1分钟快速合成gif

推荐几款最好用的MySQL开源客户端,建议收藏!

Community News——Congratulations to Dolphin Scheduling China User Group for 9 new "Community Administrators"

An ABAP tool that can print the browsing history of a user in the system for BSP applications

Spike project harvest
随机推荐
Chapter one module of the re module,
x64汇编代码测试 用户模式和内核模式
Taurus.MVC WebAPI 入门开发教程4:控制器方法及参数定义、获取及基础校验属性【Require】。
匿名函数和全部内置函数详细认识(下篇)
不同主机收不到组播消息原因分析
简述 Mock 接口测试
腾讯云TDP-对象存储COS产品新用户福利
怎么截取视频做gif动图?手把手教你视频在线转gif制作
Cesium快速上手4-Polylines图元使用讲解
【21天学习挑战赛】折半查找
一个 ABAP Development Tool 自定义 service endpoint 的测试工具
A test tool for ABAP Development Tool custom service endpoint
玩转Redis|学会这10点让你分分钟拿下Redis,满足你的一切疑问
Methodology of multi-living in different places
架构设计之一——基础架构
8月Meetup | “数据调度+分析引擎”解锁企业数字化转型之路
LeetCode-876. Middle of the Linked List
力扣+牛客--刷题记录
北海 Kraken:基于 Flutter 构建的高性能 Web 渲染引擎
FP6378AS5CTR SOT - 23-5 effective 1 mhz2a synchronous buck regulator