FTXUI 6.1.9 C++ functional terminal UI.

Loading...
Searching...
No Matches
examples/component/window.cpp
Go to the documentation of this file.
1// Copyright 2023 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 <ftxui/component/component.hpp>
5#include <ftxui/component/screen_interactive.hpp>
6#include <string>
7
8 using namespace ftxui;
9
10 Component DummyWindowContent() {
11 class Impl : public ComponentBase {
12 private:
13 bool checked[3] = {false, false, false};
14 float slider = 50;
15
16 public:
17 Impl() {
18 Add(Container::Vertical({
19 Checkbox("Check me", &checked[0]),
20 Checkbox("Check me", &checked[1]),
21 Checkbox("Check me", &checked[2]),
22 Slider("Slider", &slider, 0.f, 100.f),
23 }));
24 }
25 };
26 return Make<Impl>();
27}
28
29 int main() {
30 int window_1_left = 20;
31 int window_1_top = 10;
32 int window_1_width = 40;
33 int window_1_height = 20;
34
35 auto window_1 = Window({
36 .inner = DummyWindowContent(),
37 .title = "First window",
38 .left = &window_1_left,
39 .top = &window_1_top,
40 .width = &window_1_width,
41 .height = &window_1_height,
42 });
43
44 auto window_2 = Window({
45 .inner = DummyWindowContent(),
46 .title = "My window",
47 .left = 40,
48 .top = 20,
49 });
50
51 auto window_3 = Window({
52 .inner = DummyWindowContent(),
53 .title = "My window",
54 .left = 60,
55 .top = 30,
56 });
57
58 auto window_4 = Window({
59 .inner = DummyWindowContent(),
60 });
61
62 auto window_5 = Window({});
63
64 auto window_container = Container::Stacked({
65 window_1,
66 window_2,
67 window_3,
68 window_4,
69 window_5,
70 });
71
72 auto display_win_1 = Renderer([&] {
73 return text("window_1: " + //
74 std::to_string(window_1_width) + "x" +
75 std::to_string(window_1_height) + " + " +
76 std::to_string(window_1_left) + "," +
77 std::to_string(window_1_top));
78 });
79
80 auto layout = Container::Vertical({
81 display_win_1,
82 window_container,
83 });
84
85 auto screen = ScreenInteractive::Fullscreen();
86 screen.Loop(layout);
87
88 return EXIT_SUCCESS;
89}
component.hpp
DummyWindowContent
Component DummyWindowContent()
Definition examples/component/window.cpp:10
main
int main()
Definition examples/component/window.cpp:29
ftxui::ComponentBase::Add
void Add(Component children)
Add a child. @param child The child to be attached.
Definition component.cpp:70
ftxui::ScreenInteractive::Fullscreen
static ScreenInteractive Fullscreen()
Definition screen_interactive.cpp:376
ftxui::ComponentBase
It implement rendering itself as ftxui::Element. It implement keyboard navigation by responding to ft...
Definition component_base.hpp:30
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::Window
Component Window(WindowOptions option)
A draggeable / resizeable window. To use multiple of them, they must be stacked using Container::Stac...
Definition src/ftxui/component/window.cpp:312
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::Container::Stacked
Component Stacked(Components children)
A list of components to be stacked on top of each other. Events are propagated to the first component...
Definition container.cpp:432
ftxui::Checkbox
Component Checkbox(CheckboxOption options)
Draw checkable element.
Definition src/ftxui/component/checkbox.cpp:108
ftxui::text
Element text(std::wstring text)
Display a piece of unicode text.
Definition text.cpp:160
ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
ftxui::Make
std::shared_ptr< T > Make(Args &&... args)
Definition component.hpp:26
ftxui::Slider
Component Slider(SliderOption< T > options)
A slider in any direction.
Definition src/ftxui/component/slider.cpp:346
ftxui::Component
std::shared_ptr< ComponentBase > Component
Definition component_base.hpp:24
screen_interactive.hpp