FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
button_style.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 <string> // for operator+, to_string
5
6#include "ftxui/component/captured_mouse.hpp" // for ftxui
7#include "ftxui/component/component.hpp" // for Button, Vertical, Renderer, Horizontal, operator|
8#include "ftxui/component/component_base.hpp" // for Component
9#include "ftxui/component/component_options.hpp" // for ButtonOption
10#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
11#include "ftxui/dom/elements.hpp" // for Element, separator, text, border
12#include "ftxui/screen/color.hpp" // for Color, Color::Blue, Color::Green, Color::Red
13
14using namespace ftxui;
15
16int main() {
17 int value = 0;
18 auto action = [&] { value++; };
19 auto action_renderer =
20 Renderer([&] { return text("count = " + std::to_string(value)); });
21
22 auto buttons =
24 action_renderer,
25 Renderer([] { return separator(); }),
26 Container::Horizontal({
28 Button("Ascii 1", action, ButtonOption::Ascii()),
29 Button("Ascii 2", action, ButtonOption::Ascii()),
30 Button("Ascii 3", action, ButtonOption::Ascii()),
31 }),
32 Renderer([] { return separator(); }),
33 Container::Vertical({
34 Button("Simple 1", action, ButtonOption::Simple()),
35 Button("Simple 2", action, ButtonOption::Simple()),
36 Button("Simple 3", action, ButtonOption::Simple()),
37 }),
38 Renderer([] { return separator(); }),
39 Container::Vertical({
40 Button("Animated 1", action, ButtonOption::Animated()),
41 Button("Animated 2", action, ButtonOption::Animated()),
42 Button("Animated 3", action, ButtonOption::Animated()),
43 }),
44 Renderer([] { return separator(); }),
45 Container::Vertical({
46 Button("Animated 4", action,
48 Button("Animated 5", action,
50 Button("Animated 6", action,
52 }),
53 }),
54 }) |
55 border;
56
57 auto screen = ScreenInteractive::FitComponent();
58 screen.Loop(buttons);
59 return 0;
60}
int main()
static ButtonOption Animated()
Create a ButtonOption, using animated colors.
static ScreenInteractive FitComponent()
static ButtonOption Simple()
Create a ButtonOption, inverted when focused.
static ButtonOption Ascii()
Create a ButtonOption, highlighted using [] characters.
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.
Component Vertical(Components children)
A list of components, drawn one by one vertically and navigated vertically using up/down arrow key or...
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.
The FTXUI ftxui:: namespace.
Definition animation.hpp:10