FTXUI 6.1.9 C++ functional terminal UI.

Loading...
Searching...
No Matches
examples/component/renderer.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 <memory> // for shared_ptr, allocator, __shared_ptr_access
5
6#include "ftxui/component/captured_mouse.hpp" // for ftxui
7#include "ftxui/component/component.hpp" // for Renderer, Button, Vertical
8#include "ftxui/component/component_base.hpp" // for ComponentBase
9#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
10#include "ftxui/dom/elements.hpp" // for operator|, Element, text, bold, border, center, color
11#include "ftxui/screen/color.hpp" // for Color, Color::Red
12
13 int main() {
14 using namespace ftxui;
15 auto screen = ScreenInteractive::FitComponent();
16
17 // A Renderer() is a component using a lambda function as a parameter to
18 // render itself.
19
20 // 1. Example of focusable renderer:
21 auto renderer_focusable = Renderer([](bool focused) {
22 if (focused)
23 return text("FOCUSABLE RENDERER()") | center | bold | border;
24 else
25 return text(" Focusable renderer() ") | center | border;
26 });
27
28 // 2. Examples of a non focusable renderer.
29 auto renderer_non_focusable = Renderer([&] {
30 return text("~~~~~ Non Focusable renderer() ~~~~~"); //
31 });
32
33 // 3. Renderer can wrap other components to redefine their Render() function.
34 auto button = Button("Wrapped quit button", screen.ExitLoopClosure());
35 auto renderer_wrap = Renderer(button, [&] {
36 if (button->Focused())
37 return button->Render() | bold | color(Color::Red);
38 else
39 return button->Render();
40 });
41
42 // Let's renderer everyone:
43 screen.Loop(Container::Vertical({
44 renderer_focusable,
45 renderer_non_focusable,
46 renderer_wrap,
47 }));
48}
captured_mouse.hpp
color.hpp
component.hpp
component_base.hpp
elements.hpp
main
int main()
Definition examples/component/renderer.cpp:13
ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
screen_interactive.hpp