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
15using namespace ftxui;
16
17int 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}
int main()
static ButtonOption Animated()
Create a ButtonOption, using animated colors.
static ScreenInteractive FitComponent()
Component Horizontal(Components children)
A list of components, drawn one by one horizontally and navigated horizontally using left/right arrow...
Component Button(ButtonOption options)
Draw a button. Execute a function when clicked.
Component Renderer(Component child, std::function< Element()>)
Return a new Component, similar to |child|, but using |render| as the Component::Render() event.
virtual void Render(Screen &screen)
Display an element on a ftxui::Screen.
Definition node.cpp:59
Element text(std::wstring text)
Display a piece of unicode text.
Definition text.cpp:160
Element separator()
Draw a vertical or horizontal separation in between two other elements.
Element gauge(float progress)
Draw a high definition progress bar.
Element vbox(Elements)
A container displaying elements vertically one by one.
Definition vbox.cpp:96
The FTXUI ftxui:: namespace.
Definition animation.hpp:10