mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-15 07:28:16 +08:00
Feature: Windows. (#690)
Into ftxui/component/, add: ``` Container::Stacked(...) Window(...); ``` Together, they can be used to display draggable/resizable windows. Bug:https://github.com/ArthurSonzogni/FTXUI/issues/682 * Fix typo.
This commit is contained in:
@@ -43,4 +43,5 @@ example(tab_horizontal)
|
||||
example(tab_vertical)
|
||||
example(textarea)
|
||||
example(toggle)
|
||||
example(window)
|
||||
example(with_restored_io)
|
||||
|
86
examples/component/window.cpp
Normal file
86
examples/component/window.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
#include <ftxui/component/component.hpp>
|
||||
#include <ftxui/component/screen_interactive.hpp>
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
Component DummyWindowContent() {
|
||||
class Impl : public ComponentBase {
|
||||
private:
|
||||
bool checked[3] = {false, false, false};
|
||||
float slider = 50;
|
||||
|
||||
public:
|
||||
Impl() {
|
||||
Add(Container::Vertical({
|
||||
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,
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::Fullscreen();
|
||||
screen.Loop(layout);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@@ -35,4 +35,3 @@ example(style_underlined_double)
|
||||
example(table)
|
||||
example(vbox_hbox)
|
||||
example(vflow)
|
||||
example(window)
|
||||
|
@@ -1,34 +0,0 @@
|
||||
#include <stdlib.h> // for EXIT_SUCCESS
|
||||
#include <ftxui/dom/elements.hpp> // for operator|=, Element, bgcolor, color, graph, border
|
||||
#include <ftxui/screen/screen.hpp> // for Fixed, Screen
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::DarkBlue, Color::Red, ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
Element document = graph([](int x, int y) {
|
||||
std::vector<int> result(x, 0);
|
||||
for (int i{0}; i < x; ++i) {
|
||||
result[i] = ((3 * i) / 2) % y;
|
||||
}
|
||||
return result;
|
||||
});
|
||||
|
||||
document |= color(Color::Red);
|
||||
document |= bgcolor(Color::DarkBlue);
|
||||
document |= border;
|
||||
|
||||
const int width = 80;
|
||||
const int height = 10;
|
||||
auto screen =
|
||||
Screen::Create(Dimension::Fixed(width), Dimension::Fixed(height));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSE file.
|
Reference in New Issue
Block a user