当前位置:网站首页>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 用于渲染动态用户界面,生成多个帧,并根据事件更新其状态。
边栏推荐
猜你喜欢

WIZnet 物联网设计大赛 - WizFi360大赛延迟通知

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

自助服务知识库是什么?

面了个腾讯25k+出来的,他让我见识到什么基础的天花板

2022 CCF中国开源大会会议通知(第四轮)

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

Servlet简单项目操作

如何将jpg图片变成gif?教你一分钟图片合成gif的方法

Colocate Join :ClickHouse的一种高性能分布式join查询模型

An ABAP tool that can print the browsing history of a user in the system for BSP applications
随机推荐
简述 Mock 接口测试
2025年推出 奥迪透露将推出大型SUV产品
PNG如何变gif?教你一招png秒变gif动图的方法
spark面试常问问题
FTXUI基础笔记(botton按钮组件进阶)
An ABAP tool that can print the browsing history of a user in the system for BSP applications
Colocate Join :ClickHouse的一种高性能分布式join查询模型
一文带你了解 HONOR Connect
LeetCode-692. Top K Frequent Words
Etcd Kubernetes 集群稳定性:LIST 请求源码分析、性能评估与大规模基础服务部署调优
积分可以当钱用,阿里推出个人「碳账户」
Please check the preparation guide for the 2022 Huawei Developer Competition
使用 ABAP 正则表达式解析 uuid 的值
二叉树详解
A Sina Weibo semantic sentiment analysis tool developed by ABAP
Parse the value of uuid using ABAP regular expressions
Taurus.MVC WebAPI 入门开发教程4:控制器方法及参数定义、获取及基础校验属性【Require】。
腾讯云TDP-对象存储COS产品新用户福利
【服务器数据恢复】raid5崩溃导致lvm信息和VXFS文件系统损坏的数据恢复案例
ExceptionInInitializerError