FTXUI 7.0.3
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/app.hpp" // for Component, App
7#include "ftxui/component/component.hpp" // for Input, Renderer, Vertical
8#include "ftxui/component/component_base.hpp" // for ComponentBase
9#include "ftxui/component/component_options.hpp" // for InputOption
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 text(
17 "FTXUI: A powerful library for building user interfaces.\n"
18 "Enjoy a rich set of components and a declarative style.\n"
19 "Create beautiful and responsive UIs with minimal effort.\n"
20 "Join the community and experience the power of FTXUI.");
21}
22
23int main() {
24 auto screen = App::TerminalOutput();
25
26 auto quit =
27 Button("Quit", screen.ExitLoopClosure(), ButtonOption::Animated());
28
29 int selection_change_counter = 0;
30 std::string selection_content = "";
31 screen.SelectionChange([&] {
32 selection_change_counter++;
33 selection_content = screen.GetSelection();
34 });
35
36 // pour Ref
37 auto renderer = Renderer(quit, [&] {
38 return vbox({
39 text("Select changed: " + std::to_string(selection_change_counter) +
40 " times"),
41 text("Currently selected: "),
42 paragraph(selection_content) | vscroll_indicator | frame | border |
43 size(HEIGHT, EQUAL, 10),
44 window(text("Horizontal split"), hbox({
45 LoremIpsum(),
46 separator(),
47 LoremIpsum(),
48 separator(),
49 LoremIpsum(),
50 })),
51 window(text("Vertical split"), vbox({
52 LoremIpsum(),
53 separator(),
54 LoremIpsum(),
55 separator(),
56 LoremIpsum(),
57 })),
58 window(text("Grid split with different style"),
59 vbox({
60 hbox({
61 LoremIpsum(),
62 separator(),
63 LoremIpsum() //
64 | selectionBackgroundColor(Color::Yellow) //
65 | selectionColor(Color::Black) //
67 separator(),
68 LoremIpsum() | selectionColor(Color::Blue),
69 }),
70 separator(),
71 hbox({
72 LoremIpsum() | selectionColor(Color::Red),
73 separator(),
74 LoremIpsum() | selectionStyle([](Cell& pixel) {
75 pixel.underlined_double = true;
76 }),
77 separator(),
78 LoremIpsum(),
79 }),
80 })),
81 quit->Render(),
82 });
83 });
84
85 screen.Loop(renderer);
86}
Element LoremIpsum()
Component Button(ConstStringRef label, std::function< void()> on_click, ButtonOption options=ButtonOption::Simple())
Dessine un bouton. Exécute une fonction lorsqu'il est cliqué.
Component Renderer(Component child, std::function< Element()>)
Retourne un nouveau Component, similaire à |child|, mais utilisant |render| comme événement Component...
Element window(Element title, Element content, BorderStyle border=ROUNDED)
Dessine une fenêtre avec un titre et une bordure autour de l'élément.
Element text(std::string_view text)
Affiche un morceau de texte unicode encodé en UTF8.
Decorator size(WidthOrHeight direction, Constraint constraint, int value)
Applique une contrainte sur la taille d'un élément.
Element paragraph(std::string_view the_text)
Renvoie un élément affichant le paragraphe sur plusieurs lignes.
Element separator()
Dessine une séparation verticale ou horizontale entre deux autres éléments.
Element vbox(Elements children)
Un conteneur affichant les éléments verticalement un par un.
Definition vbox.cpp:96
L'espace de noms FTXUI ftxui::
Definition animation.hpp:11
std::shared_ptr< Node > Element
Definition elements.hpp:25
Element hbox(Elements children)
Un conteneur affichant les éléments horizontalement un par un.
Definition hbox.cpp:94
Decorator selectionBackgroundColor(Color foreground)
Définit la couleur d'arrière-plan d'un élément lorsqu'il est sélectionné. Notez que le style est appl...
Decorator selectionColor(Color foreground)
Définit la couleur d'un élément lorsqu'il est sélectionné.
Element selectionStyleReset(Element child)
Réinitialise le style de sélection d'un élément.
Decorator selectionStyle(std::function< void(Cell &)> style)
Définit le style d'un élément lorsqu'il est sélectionné.