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
13using namespace ftxui;
14
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
24int main() {
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() //
68 separator(),
70 }),
71 separator(),
72 hbox({
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}
virtual void Render(Screen &screen)
Display an element on a ftxui::Screen.
Definition node.cpp:63
static ScreenInteractive TerminalOutput()
Element LoremIpsum()
Element window(Element title, Element content, BorderStyle border=ROUNDED)
Draw window with a title and a border around the element.
Element vscroll_indicator(Element)
Display a vertical scrollbar to the right. colors.
Decorator size(WidthOrHeight, Constraint, int value)
Apply a constraint on the size of an element.
std::shared_ptr< Node > Element
Definition elements.hpp:22
Decorator selectionStyle(std::function< void(Pixel &)> style)
Set the style of an element when selected.
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.
Element hbox(Elements)
A container displaying elements horizontally one by one.
Definition hbox.cpp:94
Decorator selectionBackgroundColor(Color foreground)
Set the background color of an element when selected. Note that the style is applied on top of the ex...
Element text(std::wstring text)
Display a piece of unicode text.
Definition text.cpp:160
Decorator selectionColor(Color foreground)
Set the color of an element when selected.
Element selectionStyleReset(Element)
Reset the selection style of an element.
Element separator()
Draw a vertical or horizontal separation in between two other elements.
Elements paragraph(std::wstring text)
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
Element border(Element)
Draw a border around the element.
Element vbox(Elements)
A container displaying elements vertically one by one.
Definition vbox.cpp:96
static ButtonOption Animated()
Create a ButtonOption, using animated colors.
A Unicode character and its associated style.
Definition pixel.hpp:15
bool underlined_double
Definition pixel.hpp:34