FTXUI 6.1.9 C++ functional terminal UI.

Loading...
Searching...
No Matches
button_in_frame.cpp
Go to the documentation of this file.
1// Copyright 2022 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 allocator, __shared_ptr_access, shared_ptr
5#include <string> // for to_string, operator+
6
7#include "ftxui/component/captured_mouse.hpp" // for ftxui
8#include "ftxui/component/component.hpp" // for Button, Renderer, Vertical
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 operator|, text, Element, hbox, separator, size, vbox, border, frame, vscroll_indicator, HEIGHT, LESS_THAN
13#include "ftxui/screen/color.hpp" // for Color, Color::Default, Color::GrayDark, Color::White
14
15 using namespace ftxui;
16
17 int main() {
18 int counter = 0;
19 auto on_click = [&] { counter++; };
20
21 auto style = ButtonOption::Animated(Color::Default, Color::GrayDark,
22 Color::Default, Color::White);
23
24 auto container = Container::Vertical({});
25 for (int i = 0; i < 30; ++i) {
26 auto button = Button("Button " + std::to_string(i), on_click, style);
27 container->Add(button);
28 }
29
30 auto renderer = Renderer(container, [&] {
31 return vbox({
32 hbox({
33 text("Counter:"),
34 text(std::to_string(counter)),
35 }),
36 separator(),
37 container->Render() | vscroll_indicator | frame |
38 size(HEIGHT, LESS_THAN, 20),
39 }) |
40 border;
41 });
42
43 auto screen = ScreenInteractive::FitComponent();
44 screen.Loop(renderer);
45
46 return 0;
47}
main
int main()
Definition button_in_frame.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::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::Container::Vertical
Component Vertical(Components children)
A list of components, drawn one by one vertically and navigated vertically using up/down arrow key or...
Definition container.cpp:317
ftxui::Node::Render
virtual void Render(Screen &screen)
Display an element on a ftxui::Screen.
Definition node.cpp:59
ftxui::size
Decorator size(WidthOrHeight, Constraint, int value)
Apply a constraint on the size of an element.
Definition src/ftxui/dom/size.cpp:89
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::vbox
Element vbox(Elements)
A container displaying elements vertically one by one.
Definition vbox.cpp:96
ftxui::Color::Default
@ Default
Definition color.hpp:50
ftxui::Color::White
@ White
Definition color.hpp:69
ftxui::Color::GrayDark
@ GrayDark
Definition color.hpp:62
ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
ftxui::HEIGHT
@ HEIGHT
Definition elements.hpp:161
ftxui::hbox
Element hbox(Elements)
A container displaying elements horizontally one by one.
Definition hbox.cpp:94
ftxui::LESS_THAN
@ LESS_THAN
Definition elements.hpp:162
screen_interactive.hpp