FTXUI  5.0.0
C++ functional terminal UI.
examples/component/window.cpp
// Copyright 2023 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
using namespace ftxui;
Component DummyWindowContent() {
class Impl : public ComponentBase {
private:
bool checked[3] = {false, false, false};
float slider = 50;
public:
Impl() {
Checkbox("Check me", &checked[0]),
Checkbox("Check me", &checked[1]),
Checkbox("Check me", &checked[2]),
Slider("Slider", &slider, 0.f, 100.f),
}));
}
};
return Make<Impl>();
}
int main() {
int window_1_left = 20;
int window_1_top = 10;
int window_1_width = 40;
int window_1_height = 20;
auto window_1 = Window({
.inner = DummyWindowContent(),
.title = "First window",
.left = &window_1_left,
.top = &window_1_top,
.width = &window_1_width,
.height = &window_1_height,
});
auto window_2 = Window({
.inner = DummyWindowContent(),
.title = "My window",
.left = 40,
.top = 20,
});
auto window_3 = Window({
.inner = DummyWindowContent(),
.title = "My window",
.left = 60,
.top = 30,
});
auto window_4 = Window({
.inner = DummyWindowContent(),
});
auto window_5 = Window({});
auto window_container = Container::Stacked({
window_1,
window_2,
window_3,
window_4,
window_5,
});
auto display_win_1 = Renderer([&] {
return text("window_1: " + //
std::to_string(window_1_width) + "x" +
std::to_string(window_1_height) + " + " +
std::to_string(window_1_left) + "," +
std::to_string(window_1_top));
});
auto layout = Container::Vertical({
display_win_1,
window_container,
});
screen.Loop(layout);
return EXIT_SUCCESS;
}
static ScreenInteractive Fullscreen()
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:316
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:431
std::shared_ptr< ComponentBase > Component
Component Renderer(Component child, std::function< Element()>)
Return a new Component, similar to |child|, but using |render| as the Component::Render() event.
Definition: renderer.cpp:61
Component Window(WindowOptions option)
A draggeable / resizeable window. To use multiple of them, they must be stacked using Container::Stac...
Definition: window.cpp:312
std::string to_string(const std::wstring &s)
Convert a UTF8 std::string into a std::wstring.
Definition: string.cpp:1565
Element text(std::wstring text)
Display a piece of unicode text.
Definition: text.cpp:119
Component Slider(SliderOption< T > options)
A slider in any direction.
Definition: slider.cpp:346
Component Checkbox(CheckboxOption options)
Draw checkable element.
Definition: checkbox.cpp:108