当前位置:网站首页>FTXUI基础笔记(hello world)
FTXUI基础笔记(hello world)
2022-08-10 15:57:00 【zhangrelay】
程序如下,构建单个框架,需要创建一个 ftxui::Element,并将其显示在 ftxui::Screen 上。
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#include <iostream>
int main(void) {
using namespace ftxui;
// Define the document
Element document =
hbox({
text("ros1") | border,
text("bridge") | border | flex,
text("ros2") | border,
});
auto screen = Screen::Create(
Dimension::Full(), // Width
Dimension::Fit(document) // Height
);
Render(screen, document);
screen.Print();
return EXIT_SUCCESS;
}
编译执行后效果如下:
模块列表 项目由3个模块组成:
ftxui/screen 定义了一个 ftxui::Screen,一个 ftxui::Pixel 的网格。 ftxui/dom 是主要模块。 它定义了一组分层的 ftxui::Element。 一个元素在 ftxui::Screen 上绘制了一些东西。 它响应容器的大小。 ftxui/component 如果程序需要响应用户输入,则需要该模块。 它定义了一组 ftxui::Component。 这些组件可用于通过使用箭头键和与复选框等小部件进行交互来导航程序。 也可以制作自己的组件。 用户可以使用箭头键进行导航,并与复选框/输入框/...等小部件进行交互。可以创建自己的组件。
按钮程序如下:
#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 = 0;
// The tree of components. This defines how to navigate using the keyboard.
auto buttons = Container::Horizontal({
Button("Hello ROS2", [&] { value++; }),
});
// Modify the way to render them on screen:
auto component = Renderer(buttons, [&] {
return vbox({
text("click = " + 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.
ftxui::component 模块定义了生成响应用户事件(键盘、鼠标等)的交互式组件的逻辑。
ftxui::ScreenInteractive 定义了一个渲染组件的主循环。
ftxui::Component 是指向 ftxui::ComponentBase 的共享指针。 后者定义:
ftxui::ComponentBase::Render():如何渲染界面。 ftxui::ComponentBase::OnEvent():如何对事件做出反应。 ftxui::ComponentBase::Add():构造两个组件之间的父子关系。 组件树用于定义如何使用键盘进行导航。 ftxui::Element 用于渲染单个帧。
ftxui::Component 用于渲染动态用户界面,生成多个帧,并根据事件更新其状态。
边栏推荐
- openpyxl绘制堆叠图
- 可以在家干的兼职都有哪些呢?做自媒体怎么样?
- 易基因|深度综述:m6A RNA甲基化在大脑发育和疾病中的表观转录调控作用
- Brainstorm: Goals and
- 如何将jpg静图做成gif动图?教你1分钟快速合成gif
- Spike project harvest
- String compression (3) short string compression
- An ABAP tool that can print the browsing history of a user in the system for BSP applications
- 自助服务知识库是什么?
- 超越神经缩放法则:通过数据剪枝
猜你喜欢
力扣+牛客--刷题记录
如何将jpg图片变成gif?教你一分钟图片合成gif的方法
MySQL的使用演示及操作,MySQL数据字符集的设置
【21天学习挑战赛】直接选择排序
软件配置 | pip下载第三方库文件及配置pip源的不完全总结
[FreeRTOS] 13 Dynamic Memory Management
【Windows】将排除项添加到安全中心以避免exe被系统自动删除
Recommend a few had better use the MySQL open source client, collection!
openpyxl绘制堆叠图
I met a 25k+ from Tencent, he let me see what kind of basic ceiling
随机推荐
LeetCode-876. Middle of the Linked List
Copper lock password library
FP6378AS5CTR SOT - 23-5 effective 1 mhz2a synchronous buck regulator
Oracle database backup DMP file is too big, what method can be split into multiple DMP when backup?
Etcd Kubernetes 集群稳定性:LIST 请求源码分析、性能评估与大规模基础服务部署调优
Zotero 开源文献管理工具
积分可以当钱用,阿里推出个人「碳账户」
Community News——Congratulations to Dolphin Scheduling China User Group for 9 new "Community Administrators"
多线程面试指南
商业智能BI行业分析思维框架:铅酸蓄电池行业(二)
5G NR MIB Detailed Explanation
cmake record
Mobileye携手极氪通过OTA升级开启高级驾驶辅助新篇章
String compression (3) short string compression
常用持续集成工具对比
怎么学自动化测试
不爱生活的段子手不是好设计师|ONES 人物
【服务器数据恢复】raid5崩溃导致lvm信息和VXFS文件系统损坏的数据恢复案例
[FreeRTOS] 13 Dynamic Memory Management
WinUI 3 Fundamentals 5小时教学视频