当前位置:网站首页>Ftxui basic notes (botton button component Foundation)
Ftxui basic notes (botton button component Foundation)
2022-07-19 04:15:00 【zhangrelay】

Let's look at the original sample program first :
#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(" Count plus 1", [&] { value--; }),
Button(" Count minus 1", [&] { value++; }),
});
// Modify the way to render them on screen:
auto component = Renderer(buttons, [&] {
return vbox({
text(" The number = " + 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.The default value is 50. Click the button to add or subtract 1 function .

A brief explanation :
Header file section
#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
Button properties , Including post click function
// The tree of components. This defines how to navigate using the keyboard.
auto buttons = Container::Horizontal({
Button(" Count plus 1", [&] { value--; }),
Button(" Count minus 1", [&] { value++; }),
});
Overall display on the terminal :
// Modify the way to render them on screen:
auto component = Renderer(buttons, [&] {
return vbox({
text(" The number = " + std::to_string(value)),
separator(),
gauge(value * 0.01f),
separator(),
buttons->Render(),
}) |
border;
});
Program bug, Addition and subtraction are reversed :

You can revise it yourself .
This function is too simple , Examples of the more complex original are as follows :
#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(
" Count minus one ", [&] { value--; }, ButtonOption::Animated(Color::Red)),
Button(
" Reset ( Default 50)", [&] { value = 50; }, ButtonOption::Animated(Color::Green)),
Button(
" Counting plus one ", [&] { value++; }, ButtonOption::Animated(Color::Blue)),
});
// Modify the way to render them on screen:
auto component = Renderer(buttons, [&] {
return vbox({
vbox({
text(" The number = " + 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.
reduce

Reset
Add
It looks better .
What changed :
// The tree of components. This defines how to navigate using the keyboard.
auto buttons = Container::Horizontal({
Button(
" Count minus one ", [&] { value--; }, ButtonOption::Animated(Color::Red)),
Button(
" Reset ( Default 50)", [&] { value = 50; }, ButtonOption::Animated(Color::Green)),
Button(
" Counting plus one ", [&] { value++; }, ButtonOption::Animated(Color::Blue)),
});
-End-
边栏推荐
- Intel helps open medical service and promote the intellectualization of ultrasonic prenatal examination
- VS Code 常用快捷键
- Unity - 如何修改一个 Package 或是如何将 Package Local化
- Unity shader - "fast SSS: fast subsurface scattering"
- priority_queue的介绍及其使用
- 基于stm32f103的智能风扇系统
- Smart fan system based on STM32F103
- 若依框架包名修改器
- 小程序毕设作品之微信电子书阅读小程序毕业设计(8)毕业设计论文模板
- 超视频时代,数据洪峰何解?
猜你喜欢

Openresty 做静态资源服务器

高性能与经济性兼备:傲腾 持久内存助力移动云应对严苛内存挑战

To build agile teams, these methods are indispensable

Chapter 1 performance platform godeye source code analysis - overall architecture

EAS(能量感知调度)绿色节能调度器

小程序毕设作品之微信电子书阅读小程序毕业设计(1)开发概要

Wechat e-book reading applet graduation design of applet completion works (1) development outline

High performance and economy: aoteng persistent memory helps mobile cloud cope with severe memory challenges

mqant 深入分析

英特尔助力开立医疗推动超声产检智能化
随机推荐
[database] knowledge and skills at the end of the term ----- Chapter 9 database design
MAUI 框架入门学习05 MVVM数据模型理解
2022 Yangtze River Delta mathematical modeling: Gearbox Fault Diagnosis
[database] must know at the end of the term ----- Chapter VII database integrity
基于OpenVINO Model Server打造人像抠图服务器
Niuke 2021 training League warm-up training match interstellar love (and search Collection)
Some problems after xcode11 new project
C# 构造函数(Constructors)简单讲解
小程序毕设作品之微信电子书阅读小程序毕业设计(6)开题答辩PPT
Intel helps open medical service and promote the intellectualization of ultrasonic prenatal examination
[seventh issue of notebook series] download and use of openvino pre training model
AttributeError: ‘NoneType‘ object has no attribute ‘sort‘
Nearly 90% of servers can be saved, but the anti fraud efficiency has increased significantly. Why is PayPal's plan to break the "Ai memory wall" so cost-effective?
Micro, m3o micro service series (III)
Live broadcast of cloud intelligence face to face is waiting for you: computing power redefines productivity
【黄啊码】MySQL入门—5、数据库小技巧:单个列group by就会,多个列呢?
sql界面切换不能获取焦点
[database] must know at the end of the term ----- Chapter 6 experiment
FTXUI基础笔记(botton按钮组件基础)
[database] must know and be able at the end of the term ----- Chapter 1 database overview