FTXUI 6.1.9 C++ functional terminal UI.

Loading...
Searching...
No Matches
menu_entries_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 <iostream> // for basic_ostream::operator<<, operator<<, endl, basic_ostream, basic_ostream<>::__ostream_type, cout, ostream
5#include <memory> // for shared_ptr, __shared_ptr_access
6#include <string> // for to_string, allocator
7
8#include "ftxui/component/captured_mouse.hpp" // for ftxui
9#include "ftxui/component/component.hpp" // for MenuEntryAnimated, Renderer, Vertical
10#include "ftxui/component/component_base.hpp" // for ComponentBase
11#include "ftxui/component/component_options.hpp" // for MenuEntryAnimated
12#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
13#include "ftxui/dom/elements.hpp" // for operator|, separator, Element, Decorator, color, text, hbox, size, bold, frame, inverted, vbox, HEIGHT, LESS_THAN, border
14#include "ftxui/screen/color.hpp" // for Color, Color::Blue, Color::Cyan, Color::Green, Color::Red, Color::Yellow
15
16 using namespace ftxui;
17
18// Define a special style for some menu entry.
19 MenuEntryOption Colored(ftxui::Color c) {
20 MenuEntryOption option;
21 option.animated_colors.foreground.enabled = true;
22 option.animated_colors.background.enabled = true;
23 option.animated_colors.background.active = c;
24 option.animated_colors.background.inactive = Color::Black;
25 option.animated_colors.foreground.active = Color::White;
26 option.animated_colors.foreground.inactive = c;
27 return option;
28}
29
30 int main() {
31 auto screen = ScreenInteractive::TerminalOutput();
32
33 int selected = 0;
34 auto menu = Container::Vertical(
35 {
36 MenuEntry(" 1. rear", Colored(Color::Red)),
37 MenuEntry(" 2. drown", Colored(Color::Yellow)),
38 MenuEntry(" 3. nail", Colored(Color::Green)),
39 MenuEntry(" 4. quit", Colored(Color::Cyan)),
40 MenuEntry(" 5. decorative", Colored(Color::Blue)),
41 MenuEntry(" 7. costume"),
42 MenuEntry(" 8. pick"),
43 MenuEntry(" 9. oral"),
44 MenuEntry("11. minister"),
45 MenuEntry("12. football"),
46 MenuEntry("13. welcome"),
47 MenuEntry("14. copper"),
48 MenuEntry("15. inhabitant"),
49 },
50 &selected);
51
52 // Display together the menu with a border
53 auto renderer = Renderer(menu, [&] {
54 return vbox({
55 hbox(text("selected = "), text(std::to_string(selected))),
56 separator(),
57 menu->Render() | frame,
58 }) |
59 border | bgcolor(Color::Black);
60 });
61
62 screen.Loop(renderer);
63
64 std::cout << "Selected element = " << selected << std::endl;
65}
captured_mouse.hpp
color.hpp
component.hpp
component_base.hpp
component_options.hpp
elements.hpp
ftxui::ScreenInteractive::TerminalOutput
static ScreenInteractive TerminalOutput()
Definition screen_interactive.cpp:410
ftxui::AnimatedColorOption::active
Color active
Definition component_options.hpp:66
ftxui::AnimatedColorOption::enabled
bool enabled
Definition component_options.hpp:64
ftxui::AnimatedColorOption::inactive
Color inactive
Definition component_options.hpp:65
ftxui::MenuEntryOption::animated_colors
AnimatedColorsOption animated_colors
Definition component_options.hpp:81
ftxui::MenuEntry
Component MenuEntry(MenuEntryOption options)
A specific menu entry. They can be put into a Container::Vertical to form a menu.
Definition src/ftxui/component/menu.cpp:614
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::MenuEntryOption
Option for the MenuEntry component.
Definition component_options.hpp:78
ftxui::Node::Render
virtual void Render(Screen &screen)
Display an element on a ftxui::Screen.
Definition node.cpp:59
ftxui::bgcolor
Decorator bgcolor(Color)
Decorate using a background color.
Definition dom/color.cpp:124
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::Cyan
@ Cyan
Definition color.hpp:60
ftxui::Color::White
@ White
Definition color.hpp:69
ftxui::Color::Yellow
@ Yellow
Definition color.hpp:57
ftxui::Color::Black
@ Black
Definition color.hpp:54
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::Color
Color is a class that represents a color in the terminal user interface.
Definition color.hpp:22
Colored
MenuEntryOption Colored(ftxui::Color c)
Definition menu_entries_animated.cpp:19
main
int main()
Definition menu_entries_animated.cpp:30
ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
ftxui::hbox
Element hbox(Elements)
A container displaying elements horizontally one by one.
Definition hbox.cpp:94
ftxui::frame
Element frame(Element)
Allow an element to be displayed inside a 'virtual' area. It size can be larger than its container....
Definition frame.cpp:118
screen_interactive.hpp
ftxui::AnimatedColorsOption::foreground
AnimatedColorOption foreground
Definition component_options.hpp:73
ftxui::AnimatedColorsOption::background
AnimatedColorOption background
Definition component_options.hpp:72