FTXUI 7.0.3
C++ functional terminal UI.
Loading...
Searching...
No Matches
button_animated.cpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4#include <memory> // for shared_ptr, __shared_ptr_access
5#include <string> // for operator+, to_string
6
7#include "ftxui/component/app.hpp" // for App
8#include "ftxui/component/captured_mouse.hpp" // for ftxui
9#include "ftxui/component/component.hpp" // for Button, Horizontal, Renderer
10#include "ftxui/component/component_base.hpp" // for ComponentBase
11#include "ftxui/component/component_options.hpp" // for ButtonOption
12#include "ftxui/dom/elements.hpp" // for gauge, separator, text, vbox, operator|, Element, border
13#include "ftxui/screen/color.hpp" // for Color, Color::Blue, Color::Green, Color::Red
14
15using namespace ftxui;
16
17int main() {
18 int value = 50;
19
20 // L'arbre de composants. Cela définit comment naviguer en utilisant le clavier.
21 auto buttons = Container::Horizontal({
22 Button(
23 "Decrease", [&] { value--; }, ButtonOption::Animated(Color::Red)),
24 Button(
25 "Reset", [&] { value = 50; }, ButtonOption::Animated(Color::Green)),
26 Button(
27 "Increase", [&] { value++; }, ButtonOption::Animated(Color::Blue)),
28 });
29
30 // Modifier la façon de les afficher à l'écran :
31 auto component = Renderer(buttons, [&] {
32 return vbox({
33 vbox({
34 text("value = " + std::to_string(value)),
35 separator(),
36 gauge(value * 0.01f),
37 }) | border,
38 buttons->Render(),
39 });
40 });
41
42 auto screen = App::FitComponent();
43 screen.Loop(component);
44 return 0;
45}
int main()
Component Button(ConstStringRef label, std::function< void()> on_click, ButtonOption options=ButtonOption::Simple())
Dessine un bouton. Exécute une fonction lorsqu'il est cliqué.
Component Renderer(Component child, std::function< Element()>)
Retourne un nouveau Component, similaire à |child|, mais utilisant |render| comme événement Component...
Element text(std::string_view text)
Affiche un morceau de texte unicode encodé en UTF8.
Element separator()
Dessine une séparation verticale ou horizontale entre deux autres éléments.
Element gauge(float progress)
Dessine une barre de progression haute définition.
Element vbox(Elements children)
Un conteneur affichant les éléments verticalement un par un.
Definition vbox.cpp:96
L'espace de noms FTXUI ftxui::
Definition animation.hpp:11
int value
Definition elements.hpp:195