FTXUI 6.1.9 C++ functional terminal UI.

Loading...
Searching...
No Matches
examples/component/selection.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 char_traits, operator+, string, basic_string
5
6#include "ftxui/component/component.hpp" // for Input, Renderer, Vertical
7#include "ftxui/component/component_base.hpp" // for ComponentBase
8#include "ftxui/component/component_options.hpp" // for InputOption
9#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
10#include "ftxui/dom/elements.hpp" // for text, hbox, separator, Element, operator|, vbox, border
11#include "ftxui/util/ref.hpp" // for Ref
12
13 using namespace ftxui;
14
15 Element LoremIpsum() {
16 return vbox({
17 text("FTXUI: A powerful library for building user interfaces."),
18 text("Enjoy a rich set of components and a declarative style."),
19 text("Create beautiful and responsive UIs with minimal effort."),
20 text("Join the community and experience the power of FTXUI."),
21 });
22}
23
24 int main() {
25 auto screen = ScreenInteractive::TerminalOutput();
26
27 auto quit =
28 Button("Quit", screen.ExitLoopClosure(), ButtonOption::Animated());
29
30 int selection_change_counter = 0;
31 std::string selection_content = "";
32 screen.SelectionChange([&] {
33 selection_change_counter++;
34 selection_content = screen.GetSelection();
35 });
36
37 // The components:
38 auto renderer = Renderer(quit, [&] {
39 return vbox({
40 text("Select changed: " + std::to_string(selection_change_counter) +
41 " times"),
42 text("Currently selected: "),
43 paragraph(selection_content) | vscroll_indicator | frame | border |
44 size(HEIGHT, EQUAL, 10),
45 window(text("Horizontal split"), hbox({
46 LoremIpsum(),
47 separator(),
48 LoremIpsum(),
49 separator(),
50 LoremIpsum(),
51 })),
52 window(text("Vertical split"), vbox({
53 LoremIpsum(),
54 separator(),
55 LoremIpsum(),
56 separator(),
57 LoremIpsum(),
58 })),
59 window(text("Grid split with different style"),
60 vbox({
61 hbox({
62 LoremIpsum(),
63 separator(),
64 LoremIpsum() //
65 | selectionBackgroundColor(Color::Yellow) //
66 | selectionColor(Color::Black) //
67 | selectionStyleReset,
68 separator(),
69 LoremIpsum() | selectionColor(Color::Blue),
70 }),
71 separator(),
72 hbox({
73 LoremIpsum() | selectionColor(Color::Red),
74 separator(),
75 LoremIpsum() | selectionStyle([](Pixel& pixel) {
76 pixel.underlined_double = true;
77 }),
78 separator(),
79 LoremIpsum(),
80 }),
81 })),
82 quit->Render(),
83 });
84 });
85
86 screen.Loop(renderer);
87}
component.hpp
component_base.hpp
component_options.hpp
elements.hpp
LoremIpsum
Element LoremIpsum()
Definition examples/component/selection.cpp:15
main
int main()
Definition examples/component/selection.cpp:24
ftxui::ButtonOption::Animated
static ButtonOption Animated()
Create a ButtonOption, using animated colors.
Definition component_options.cpp:196
ftxui::ScreenInteractive::TerminalOutput
static ScreenInteractive TerminalOutput()
Definition screen_interactive.cpp:410
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::window
Element window(Element title, Element content, BorderStyle border=ROUNDED)
Draw window with a title and a border around the element.
Definition src/ftxui/dom/border.cpp:507
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::Yellow
@ Yellow
Definition color.hpp:57
ftxui::Color::Black
@ Black
Definition color.hpp:54
ftxui::Color::Red
@ Red
Definition color.hpp:55
ftxui::Color::Blue
@ Blue
Definition color.hpp:58
ftxui::Pixel::underlined_double
bool underlined_double
Definition pixel.hpp:34
ftxui::Pixel
A Unicode character and its associated style.
Definition pixel.hpp:15
ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
ftxui::HEIGHT
@ HEIGHT
Definition elements.hpp:161
ftxui::Element
std::shared_ptr< Node > Element
Definition elements.hpp:22
ftxui::selectionStyle
Decorator selectionStyle(std::function< void(Pixel &)> style)
Set the style of an element when selected.
Definition selection_style.cpp:86
ftxui::hbox
Element hbox(Elements)
A container displaying elements horizontally one by one.
Definition hbox.cpp:94
ftxui::selectionBackgroundColor
Decorator selectionBackgroundColor(Color foreground)
Set the background color of an element when selected. Note that the style is applied on top of the ex...
Definition selection_style.cpp:61
ftxui::selectionColor
Decorator selectionColor(Color foreground)
Set the color of an element when selected.
Definition selection_style.cpp:78
ftxui::selectionStyleReset
Element selectionStyleReset(Element)
Reset the selection style of an element.
Definition selection_style.cpp:55
ftxui::paragraph
Elements paragraph(std::wstring text)
ftxui::EQUAL
@ EQUAL
Definition elements.hpp:162
ref.hpp
screen_interactive.hpp