当前位置:网站首页>Ftxui basic notes (Hello World)

Ftxui basic notes (Hello World)

2022-07-23 07:45:00 51CTO


The procedure is as follows , Build a single framework , You need to create a ftxui::Element, And show it in ftxui::Screen On .

      
      
#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;
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.

The effect after compilation and execution is as follows :

FTXUI Basic notes (hello world)_FTXUI

 


Module list
Project by 3 Modules :

ftxui/screen Defined a ftxui::Screen, One ftxui::Pixel The grid of .
ftxui/dom It's the main module . It defines a set of hierarchical ftxui::Element. An element is in ftxui::Screen Something is drawn on . It responds to the size of the container .
ftxui/component If the program needs to respond to user input , You need this module . It defines a set of ftxui::Component. These components can be used to navigate the program by using arrow keys and interacting with widgets such as check boxes . You can also make your own components . Users can use the arrow keys to navigate , And with the check box / Input box /... Wait for widgets to interact . You can create your own components .


The button procedure is 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/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.
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.

FTXUI Basic notes (hello world)_#include_02


 

ftxui::component The module defines generating response user events ( keyboard 、 Mouse, etc. ) The logic of interactive components .

ftxui::ScreenInteractive Defines a main loop of rendering components .

ftxui::Component It's pointing ftxui::ComponentBase Shared pointer to . The latter defines :

ftxui::ComponentBase::Render(): How to render the interface .
ftxui::ComponentBase::OnEvent(): How to respond to events .
ftxui::ComponentBase::Add(): Construct the parent-child relationship between two components . The component tree is used to define how to navigate using the keyboard .
ftxui::Element For rendering a single frame .

ftxui::Component For rendering dynamic user interface , Generate multiple frames , And update its status according to the event .


原网站

版权声明
本文为[51CTO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/07/202207222110365039.html