FTXUI 6.1.9 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/captured_mouse.hpp" // for ftxui
8#include "ftxui/component/component.hpp" // for Button, Horizontal, Renderer
9#include "ftxui/component/component_base.hpp" // for ComponentBase
10#include "ftxui/component/component_options.hpp" // for ButtonOption
11#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
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
15 using namespace ftxui;
16
17 int main() {
18 int value = 50;
19
20 // The tree of components. This defines how to navigate using the keyboard.
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 // Modify the way to render them on screen:
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 = ScreenInteractive::FitComponent();
43 screen.Loop(component);
44 return 0;
45}
main
int main()
Definition button_animated.cpp:17
captured_mouse.hpp
color.hpp
component.hpp
component_base.hpp
component_options.hpp
elements.hpp
ftxui::ButtonOption::Animated
static ButtonOption Animated()
Create a ButtonOption, using animated colors.
Definition component_options.cpp:196
ftxui::ScreenInteractive::FitComponent
static ScreenInteractive FitComponent()
Definition screen_interactive.cpp:423
ftxui::Container::Horizontal
Component Horizontal(Components children)
A list of components, drawn one by one horizontally and navigated horizontally using left/right arrow...
Definition container.cpp:360
ftxui::Button
Component Button(ButtonOption options)
Draw a button. Execute a function when clicked.
Definition src/ftxui/component/button.cpp:175
ftxui::Renderer
Component Renderer(Component child, std::function< Element()>)
Return a new Component, similar to |child|, but using |render| as the Component::Render() event.
Definition src/ftxui/component/renderer.cpp:61
ftxui::Node::Render
virtual void Render(Screen &screen)
Display an element on a ftxui::Screen.
Definition node.cpp:59
ftxui::text
Element text(std::wstring text)
Display a piece of unicode text.
Definition text.cpp:160
ftxui::separator
Element separator()
Draw a vertical or horizontal separation in between two other elements.
Definition src/ftxui/dom/separator.cpp:134
ftxui::gauge
Element gauge(float progress)
Draw a high definition progress bar.
Definition src/ftxui/dom/gauge.cpp:293
ftxui::vbox
Element vbox(Elements)
A container displaying elements vertically one by one.
Definition vbox.cpp:96
ftxui::Color::Green
@ Green
Definition color.hpp:56
ftxui::Color::Red
@ Red
Definition color.hpp:55
ftxui::Color::Blue
@ Blue
Definition color.hpp:58
ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
screen_interactive.hpp