Initialize
This commit is contained in:
28
ftxui/examples/CMakeLists.txt
Normal file
28
ftxui/examples/CMakeLists.txt
Normal file
@@ -0,0 +1,28 @@
|
||||
if(NOT FTXUI_BUILD_EXAMPLES)
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(EXAMPLES_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
function(example name)
|
||||
add_executable(ftxui_example_${name} ${name}.cpp)
|
||||
target_link_libraries(ftxui_example_${name} PUBLIC ${DIRECTORY_LIB})
|
||||
file(RELATIVE_PATH dir ${EXAMPLES_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set_property(GLOBAL APPEND PROPERTY FTXUI::EXAMPLES ${dir}/${name})
|
||||
target_compile_features(ftxui_example_${name} PRIVATE cxx_std_20)
|
||||
endfunction(example)
|
||||
|
||||
add_subdirectory(component)
|
||||
add_subdirectory(dom)
|
||||
|
||||
if (EMSCRIPTEN)
|
||||
get_property(EXAMPLES GLOBAL PROPERTY FTXUI::EXAMPLES)
|
||||
foreach(file
|
||||
"index.css"
|
||||
"index.html"
|
||||
"index.mjs"
|
||||
"run_webassembly.py"
|
||||
"sw.js"
|
||||
)
|
||||
configure_file(${file} ${file})
|
||||
endforeach(file)
|
||||
endif()
|
||||
52
ftxui/examples/component/CMakeLists.txt
Normal file
52
ftxui/examples/component/CMakeLists.txt
Normal file
@@ -0,0 +1,52 @@
|
||||
set(DIRECTORY_LIB component)
|
||||
|
||||
example(button)
|
||||
example(button_animated)
|
||||
example(button_in_frame)
|
||||
example(button_style)
|
||||
example(canvas_animated)
|
||||
example(checkbox)
|
||||
example(checkbox_in_frame)
|
||||
example(collapsible)
|
||||
example(composition)
|
||||
example(custom_loop)
|
||||
example(dropdown)
|
||||
example(dropdown_custom)
|
||||
example(flexbox_gallery)
|
||||
example(focus)
|
||||
example(focus_cursor)
|
||||
example(gallery)
|
||||
example(homescreen)
|
||||
example(input)
|
||||
example(input_in_frame)
|
||||
example(input_style)
|
||||
example(linear_gradient_gallery)
|
||||
example(maybe)
|
||||
example(menu)
|
||||
example(menu2)
|
||||
example(menu_entries)
|
||||
example(menu_entries_animated)
|
||||
example(menu_in_frame)
|
||||
example(menu_in_frame_horizontal)
|
||||
example(menu_multiple)
|
||||
example(menu_style)
|
||||
example(menu_underline_animated_gallery)
|
||||
example(modal_dialog)
|
||||
example(modal_dialog_custom)
|
||||
example(nested_screen)
|
||||
example(print_key_press)
|
||||
example(radiobox)
|
||||
example(radiobox_in_frame)
|
||||
example(renderer)
|
||||
example(resizable_split)
|
||||
example(scrollbar)
|
||||
example(selection)
|
||||
example(slider)
|
||||
example(slider_direction)
|
||||
example(slider_rgb)
|
||||
example(tab_horizontal)
|
||||
example(tab_vertical)
|
||||
example(textarea)
|
||||
example(toggle)
|
||||
example(window)
|
||||
example(with_restored_io)
|
||||
64
ftxui/examples/component/button.cpp
Normal file
64
ftxui/examples/component/button.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
// 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.
|
||||
#include <memory> // for shared_ptr, __shared_ptr_access
|
||||
#include <string> // for operator+, to_string
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Button, Horizontal, Renderer
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for separator, gauge, text, Element, operator|, vbox, border
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
// This is a helper function to create a button with a custom style.
|
||||
// The style is defined by a lambda function that takes an EntryState and
|
||||
// returns an Element.
|
||||
// We are using `center` to center the text inside the button, then `border` to
|
||||
// add a border around the button, and finally `flex` to make the button fill
|
||||
// the available space.
|
||||
ButtonOption Style() {
|
||||
auto option = ButtonOption::Animated();
|
||||
option.transform = [](const EntryState& s) {
|
||||
auto element = text(s.label);
|
||||
if (s.focused) {
|
||||
element |= bold;
|
||||
}
|
||||
return element | center | borderEmpty | flex;
|
||||
};
|
||||
return option;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int value = 50;
|
||||
|
||||
// clang-format off
|
||||
auto btn_dec_01 = Button("-1", [&] { value -= 1; }, Style());
|
||||
auto btn_inc_01 = Button("+1", [&] { value += 1; }, Style());
|
||||
auto btn_dec_10 = Button("-10", [&] { value -= 10; }, Style());
|
||||
auto btn_inc_10 = Button("+10", [&] { value += 10; }, Style());
|
||||
// clang-format on
|
||||
|
||||
// The tree of components. This defines how to navigate using the keyboard.
|
||||
// The selected `row` is shared to get a grid layout.
|
||||
int row = 0;
|
||||
auto buttons = Container::Vertical({
|
||||
Container::Horizontal({btn_dec_01, btn_inc_01}, &row) | flex,
|
||||
Container::Horizontal({btn_dec_10, btn_inc_10}, &row) | flex,
|
||||
});
|
||||
|
||||
// Modify the way to render them on screen:
|
||||
auto component = Renderer(buttons, [&] {
|
||||
return vbox({
|
||||
text("value = " + std::to_string(value)),
|
||||
separator(),
|
||||
buttons->Render() | flex,
|
||||
}) |
|
||||
flex | border;
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
screen.Loop(component);
|
||||
return 0;
|
||||
}
|
||||
45
ftxui/examples/component/button_animated.cpp
Normal file
45
ftxui/examples/component/button_animated.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
// 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.
|
||||
#include <memory> // for shared_ptr, __shared_ptr_access
|
||||
#include <string> // for operator+, to_string
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Button, Horizontal, Renderer
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/component_options.hpp" // for ButtonOption
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for gauge, separator, text, vbox, operator|, Element, border
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::Blue, Color::Green, Color::Red
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
int main() {
|
||||
int value = 50;
|
||||
|
||||
// The tree of components. This defines how to navigate using the keyboard.
|
||||
auto buttons = Container::Horizontal({
|
||||
Button(
|
||||
"Decrease", [&] { value--; }, ButtonOption::Animated(Color::Red)),
|
||||
Button(
|
||||
"Reset", [&] { value = 50; }, ButtonOption::Animated(Color::Green)),
|
||||
Button(
|
||||
"Increase", [&] { value++; }, ButtonOption::Animated(Color::Blue)),
|
||||
});
|
||||
|
||||
// Modify the way to render them on screen:
|
||||
auto component = Renderer(buttons, [&] {
|
||||
return vbox({
|
||||
vbox({
|
||||
text("value = " + std::to_string(value)),
|
||||
separator(),
|
||||
gauge(value * 0.01f),
|
||||
}) | border,
|
||||
buttons->Render(),
|
||||
});
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
screen.Loop(component);
|
||||
return 0;
|
||||
}
|
||||
47
ftxui/examples/component/button_in_frame.cpp
Normal file
47
ftxui/examples/component/button_in_frame.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright 2022 Arthur Sonzogni. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSE file.
|
||||
#include <memory> // for allocator, __shared_ptr_access, shared_ptr
|
||||
#include <string> // for to_string, operator+
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Button, Renderer, Vertical
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/component_options.hpp" // for ButtonOption
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, text, Element, hbox, separator, size, vbox, border, frame, vscroll_indicator, HEIGHT, LESS_THAN
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::Default, Color::GrayDark, Color::White
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
int main() {
|
||||
int counter = 0;
|
||||
auto on_click = [&] { counter++; };
|
||||
|
||||
auto style = ButtonOption::Animated(Color::Default, Color::GrayDark,
|
||||
Color::Default, Color::White);
|
||||
|
||||
auto container = Container::Vertical({});
|
||||
for (int i = 0; i < 30; ++i) {
|
||||
auto button = Button("Button " + std::to_string(i), on_click, style);
|
||||
container->Add(button);
|
||||
}
|
||||
|
||||
auto renderer = Renderer(container, [&] {
|
||||
return vbox({
|
||||
hbox({
|
||||
text("Counter:"),
|
||||
text(std::to_string(counter)),
|
||||
}),
|
||||
separator(),
|
||||
container->Render() | vscroll_indicator | frame |
|
||||
size(HEIGHT, LESS_THAN, 20),
|
||||
}) |
|
||||
border;
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
screen.Loop(renderer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
60
ftxui/examples/component/button_style.cpp
Normal file
60
ftxui/examples/component/button_style.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
// 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.
|
||||
#include <string> // for operator+, to_string
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Button, Vertical, Renderer, Horizontal, operator|
|
||||
#include "ftxui/component/component_base.hpp" // for Component
|
||||
#include "ftxui/component/component_options.hpp" // for ButtonOption
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for Element, separator, text, border
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::Blue, Color::Green, Color::Red
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
int main() {
|
||||
int value = 0;
|
||||
auto action = [&] { value++; };
|
||||
auto action_renderer =
|
||||
Renderer([&] { return text("count = " + std::to_string(value)); });
|
||||
|
||||
auto buttons =
|
||||
Container::Vertical({
|
||||
action_renderer,
|
||||
Renderer([] { return separator(); }),
|
||||
Container::Horizontal({
|
||||
Container::Vertical({
|
||||
Button("Ascii 1", action, ButtonOption::Ascii()),
|
||||
Button("Ascii 2", action, ButtonOption::Ascii()),
|
||||
Button("Ascii 3", action, ButtonOption::Ascii()),
|
||||
}),
|
||||
Renderer([] { return separator(); }),
|
||||
Container::Vertical({
|
||||
Button("Simple 1", action, ButtonOption::Simple()),
|
||||
Button("Simple 2", action, ButtonOption::Simple()),
|
||||
Button("Simple 3", action, ButtonOption::Simple()),
|
||||
}),
|
||||
Renderer([] { return separator(); }),
|
||||
Container::Vertical({
|
||||
Button("Animated 1", action, ButtonOption::Animated()),
|
||||
Button("Animated 2", action, ButtonOption::Animated()),
|
||||
Button("Animated 3", action, ButtonOption::Animated()),
|
||||
}),
|
||||
Renderer([] { return separator(); }),
|
||||
Container::Vertical({
|
||||
Button("Animated 4", action,
|
||||
ButtonOption::Animated(Color::Red)),
|
||||
Button("Animated 5", action,
|
||||
ButtonOption::Animated(Color::Green)),
|
||||
Button("Animated 6", action,
|
||||
ButtonOption::Animated(Color::Blue)),
|
||||
}),
|
||||
}),
|
||||
}) |
|
||||
border;
|
||||
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
screen.Loop(buttons);
|
||||
return 0;
|
||||
}
|
||||
263
ftxui/examples/component/canvas_animated.cpp
Normal file
263
ftxui/examples/component/canvas_animated.cpp
Normal file
@@ -0,0 +1,263 @@
|
||||
// Copyright 2021 Arthur Sonzogni. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSED file.
|
||||
#include <cmath> // for sin, cos
|
||||
#include <ftxui/dom/elements.hpp> // for canvas, Element, separator, hbox, operator|, border
|
||||
#include <ftxui/screen/screen.hpp> // for Pixel
|
||||
#include <memory> // for allocator, shared_ptr, __shared_ptr_access
|
||||
#include <string> // for string, basic_string
|
||||
#include <utility> // for move
|
||||
#include <vector> // for vector, __alloc_traits<>::value_type
|
||||
|
||||
#include "ftxui/component/component.hpp" // for Renderer, CatchEvent, Horizontal, Menu, Tab
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/event.hpp" // for Event
|
||||
#include "ftxui/component/mouse.hpp" // for Mouse
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/canvas.hpp" // for Canvas
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::Red, Color::Blue, Color::Green, ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
|
||||
int mouse_x = 0;
|
||||
int mouse_y = 0;
|
||||
|
||||
// A triangle following the mouse, using braille characters.
|
||||
auto renderer_line_braille = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0, 0, "Several lines (braille)");
|
||||
c.DrawPointLine(mouse_x, mouse_y, 80, 10, Color::Red);
|
||||
c.DrawPointLine(80, 10, 80, 40, Color::Blue);
|
||||
c.DrawPointLine(80, 40, mouse_x, mouse_y, Color::Green);
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
|
||||
// A triangle following the mouse, using block characters.
|
||||
auto renderer_line_block = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0, 0, "Several lines (block)");
|
||||
c.DrawBlockLine(mouse_x, mouse_y, 80, 10, Color::Red);
|
||||
c.DrawBlockLine(80, 10, 80, 40, Color::Blue);
|
||||
c.DrawBlockLine(80, 40, mouse_x, mouse_y, Color::Green);
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
|
||||
// A circle following the mouse, using braille characters.
|
||||
auto renderer_circle_braille = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0, 0, "A circle (braille)");
|
||||
c.DrawPointCircle(mouse_x, mouse_y, 30);
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
|
||||
// A circle following the mouse, using block characters.
|
||||
auto renderer_circle_block = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0, 0, "A circle (block)");
|
||||
c.DrawBlockCircle(mouse_x, mouse_y, 30);
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
|
||||
// A filled circle following the mouse, using braille characters.
|
||||
auto renderer_circle_filled_braille = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0, 0, "A circle filled (braille)");
|
||||
c.DrawPointCircleFilled(mouse_x, mouse_y, 30);
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
|
||||
// A filled circle following the mouse, using block characters.
|
||||
auto renderer_circle_filled_block = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0, 0, "A circle filled (block)");
|
||||
c.DrawBlockCircleFilled(mouse_x, mouse_y, 30);
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
|
||||
// An ellipse following the mouse, using braille characters.
|
||||
auto renderer_ellipse_braille = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0, 0, "An ellipse (braille)");
|
||||
c.DrawPointEllipse(mouse_x / 2, mouse_y / 2, mouse_x / 2, mouse_y / 2);
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
|
||||
// An ellipse following the mouse, using block characters.
|
||||
auto renderer_ellipse_block = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0, 0, "An ellipse (block)");
|
||||
c.DrawBlockEllipse(mouse_x / 2, mouse_y / 2, mouse_x / 2, mouse_y / 2);
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
|
||||
// An ellipse following the mouse filled, using braille characters.
|
||||
auto renderer_ellipse_filled_braille = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0, 0, "A filled ellipse (braille)");
|
||||
c.DrawPointEllipseFilled(mouse_x / 2, mouse_y / 2, mouse_x / 2,
|
||||
mouse_y / 2);
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
|
||||
// An ellipse following the mouse filled, using block characters.
|
||||
auto renderer_ellipse_filled_block = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0, 0, "A filled ellipse (block)");
|
||||
c.DrawBlockEllipseFilled(mouse_x / 2, mouse_y / 2, mouse_x / 2,
|
||||
mouse_y / 2);
|
||||
c.DrawBlockEllipse(mouse_x / 2, mouse_y / 2, mouse_x / 2, mouse_y / 2);
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
|
||||
// A text following the mouse
|
||||
auto renderer_text = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0, 0, "A piece of text");
|
||||
c.DrawText(mouse_x, mouse_y, "This is a piece of text with effects",
|
||||
[](Pixel& p) {
|
||||
p.foreground_color = Color::Red;
|
||||
p.underlined = true;
|
||||
p.bold = true;
|
||||
});
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
|
||||
auto renderer_plot_1 = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0, 0, "A graph");
|
||||
|
||||
std::vector<int> ys(100);
|
||||
for (int x = 0; x < 100; x++) {
|
||||
float dx = float(x - mouse_x);
|
||||
float dy = 50.f;
|
||||
ys[x] = int(dy + 20 * cos(dx * 0.14) + 10 * sin(dx * 0.42));
|
||||
}
|
||||
for (int x = 1; x < 99; x++) {
|
||||
c.DrawPointLine(x, ys[x], x + 1, ys[x + 1]);
|
||||
}
|
||||
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
|
||||
auto renderer_plot_2 = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0, 0, "A symmetrical graph filled");
|
||||
std::vector<int> ys(100);
|
||||
for (int x = 0; x < 100; x++) {
|
||||
ys[x] = int(30 + //
|
||||
10 * cos(x * 0.2 - mouse_x * 0.05) + //
|
||||
5 * sin(x * 0.4) + //
|
||||
5 * sin(x * 0.3 - mouse_y * 0.05)); //
|
||||
}
|
||||
for (int x = 0; x < 100; x++) {
|
||||
c.DrawPointLine(x, 50 + ys[x], x, 50 - ys[x], Color::Red);
|
||||
}
|
||||
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
|
||||
auto renderer_plot_3 = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0, 0, "A 2D gaussian plot");
|
||||
int size = 15;
|
||||
|
||||
// mouse_x = 5mx + 3*my
|
||||
// mouse_y = 0mx + -5my + 90
|
||||
float my = (mouse_y - 90) / -5.f;
|
||||
float mx = (mouse_x - 3 * my) / 5.f;
|
||||
std::vector<std::vector<float>> ys(size, std::vector<float>(size));
|
||||
for (int y = 0; y < size; y++) {
|
||||
for (int x = 0; x < size; x++) {
|
||||
float dx = x - mx;
|
||||
float dy = y - my;
|
||||
ys[y][x] = -1.5 + 3.0 * std::exp(-0.2f * (dx * dx + dy * dy));
|
||||
}
|
||||
}
|
||||
for (int y = 0; y < size; y++) {
|
||||
for (int x = 0; x < size; x++) {
|
||||
if (x != 0) {
|
||||
c.DrawPointLine(
|
||||
5 * (x - 1) + 3 * (y - 0), 90 - 5 * (y - 0) - 5 * ys[y][x - 1],
|
||||
5 * (x - 0) + 3 * (y - 0), 90 - 5 * (y - 0) - 5 * ys[y][x]);
|
||||
}
|
||||
if (y != 0) {
|
||||
c.DrawPointLine(
|
||||
5 * (x - 0) + 3 * (y - 1), 90 - 5 * (y - 1) - 5 * ys[y - 1][x],
|
||||
5 * (x - 0) + 3 * (y - 0), 90 - 5 * (y - 0) - 5 * ys[y][x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
|
||||
int selected_tab = 12;
|
||||
auto tab = Container::Tab(
|
||||
{
|
||||
renderer_line_braille,
|
||||
renderer_line_block,
|
||||
renderer_circle_braille,
|
||||
renderer_circle_block,
|
||||
renderer_circle_filled_braille,
|
||||
renderer_circle_filled_block,
|
||||
renderer_ellipse_braille,
|
||||
renderer_ellipse_block,
|
||||
renderer_ellipse_filled_braille,
|
||||
renderer_ellipse_filled_block,
|
||||
|
||||
renderer_plot_1,
|
||||
renderer_plot_2,
|
||||
renderer_plot_3,
|
||||
|
||||
renderer_text,
|
||||
},
|
||||
&selected_tab);
|
||||
|
||||
// This capture the last mouse position.
|
||||
auto tab_with_mouse = CatchEvent(tab, [&](Event e) {
|
||||
if (e.is_mouse()) {
|
||||
mouse_x = (e.mouse().x - 1) * 2;
|
||||
mouse_y = (e.mouse().y - 1) * 4;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
std::vector<std::string> tab_titles = {
|
||||
"line (braille)",
|
||||
"line (block)",
|
||||
"circle (braille)",
|
||||
"circle (block)",
|
||||
"circle filled (braille)",
|
||||
"circle filled (block)",
|
||||
"ellipse (braille)",
|
||||
"ellipse (block)",
|
||||
"ellipse filled (braille)",
|
||||
"ellipse filled (block)",
|
||||
"plot_1 simple",
|
||||
"plot_2 filled",
|
||||
"plot_3 3D",
|
||||
"text",
|
||||
};
|
||||
auto tab_toggle = Menu(&tab_titles, &selected_tab);
|
||||
|
||||
auto component = Container::Horizontal({
|
||||
tab_with_mouse,
|
||||
tab_toggle,
|
||||
});
|
||||
|
||||
// Add some separator to decorate the whole component:
|
||||
auto component_renderer = Renderer(component, [&] {
|
||||
return hbox({
|
||||
tab_with_mouse->Render(),
|
||||
separator(),
|
||||
tab_toggle->Render(),
|
||||
}) |
|
||||
border;
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
screen.Loop(component_renderer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
38
ftxui/examples/component/checkbox.cpp
Normal file
38
ftxui/examples/component/checkbox.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright 2021 Arthur Sonzogni. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSE file.
|
||||
#include <array> // for array
|
||||
#include <iostream>
|
||||
#include <memory> // for shared_ptr, __shared_ptr_access
|
||||
#include <string> // for operator+, to_string
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Checkbox, Renderer, Vertical
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, Element, size, border, frame, vscroll_indicator, HEIGHT, LESS_THAN
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
int main() {
|
||||
bool download = false;
|
||||
bool upload = false;
|
||||
bool ping = false;
|
||||
|
||||
auto container = Container::Vertical({
|
||||
Checkbox("Download", &download),
|
||||
Checkbox("Upload", &upload),
|
||||
Checkbox("Ping", &ping),
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
screen.Loop(container);
|
||||
|
||||
std::cout << "---" << std::endl;
|
||||
std::cout << "Download: " << download << std::endl;
|
||||
std::cout << "Upload: " << upload << std::endl;
|
||||
std::cout << "Ping: " << ping << std::endl;
|
||||
std::cout << "---" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
34
ftxui/examples/component/checkbox_in_frame.cpp
Normal file
34
ftxui/examples/component/checkbox_in_frame.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
// 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.
|
||||
#include <array> // for array
|
||||
#include <memory> // for shared_ptr, __shared_ptr_access
|
||||
#include <string> // for operator+, to_string
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Checkbox, Renderer, Vertical
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, Element, size, border, frame, vscroll_indicator, HEIGHT, LESS_THAN
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
int main() {
|
||||
std::array<bool, 30> states;
|
||||
|
||||
auto container = Container::Vertical({});
|
||||
for (int i = 0; i < 30; ++i) {
|
||||
states[i] = false;
|
||||
container->Add(Checkbox("Checkbox" + std::to_string(i), &states[i]));
|
||||
}
|
||||
|
||||
auto renderer = Renderer(container, [&] {
|
||||
return container->Render() | vscroll_indicator | frame |
|
||||
size(HEIGHT, LESS_THAN, 10) | border;
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
screen.Loop(renderer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
57
ftxui/examples/component/collapsible.cpp
Normal file
57
ftxui/examples/component/collapsible.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
// 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.
|
||||
#include <memory> // for allocator, make_shared, __shared_ptr_access
|
||||
#include <utility> // for move
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Collapsible, Renderer, Vertical
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for text, hbox, Element
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
// Take a list of component, display them vertically, one column shifted to the
|
||||
// right.
|
||||
Component Inner(std::vector<Component> children) {
|
||||
Component vlist = Container::Vertical(std::move(children));
|
||||
return Renderer(vlist, [vlist] {
|
||||
return hbox({
|
||||
text(" "),
|
||||
vlist->Render(),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Component Empty() {
|
||||
return std::make_shared<ComponentBase>();
|
||||
}
|
||||
|
||||
int main() {
|
||||
auto component =
|
||||
Collapsible("Collapsible 1",
|
||||
Inner({
|
||||
Collapsible("Collapsible 1.1",
|
||||
Inner({
|
||||
Collapsible("Collapsible 1.1.1", Empty()),
|
||||
Collapsible("Collapsible 1.1.2", Empty()),
|
||||
Collapsible("Collapsible 1.1.3", Empty()),
|
||||
})),
|
||||
Collapsible("Collapsible 1.2",
|
||||
Inner({
|
||||
Collapsible("Collapsible 1.2.1", Empty()),
|
||||
Collapsible("Collapsible 1.2.2", Empty()),
|
||||
Collapsible("Collapsible 1.2.3", Empty()),
|
||||
})),
|
||||
Collapsible("Collapsible 1.3",
|
||||
Inner({
|
||||
Collapsible("Collapsible 1.3.1", Empty()),
|
||||
Collapsible("Collapsible 1.3.2", Empty()),
|
||||
Collapsible("Collapsible 1.3.3", Empty()),
|
||||
})),
|
||||
}));
|
||||
|
||||
ScreenInteractive::FitComponent().Loop(component);
|
||||
}
|
||||
63
ftxui/examples/component/composition.cpp
Normal file
63
ftxui/examples/component/composition.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
// Copyright 2021 Arthur Sonzogni. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSE file.
|
||||
#include <memory> // for allocator, shared_ptr, __shared_ptr_access
|
||||
#include <string> // for operator+, to_string
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Button, Horizontal, Renderer
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for text, separator, Element, operator|, vbox, border
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
// An example of how to compose multiple components into one and maintain their
|
||||
// interactiveness.
|
||||
int main() {
|
||||
auto left_count = 0;
|
||||
auto right_count = 0;
|
||||
|
||||
auto left_buttons = Container::Horizontal({
|
||||
Button("Decrease", [&] { left_count--; }),
|
||||
Button("Increase", [&] { left_count++; }),
|
||||
});
|
||||
|
||||
auto right_buttons = Container::Horizontal({
|
||||
Button("Decrease", [&] { right_count--; }),
|
||||
Button("Increase", [&] { right_count++; }),
|
||||
});
|
||||
|
||||
// Renderer decorates its child with a new rendering function. The way the
|
||||
// children reacts to events is maintained.
|
||||
auto leftpane = Renderer(left_buttons, [&] {
|
||||
return vbox({
|
||||
text("This is the left control"),
|
||||
separator(),
|
||||
text("Left button count: " + std::to_string(left_count)),
|
||||
left_buttons->Render(),
|
||||
}) |
|
||||
border;
|
||||
});
|
||||
|
||||
auto rightpane = Renderer(right_buttons, [&] {
|
||||
return vbox({
|
||||
text("This is the right control"),
|
||||
separator(),
|
||||
text("Right button count: " + std::to_string(right_count)),
|
||||
right_buttons->Render(),
|
||||
}) |
|
||||
border;
|
||||
});
|
||||
|
||||
// Container groups components togethers. To render a Container::Horizontal,
|
||||
// it render its children side by side. It maintains their interactiveness and
|
||||
// provide the logic to navigate from one to the other using the arrow keys.
|
||||
auto composition = Container::Horizontal({leftpane, rightpane});
|
||||
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
screen.Loop(composition);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Thanks to Chris Morgan for this example!
|
||||
54
ftxui/examples/component/custom_loop.cpp
Normal file
54
ftxui/examples/component/custom_loop.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
// 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.
|
||||
#include <stdlib.h> // for EXIT_SUCCESS
|
||||
#include <chrono> // for milliseconds
|
||||
#include <ftxui/component/event.hpp> // for Event
|
||||
#include <ftxui/component/mouse.hpp> // for ftxui
|
||||
#include <ftxui/dom/elements.hpp> // for text, separator, Element, operator|, vbox, border
|
||||
#include <memory> // for allocator, shared_ptr
|
||||
#include <string> // for operator+, to_string
|
||||
#include <thread> // for sleep_for
|
||||
|
||||
#include "ftxui/component/component.hpp" // for CatchEvent, Renderer, operator|=
|
||||
#include "ftxui/component/loop.hpp" // for Loop
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
|
||||
// Create a component counting the number of frames drawn and event handled.
|
||||
int custom_loop_count = 0;
|
||||
int frame_count = 0;
|
||||
int event_count = 0;
|
||||
auto component = Renderer([&] {
|
||||
frame_count++;
|
||||
return vbox({
|
||||
text("This demonstrates using a custom ftxui::Loop. It "),
|
||||
text("runs at 100 iterations per seconds. The FTXUI events "),
|
||||
text("are all processed once per iteration and a new frame "),
|
||||
text("is rendered as needed"),
|
||||
separator(),
|
||||
text("ftxui event count: " + std::to_string(event_count)),
|
||||
text("ftxui frame count: " + std::to_string(frame_count)),
|
||||
text("Custom loop count: " + std::to_string(custom_loop_count)),
|
||||
}) |
|
||||
border;
|
||||
});
|
||||
|
||||
component |= CatchEvent([&](Event) -> bool {
|
||||
event_count++;
|
||||
return false;
|
||||
});
|
||||
|
||||
Loop loop(&screen, component);
|
||||
|
||||
while (!loop.HasQuitted()) {
|
||||
custom_loop_count++;
|
||||
loop.RunOnce();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
44
ftxui/examples/component/dropdown.cpp
Normal file
44
ftxui/examples/component/dropdown.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
// 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.
|
||||
#include <string> // for basic_string, string, allocator
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Dropdown, Horizontal, Vertical
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
|
||||
std::vector<std::string> entries = {
|
||||
"tribute", "clearance", "ally", "bend", "electronics",
|
||||
"module", "era", "cultural", "sniff", "nationalism",
|
||||
"negotiation", "deliver", "figure", "east", "tribute",
|
||||
"clearance", "ally", "bend", "electronics", "module",
|
||||
"era", "cultural", "sniff", "nationalism", "negotiation",
|
||||
"deliver", "figure", "east", "tribute", "clearance",
|
||||
"ally", "bend", "electronics", "module", "era",
|
||||
"cultural", "sniff", "nationalism", "negotiation", "deliver",
|
||||
"figure", "east",
|
||||
};
|
||||
|
||||
int selected_1 = 0;
|
||||
int selected_2 = 0;
|
||||
int selected_3 = 0;
|
||||
int selected_4 = 0;
|
||||
|
||||
auto layout = Container::Vertical({
|
||||
Container::Horizontal({
|
||||
Dropdown(&entries, &selected_1),
|
||||
Dropdown(&entries, &selected_2),
|
||||
}),
|
||||
Container::Horizontal({
|
||||
Dropdown(&entries, &selected_3),
|
||||
Dropdown(&entries, &selected_4),
|
||||
}),
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
screen.Loop(layout);
|
||||
}
|
||||
104
ftxui/examples/component/dropdown_custom.cpp
Normal file
104
ftxui/examples/component/dropdown_custom.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
// 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.
|
||||
#include <string> // for basic_string, string, allocator
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Dropdown, Horizontal, Vertical
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
|
||||
std::vector<std::string> entries = {
|
||||
"tribute", "clearance", "ally", "bend", "electronics",
|
||||
"module", "era", "cultural", "sniff", "nationalism",
|
||||
"negotiation", "deliver", "figure", "east", "tribute",
|
||||
"clearance", "ally", "bend", "electronics", "module",
|
||||
"era", "cultural", "sniff", "nationalism", "negotiation",
|
||||
"deliver", "figure", "east", "tribute", "clearance",
|
||||
"ally", "bend", "electronics", "module", "era",
|
||||
"cultural", "sniff", "nationalism", "negotiation", "deliver",
|
||||
"figure", "east",
|
||||
};
|
||||
|
||||
auto dropdown_1 = Dropdown({
|
||||
.radiobox = {.entries = &entries},
|
||||
.transform =
|
||||
[](bool open, Element checkbox, Element radiobox) {
|
||||
if (open) {
|
||||
return vbox({
|
||||
checkbox | inverted,
|
||||
radiobox | vscroll_indicator | frame |
|
||||
size(HEIGHT, LESS_THAN, 10),
|
||||
filler(),
|
||||
});
|
||||
}
|
||||
return vbox({
|
||||
checkbox,
|
||||
filler(),
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
auto dropdown_2 = Dropdown({
|
||||
.radiobox = {.entries = &entries},
|
||||
.transform =
|
||||
[](bool open, Element checkbox, Element radiobox) {
|
||||
if (open) {
|
||||
return vbox({
|
||||
checkbox | inverted,
|
||||
radiobox | vscroll_indicator | frame |
|
||||
size(HEIGHT, LESS_THAN, 10) | bgcolor(Color::Blue),
|
||||
filler(),
|
||||
});
|
||||
}
|
||||
return vbox({
|
||||
checkbox | bgcolor(Color::Blue),
|
||||
filler(),
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
auto dropdown_3 = Dropdown({
|
||||
.radiobox =
|
||||
{
|
||||
.entries = &entries,
|
||||
.transform =
|
||||
[](const EntryState& s) {
|
||||
auto t = text(s.label) | borderEmpty;
|
||||
if (s.active) {
|
||||
t |= bold;
|
||||
}
|
||||
if (s.focused) {
|
||||
t |= inverted;
|
||||
}
|
||||
return t;
|
||||
},
|
||||
},
|
||||
.transform =
|
||||
[](bool open, Element checkbox, Element radiobox) {
|
||||
checkbox |= borderEmpty;
|
||||
if (open) {
|
||||
return vbox({
|
||||
checkbox | inverted,
|
||||
radiobox | vscroll_indicator | frame |
|
||||
size(HEIGHT, LESS_THAN, 20) | bgcolor(Color::Red),
|
||||
filler(),
|
||||
});
|
||||
}
|
||||
return vbox({
|
||||
checkbox | bgcolor(Color::Red),
|
||||
filler(),
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
screen.Loop(Container::Horizontal({
|
||||
dropdown_1,
|
||||
dropdown_2,
|
||||
dropdown_3,
|
||||
}));
|
||||
}
|
||||
195
ftxui/examples/component/flexbox_gallery.cpp
Normal file
195
ftxui/examples/component/flexbox_gallery.cpp
Normal file
@@ -0,0 +1,195 @@
|
||||
// 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.
|
||||
#include <stddef.h> // for size_t
|
||||
#include <memory> // for shared_ptr, __shared_ptr_access, allocator
|
||||
#include <string> // for string, basic_string, to_string, operator+, char_traits
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Radiobox, Vertical, Checkbox, Horizontal, Renderer, ResizableSplitBottom, ResizableSplitRight
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for text, window, operator|, vbox, hbox, Element, flexbox, bgcolor, filler, flex, size, border, hcenter, color, EQUAL, bold, dim, notflex, xflex_grow, yflex_grow, HEIGHT, WIDTH
|
||||
#include "ftxui/dom/flexbox_config.hpp" // for FlexboxConfig, FlexboxConfig::AlignContent, FlexboxConfig::JustifyContent, FlexboxConfig::AlignContent::Center, FlexboxConfig::AlignItems, FlexboxConfig::Direction, FlexboxConfig::JustifyContent::Center, FlexboxConfig::Wrap
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::Black
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
int main() {
|
||||
auto screen = ScreenInteractive::Fullscreen();
|
||||
|
||||
int direction_index = 0;
|
||||
int wrap_index = 0;
|
||||
int justify_content_index = 0;
|
||||
int align_items_index = 0;
|
||||
int align_content_index = 0;
|
||||
|
||||
std::vector<std::string> directions = {
|
||||
"Row",
|
||||
"RowInversed",
|
||||
"Column",
|
||||
"ColumnInversed",
|
||||
};
|
||||
|
||||
std::vector<std::string> wraps = {
|
||||
"NoWrap",
|
||||
"Wrap",
|
||||
"WrapInversed",
|
||||
};
|
||||
|
||||
std::vector<std::string> justify_content = {
|
||||
"FlexStart", "FlexEnd", "Center", "Stretch",
|
||||
"SpaceBetween", "SpaceAround", "SpaceEvenly",
|
||||
};
|
||||
|
||||
std::vector<std::string> align_items = {
|
||||
"FlexStart",
|
||||
"FlexEnd",
|
||||
"Center",
|
||||
"Stretch",
|
||||
};
|
||||
|
||||
std::vector<std::string> align_content = {
|
||||
"FlexStart", "FlexEnd", "Center", "Stretch",
|
||||
"SpaceBetween", "SpaceAround", "SpaceEvenly",
|
||||
};
|
||||
|
||||
auto radiobox_direction = Radiobox(&directions, &direction_index);
|
||||
auto radiobox_wrap = Radiobox(&wraps, &wrap_index);
|
||||
auto radiobox_justify_content =
|
||||
Radiobox(&justify_content, &justify_content_index);
|
||||
auto radiobox_align_items = Radiobox(&align_items, &align_items_index);
|
||||
auto radiobox_align_content = Radiobox(&align_content, &align_content_index);
|
||||
|
||||
bool element_xflex_grow = false;
|
||||
bool element_yflex_grow = false;
|
||||
bool group_xflex_grow = true;
|
||||
bool group_yflex_grow = true;
|
||||
auto checkbox_element_xflex_grow =
|
||||
Checkbox("element |= xflex_grow", &element_xflex_grow);
|
||||
auto checkbox_element_yflex_grow =
|
||||
Checkbox("element |= yflex_grow", &element_yflex_grow);
|
||||
auto checkbox_group_xflex_grow =
|
||||
Checkbox("group |= xflex_grow", &group_xflex_grow);
|
||||
auto checkbox_group_yflex_grow =
|
||||
Checkbox("group |= yflex_grow", &group_yflex_grow);
|
||||
|
||||
auto make_box = [&](size_t dimx, size_t dimy, size_t index) {
|
||||
std::string title = std::to_string(dimx) + "x" + std::to_string(dimy);
|
||||
auto element = window(text(title) | hcenter | bold,
|
||||
text(std::to_string(index)) | hcenter | dim) |
|
||||
size(WIDTH, EQUAL, dimx) | size(HEIGHT, EQUAL, dimy) |
|
||||
bgcolor(Color::HSV(index * 25, 255, 255)) |
|
||||
color(Color::Black);
|
||||
if (element_xflex_grow) {
|
||||
element = element | xflex_grow;
|
||||
}
|
||||
if (element_yflex_grow) {
|
||||
element = element | yflex_grow;
|
||||
}
|
||||
return element;
|
||||
};
|
||||
|
||||
auto content_renderer = Renderer([&] {
|
||||
FlexboxConfig config;
|
||||
config.direction = static_cast<FlexboxConfig::Direction>(direction_index);
|
||||
config.wrap = static_cast<FlexboxConfig::Wrap>(wrap_index);
|
||||
config.justify_content =
|
||||
static_cast<FlexboxConfig::JustifyContent>(justify_content_index);
|
||||
config.align_items =
|
||||
static_cast<FlexboxConfig::AlignItems>(align_items_index);
|
||||
config.align_content =
|
||||
static_cast<FlexboxConfig::AlignContent>(align_content_index);
|
||||
|
||||
auto group = flexbox(
|
||||
{
|
||||
make_box(8, 4, 0),
|
||||
make_box(9, 6, 1),
|
||||
make_box(11, 6, 2),
|
||||
make_box(10, 4, 3),
|
||||
make_box(13, 7, 4),
|
||||
make_box(12, 4, 5),
|
||||
make_box(12, 5, 6),
|
||||
make_box(10, 4, 7),
|
||||
make_box(12, 4, 8),
|
||||
make_box(10, 5, 9),
|
||||
},
|
||||
config);
|
||||
|
||||
group = group | bgcolor(Color::Black);
|
||||
|
||||
group = group | notflex;
|
||||
|
||||
if (!group_xflex_grow) {
|
||||
group = hbox(group, filler());
|
||||
}
|
||||
if (!group_yflex_grow) {
|
||||
group = vbox(group, filler());
|
||||
}
|
||||
|
||||
group = group | flex;
|
||||
return group;
|
||||
});
|
||||
|
||||
auto center = FlexboxConfig()
|
||||
.Set(FlexboxConfig::JustifyContent::Center)
|
||||
.Set(FlexboxConfig::AlignContent::Center);
|
||||
int space_right = 10;
|
||||
int space_bottom = 1;
|
||||
content_renderer = ResizableSplitRight(
|
||||
Renderer([&] { return flexbox({text("resizable")}, center); }),
|
||||
content_renderer, &space_right);
|
||||
content_renderer = ResizableSplitBottom(
|
||||
Renderer([&] { return flexbox({text("resizable")}, center); }),
|
||||
content_renderer, &space_bottom);
|
||||
|
||||
auto main_container = Container::Vertical({
|
||||
Container::Horizontal({
|
||||
radiobox_direction,
|
||||
radiobox_wrap,
|
||||
Container::Vertical({
|
||||
checkbox_element_xflex_grow,
|
||||
checkbox_element_yflex_grow,
|
||||
checkbox_group_xflex_grow,
|
||||
checkbox_group_yflex_grow,
|
||||
}),
|
||||
}),
|
||||
Container::Horizontal({
|
||||
radiobox_justify_content,
|
||||
radiobox_align_items,
|
||||
radiobox_align_content,
|
||||
}),
|
||||
content_renderer,
|
||||
});
|
||||
|
||||
auto main_renderer = Renderer(main_container, [&] {
|
||||
return vbox({
|
||||
vbox({hbox({
|
||||
window(text("FlexboxConfig::Direction"),
|
||||
radiobox_direction->Render()),
|
||||
window(text("FlexboxConfig::Wrap"), radiobox_wrap->Render()),
|
||||
window(text("Misc:"),
|
||||
vbox({
|
||||
checkbox_element_xflex_grow->Render(),
|
||||
checkbox_element_yflex_grow->Render(),
|
||||
checkbox_group_xflex_grow->Render(),
|
||||
checkbox_group_yflex_grow->Render(),
|
||||
})),
|
||||
}),
|
||||
hbox({
|
||||
window(text("FlexboxConfig::JustifyContent"),
|
||||
radiobox_justify_content->Render()),
|
||||
window(text("FlexboxConfig::AlignItems"),
|
||||
radiobox_align_items->Render()),
|
||||
window(text("FlexboxConfig::AlignContent"),
|
||||
radiobox_align_content->Render()),
|
||||
})}),
|
||||
content_renderer->Render() | flex | border,
|
||||
});
|
||||
});
|
||||
|
||||
screen.Loop(main_renderer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
69
ftxui/examples/component/focus.cpp
Normal file
69
ftxui/examples/component/focus.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
// 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.
|
||||
#include <memory> // for allocator, shared_ptr, __shared_ptr_access
|
||||
#include <string> // for operator+, char_traits, to_string, string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Slider, Renderer, Vertical
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for Elements, Element, operator|, separator, text, focusPositionRelative, size, border, flex, frame, bgcolor, gridbox, vbox, EQUAL, center, HEIGHT, WIDTH
|
||||
#include "ftxui/screen/color.hpp" // for Color
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
Element make_box(int x, int y) {
|
||||
std::string title = "(" + std::to_string(x) + ", " + std::to_string(y) + ")";
|
||||
return text(title) | center | size(WIDTH, EQUAL, 18) |
|
||||
size(HEIGHT, EQUAL, 9) | border |
|
||||
bgcolor(Color::HSV(x * 255 / 15, 255, y * 255 / 15));
|
||||
};
|
||||
|
||||
Element make_grid() {
|
||||
std::vector<Elements> rows;
|
||||
for (int i = 0; i < 15; i++) {
|
||||
std::vector<Element> cols;
|
||||
for (int j = 0; j < 15; j++) {
|
||||
cols.push_back(make_box(i, j));
|
||||
}
|
||||
rows.push_back(cols);
|
||||
}
|
||||
|
||||
return gridbox(rows);
|
||||
};
|
||||
|
||||
int main() {
|
||||
float focus_x = 0.5f;
|
||||
float focus_y = 0.5f;
|
||||
|
||||
auto slider_x = Slider("x", &focus_x, 0.f, 1.f, 0.01f);
|
||||
auto slider_y = Slider("y", &focus_y, 0.f, 1.f, 0.01f);
|
||||
|
||||
auto renderer = Renderer(
|
||||
Container::Vertical({
|
||||
slider_x,
|
||||
slider_y,
|
||||
}),
|
||||
[&] {
|
||||
auto title = "focusPositionRelative(" + //
|
||||
std::to_string(focus_x) + ", " + //
|
||||
std::to_string(focus_y) + ")"; //
|
||||
return vbox({
|
||||
text(title),
|
||||
separator(),
|
||||
slider_x->Render(),
|
||||
slider_y->Render(),
|
||||
separator(),
|
||||
make_grid() | focusPositionRelative(focus_x, focus_y) |
|
||||
frame | flex,
|
||||
}) |
|
||||
border;
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::Fullscreen();
|
||||
screen.Loop(renderer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
37
ftxui/examples/component/focus_cursor.cpp
Normal file
37
ftxui/examples/component/focus_cursor.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
// 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.
|
||||
#include <ftxui/component/captured_mouse.hpp> // for ftxui
|
||||
#include <string> // for allocator, operator+, char_traits, string
|
||||
|
||||
#include "ftxui/component/component.hpp" // for Renderer, Vertical
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive, Component
|
||||
#include "ftxui/dom/elements.hpp" // for text, Decorator, focus, focusCursorBar, focusCursorBarBlinking, focusCursorBlock, focusCursorBlockBlinking, focusCursorUnderline, focusCursorUnderlineBlinking, hbox, Element
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
Component Instance(std::string label, Decorator focusCursor) {
|
||||
return Renderer([=](bool focused) {
|
||||
if (focused) {
|
||||
return hbox({
|
||||
text("> " + label + " "),
|
||||
focusCursor(text(" ")),
|
||||
});
|
||||
}
|
||||
return text(" " + label + " ");
|
||||
});
|
||||
};
|
||||
|
||||
int main() {
|
||||
auto screen = ScreenInteractive::Fullscreen();
|
||||
screen.Loop(Container::Vertical({
|
||||
Instance("focus", focus),
|
||||
Instance("focusCursorBlock", focusCursorBlock),
|
||||
Instance("focusCursorBlockBlinking", focusCursorBlockBlinking),
|
||||
Instance("focusCursorBar", focusCursorBar),
|
||||
Instance("focusCursorBarBlinking", focusCursorBarBlinking),
|
||||
Instance("focusCursorUnderline", focusCursorUnderline),
|
||||
Instance("focusCursorUnderlineBlinking", focusCursorUnderlineBlinking),
|
||||
}));
|
||||
return 0;
|
||||
}
|
||||
154
ftxui/examples/component/gallery.cpp
Normal file
154
ftxui/examples/component/gallery.cpp
Normal file
@@ -0,0 +1,154 @@
|
||||
// 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.
|
||||
#include <functional> // for function
|
||||
#include <memory> // for shared_ptr, allocator, __shared_ptr_access
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Slider, Checkbox, Vertical, Renderer, Button, Input, Menu, Radiobox, Toggle
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for separator, operator|, Element, size, xflex, text, WIDTH, hbox, vbox, EQUAL, border, GREATER_THAN
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
// Display a component nicely with a title on the left.
|
||||
Component Wrap(std::string name, Component component) {
|
||||
return Renderer(component, [name, component] {
|
||||
return hbox({
|
||||
text(name) | size(WIDTH, EQUAL, 8),
|
||||
separator(),
|
||||
component->Render() | xflex,
|
||||
}) |
|
||||
xflex;
|
||||
});
|
||||
}
|
||||
|
||||
int main() {
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
|
||||
// -- Menu
|
||||
// ----------------------------------------------------------------------
|
||||
const std::vector<std::string> menu_entries = {
|
||||
"Menu 1",
|
||||
"Menu 2",
|
||||
"Menu 3",
|
||||
"Menu 4",
|
||||
};
|
||||
int menu_selected = 0;
|
||||
auto menu = Menu(&menu_entries, &menu_selected);
|
||||
menu = Wrap("Menu", menu);
|
||||
|
||||
// -- Toggle------------------------------------------------------------------
|
||||
int toggle_selected = 0;
|
||||
std::vector<std::string> toggle_entries = {
|
||||
"Toggle_1",
|
||||
"Toggle_2",
|
||||
};
|
||||
auto toggle = Toggle(&toggle_entries, &toggle_selected);
|
||||
toggle = Wrap("Toggle", toggle);
|
||||
|
||||
// -- Checkbox ---------------------------------------------------------------
|
||||
bool checkbox_1_selected = false;
|
||||
bool checkbox_2_selected = false;
|
||||
bool checkbox_3_selected = false;
|
||||
bool checkbox_4_selected = false;
|
||||
|
||||
auto checkboxes = Container::Vertical({
|
||||
Checkbox("checkbox1", &checkbox_1_selected),
|
||||
Checkbox("checkbox2", &checkbox_2_selected),
|
||||
Checkbox("checkbox3", &checkbox_3_selected),
|
||||
Checkbox("checkbox4", &checkbox_4_selected),
|
||||
});
|
||||
checkboxes = Wrap("Checkbox", checkboxes);
|
||||
|
||||
// -- Radiobox ---------------------------------------------------------------
|
||||
int radiobox_selected = 0;
|
||||
std::vector<std::string> radiobox_entries = {
|
||||
"Radiobox 1",
|
||||
"Radiobox 2",
|
||||
"Radiobox 3",
|
||||
"Radiobox 4",
|
||||
};
|
||||
auto radiobox = Radiobox(&radiobox_entries, &radiobox_selected);
|
||||
radiobox = Wrap("Radiobox", radiobox);
|
||||
|
||||
// -- Input ------------------------------------------------------------------
|
||||
std::string input_label;
|
||||
auto input = Input(&input_label, "placeholder");
|
||||
input = Wrap("Input", input);
|
||||
|
||||
// -- Button -----------------------------------------------------------------
|
||||
std::string button_label = "Quit";
|
||||
std::function<void()> on_button_clicked_;
|
||||
auto button = Button(&button_label, screen.ExitLoopClosure());
|
||||
button = Wrap("Button", button);
|
||||
|
||||
// -- Slider -----------------------------------------------------------------
|
||||
int slider_value_1 = 12;
|
||||
int slider_value_2 = 56;
|
||||
int slider_value_3 = 128;
|
||||
auto sliders = Container::Vertical({
|
||||
Slider("R:", &slider_value_1, 0, 256, 1),
|
||||
Slider("G:", &slider_value_2, 0, 256, 1),
|
||||
Slider("B:", &slider_value_3, 0, 256, 1),
|
||||
});
|
||||
sliders = Wrap("Slider", sliders);
|
||||
|
||||
// A large text:
|
||||
auto lorel_ipsum = Renderer([] {
|
||||
return vbox({
|
||||
text("Lorem ipsum dolor sit amet, consectetur adipiscing elit. "),
|
||||
text("Sed do eiusmod tempor incididunt ut labore et dolore magna "
|
||||
"aliqua. "),
|
||||
text("Ut enim ad minim veniam, quis nostrud exercitation ullamco "
|
||||
"laboris nisi ut aliquip ex ea commodo consequat. "),
|
||||
text("Duis aute irure dolor in reprehenderit in voluptate velit esse "
|
||||
"cillum dolore eu fugiat nulla pariatur. "),
|
||||
text("Excepteur sint occaecat cupidatat non proident, sunt in culpa "
|
||||
"qui officia deserunt mollit anim id est laborum. "),
|
||||
|
||||
});
|
||||
});
|
||||
lorel_ipsum = Wrap("Lorel Ipsum", lorel_ipsum);
|
||||
|
||||
// -- Layout
|
||||
// -----------------------------------------------------------------
|
||||
auto layout = Container::Vertical({
|
||||
menu,
|
||||
toggle,
|
||||
checkboxes,
|
||||
radiobox,
|
||||
input,
|
||||
sliders,
|
||||
button,
|
||||
lorel_ipsum,
|
||||
});
|
||||
|
||||
auto component = Renderer(layout, [&] {
|
||||
return vbox({
|
||||
menu->Render(),
|
||||
separator(),
|
||||
toggle->Render(),
|
||||
separator(),
|
||||
checkboxes->Render(),
|
||||
separator(),
|
||||
radiobox->Render(),
|
||||
separator(),
|
||||
input->Render(),
|
||||
separator(),
|
||||
sliders->Render(),
|
||||
separator(),
|
||||
button->Render(),
|
||||
separator(),
|
||||
lorel_ipsum->Render(),
|
||||
}) |
|
||||
xflex | size(WIDTH, GREATER_THAN, 40) | border;
|
||||
});
|
||||
|
||||
screen.Loop(component);
|
||||
|
||||
return 0;
|
||||
}
|
||||
532
ftxui/examples/component/homescreen.cpp
Normal file
532
ftxui/examples/component/homescreen.cpp
Normal file
@@ -0,0 +1,532 @@
|
||||
// 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.
|
||||
#include <stddef.h> // for size_t
|
||||
#include <array> // for array
|
||||
#include <atomic> // for atomic
|
||||
#include <chrono> // for operator""s, chrono_literals
|
||||
#include <cmath> // for sin
|
||||
#include <ftxui/component/loop.hpp>
|
||||
#include <functional> // for ref, reference_wrapper, function
|
||||
#include <memory> // for allocator, shared_ptr, __shared_ptr_access
|
||||
#include <string> // for string, basic_string, char_traits, operator+, to_string
|
||||
#include <thread> // for sleep_for, thread
|
||||
#include <utility> // for move
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "../dom/color_info_sorted_2d.ipp" // for ColorInfoSorted2D
|
||||
#include "ftxui/component/component.hpp" // for Checkbox, Renderer, Horizontal, Vertical, Input, Menu, Radiobox, ResizableSplitLeft, Tab
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase, Component
|
||||
#include "ftxui/component/component_options.hpp" // for MenuOption, InputOption
|
||||
#include "ftxui/component/event.hpp" // for Event, Event::Custom
|
||||
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for text, color, operator|, bgcolor, filler, Element, vbox, size, hbox, separator, flex, window, graph, EQUAL, paragraph, WIDTH, hcenter, Elements, bold, vscroll_indicator, HEIGHT, flexbox, hflow, border, frame, flex_grow, gauge, paragraphAlignCenter, paragraphAlignJustify, paragraphAlignLeft, paragraphAlignRight, dim, spinner, LESS_THAN, center, yframe, GREATER_THAN
|
||||
#include "ftxui/dom/flexbox_config.hpp" // for FlexboxConfig
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::BlueLight, Color::RedLight, Color::Black, Color::Blue, Color::Cyan, Color::CyanLight, Color::GrayDark, Color::GrayLight, Color::Green, Color::GreenLight, Color::Magenta, Color::MagentaLight, Color::Red, Color::White, Color::Yellow, Color::YellowLight, Color::Default, Color::Palette256, ftxui
|
||||
#include "ftxui/screen/color_info.hpp" // for ColorInfo
|
||||
#include "ftxui/screen/terminal.hpp" // for Size, Dimensions
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
int main() {
|
||||
auto screen = ScreenInteractive::Fullscreen();
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// HTOP
|
||||
// ---------------------------------------------------------------------------
|
||||
int shift = 0;
|
||||
|
||||
auto my_graph = [&shift](int width, int height) {
|
||||
std::vector<int> output(width);
|
||||
for (int i = 0; i < width; ++i) {
|
||||
float v = 0.5f;
|
||||
v += 0.1f * sin((i + shift) * 0.1f);
|
||||
v += 0.2f * sin((i + shift + 10) * 0.15f);
|
||||
v += 0.1f * sin((i + shift) * 0.03f);
|
||||
v *= height;
|
||||
output[i] = (int)v;
|
||||
}
|
||||
return output;
|
||||
};
|
||||
|
||||
auto htop = Renderer([&] {
|
||||
auto frequency = vbox({
|
||||
text("Frequency [Mhz]") | hcenter,
|
||||
hbox({
|
||||
vbox({
|
||||
text("2400 "),
|
||||
filler(),
|
||||
text("1200 "),
|
||||
filler(),
|
||||
text("0 "),
|
||||
}),
|
||||
graph(std::ref(my_graph)) | flex,
|
||||
}) | flex,
|
||||
});
|
||||
|
||||
auto utilization = vbox({
|
||||
text("Utilization [%]") | hcenter,
|
||||
hbox({
|
||||
vbox({
|
||||
text("100 "),
|
||||
filler(),
|
||||
text("50 "),
|
||||
filler(),
|
||||
text("0 "),
|
||||
}),
|
||||
graph(std::ref(my_graph)) | color(Color::RedLight),
|
||||
}) | flex,
|
||||
});
|
||||
|
||||
auto ram = vbox({
|
||||
text("Ram [Mo]") | hcenter,
|
||||
hbox({
|
||||
vbox({
|
||||
text("8192"),
|
||||
filler(),
|
||||
text("4096 "),
|
||||
filler(),
|
||||
text("0 "),
|
||||
}),
|
||||
graph(std::ref(my_graph)) | color(Color::BlueLight),
|
||||
}) | flex,
|
||||
});
|
||||
|
||||
return hbox({
|
||||
vbox({
|
||||
frequency | flex,
|
||||
separator(),
|
||||
utilization | flex,
|
||||
}) | flex,
|
||||
separator(),
|
||||
ram | flex,
|
||||
}) |
|
||||
flex;
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Compiler
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const std::vector<std::string> compiler_entries = {
|
||||
"gcc",
|
||||
"clang",
|
||||
"emcc",
|
||||
"game_maker",
|
||||
"Ada compilers",
|
||||
"ALGOL 60 compilers",
|
||||
"ALGOL 68 compilers",
|
||||
"Assemblers (Intel *86)",
|
||||
"Assemblers (Motorola 68*)",
|
||||
"Assemblers (Zilog Z80)",
|
||||
"Assemblers (other)",
|
||||
"BASIC Compilers",
|
||||
"BASIC interpreters",
|
||||
"Batch compilers",
|
||||
"C compilers",
|
||||
"Source-to-source compilers",
|
||||
"C++ compilers",
|
||||
"C# compilers",
|
||||
"COBOL compilers",
|
||||
"Common Lisp compilers",
|
||||
"D compilers",
|
||||
"DIBOL/DBL compilers",
|
||||
"ECMAScript interpreters",
|
||||
"Eiffel compilers",
|
||||
"Fortran compilers",
|
||||
"Go compilers",
|
||||
"Haskell compilers",
|
||||
"Java compilers",
|
||||
"Pascal compilers",
|
||||
"Perl Interpreters",
|
||||
"PHP compilers",
|
||||
"PL/I compilers",
|
||||
"Python compilers",
|
||||
"Scheme compilers and interpreters",
|
||||
"Smalltalk compilers",
|
||||
"Tcl Interpreters",
|
||||
"VMS Interpreters",
|
||||
"Rexx Interpreters",
|
||||
"CLI compilers",
|
||||
};
|
||||
|
||||
int compiler_selected = 0;
|
||||
Component compiler = Radiobox(&compiler_entries, &compiler_selected);
|
||||
|
||||
std::array<std::string, 8> options_label = {
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-lpthread",
|
||||
"-O3",
|
||||
"-Wabi-tag",
|
||||
"-Wno-class-conversion",
|
||||
"-Wcomma-subscript",
|
||||
"-Wno-conversion-null",
|
||||
};
|
||||
std::array<bool, 8> options_state = {
|
||||
false, false, false, false, false, false, false, false,
|
||||
};
|
||||
|
||||
std::vector<std::string> input_entries;
|
||||
int input_selected = 0;
|
||||
Component input = Menu(&input_entries, &input_selected);
|
||||
|
||||
auto input_option = InputOption();
|
||||
std::string input_add_content;
|
||||
input_option.on_enter = [&] {
|
||||
input_entries.push_back(input_add_content);
|
||||
input_add_content = "";
|
||||
};
|
||||
Component input_add = Input(&input_add_content, "input files", input_option);
|
||||
|
||||
std::string executable_content_ = "";
|
||||
Component executable_ = Input(&executable_content_, "executable");
|
||||
|
||||
Component flags = Container::Vertical({
|
||||
Checkbox(&options_label[0], &options_state[0]),
|
||||
Checkbox(&options_label[1], &options_state[1]),
|
||||
Checkbox(&options_label[2], &options_state[2]),
|
||||
Checkbox(&options_label[3], &options_state[3]),
|
||||
Checkbox(&options_label[4], &options_state[4]),
|
||||
Checkbox(&options_label[5], &options_state[5]),
|
||||
Checkbox(&options_label[6], &options_state[6]),
|
||||
Checkbox(&options_label[7], &options_state[7]),
|
||||
});
|
||||
|
||||
auto compiler_component = Container::Horizontal({
|
||||
compiler,
|
||||
flags,
|
||||
Container::Vertical({
|
||||
executable_,
|
||||
Container::Horizontal({
|
||||
input_add,
|
||||
input,
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
auto render_command = [&] {
|
||||
Elements line;
|
||||
// Compiler
|
||||
line.push_back(text(compiler_entries[compiler_selected]) | bold);
|
||||
// flags
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
if (options_state[i]) {
|
||||
line.push_back(text(" "));
|
||||
line.push_back(text(options_label[i]) | dim);
|
||||
}
|
||||
}
|
||||
// Executable
|
||||
if (!executable_content_.empty()) {
|
||||
line.push_back(text(" -o ") | bold);
|
||||
line.push_back(text(executable_content_) | color(Color::BlueLight) |
|
||||
bold);
|
||||
}
|
||||
// Input
|
||||
for (auto& it : input_entries) {
|
||||
line.push_back(text(" " + it) | color(Color::RedLight));
|
||||
}
|
||||
return line;
|
||||
};
|
||||
|
||||
auto compiler_renderer = Renderer(compiler_component, [&] {
|
||||
auto compiler_win = window(text("Compiler"),
|
||||
compiler->Render() | vscroll_indicator | frame);
|
||||
auto flags_win =
|
||||
window(text("Flags"), flags->Render() | vscroll_indicator | frame);
|
||||
auto executable_win = window(text("Executable:"), executable_->Render());
|
||||
auto input_win =
|
||||
window(text("Input"), hbox({
|
||||
vbox({
|
||||
hbox({
|
||||
text("Add: "),
|
||||
input_add->Render(),
|
||||
}) | size(WIDTH, EQUAL, 20) |
|
||||
size(HEIGHT, EQUAL, 1),
|
||||
filler(),
|
||||
}),
|
||||
separator(),
|
||||
input->Render() | vscroll_indicator | frame |
|
||||
size(HEIGHT, EQUAL, 3) | flex,
|
||||
}));
|
||||
return vbox({
|
||||
hbox({
|
||||
compiler_win,
|
||||
flags_win,
|
||||
vbox({
|
||||
executable_win | size(WIDTH, EQUAL, 20),
|
||||
input_win | size(WIDTH, EQUAL, 60),
|
||||
}),
|
||||
filler(),
|
||||
}) | size(HEIGHT, LESS_THAN, 8),
|
||||
hflow(render_command()) | flex_grow,
|
||||
}) |
|
||||
flex_grow;
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Spinner
|
||||
// ---------------------------------------------------------------------------
|
||||
auto spinner_tab_renderer = Renderer([&] {
|
||||
Elements entries;
|
||||
for (int i = 0; i < 22; ++i) {
|
||||
entries.push_back(spinner(i, shift / 5) | bold |
|
||||
size(WIDTH, GREATER_THAN, 2) | border);
|
||||
}
|
||||
return hflow(std::move(entries));
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Colors
|
||||
// ---------------------------------------------------------------------------
|
||||
auto color_tab_renderer = Renderer([] {
|
||||
auto basic_color_display =
|
||||
vbox({
|
||||
text("16 color palette:"),
|
||||
separator(),
|
||||
hbox({
|
||||
vbox({
|
||||
color(Color::Default, text("Default")),
|
||||
color(Color::Black, text("Black")),
|
||||
color(Color::GrayDark, text("GrayDark")),
|
||||
color(Color::GrayLight, text("GrayLight")),
|
||||
color(Color::White, text("White")),
|
||||
color(Color::Blue, text("Blue")),
|
||||
color(Color::BlueLight, text("BlueLight")),
|
||||
color(Color::Cyan, text("Cyan")),
|
||||
color(Color::CyanLight, text("CyanLight")),
|
||||
color(Color::Green, text("Green")),
|
||||
color(Color::GreenLight, text("GreenLight")),
|
||||
color(Color::Magenta, text("Magenta")),
|
||||
color(Color::MagentaLight, text("MagentaLight")),
|
||||
color(Color::Red, text("Red")),
|
||||
color(Color::RedLight, text("RedLight")),
|
||||
color(Color::Yellow, text("Yellow")),
|
||||
color(Color::YellowLight, text("YellowLight")),
|
||||
}),
|
||||
vbox({
|
||||
bgcolor(Color::Default, text("Default")),
|
||||
bgcolor(Color::Black, text("Black")),
|
||||
bgcolor(Color::GrayDark, text("GrayDark")),
|
||||
bgcolor(Color::GrayLight, text("GrayLight")),
|
||||
bgcolor(Color::White, text("White")),
|
||||
bgcolor(Color::Blue, text("Blue")),
|
||||
bgcolor(Color::BlueLight, text("BlueLight")),
|
||||
bgcolor(Color::Cyan, text("Cyan")),
|
||||
bgcolor(Color::CyanLight, text("CyanLight")),
|
||||
bgcolor(Color::Green, text("Green")),
|
||||
bgcolor(Color::GreenLight, text("GreenLight")),
|
||||
bgcolor(Color::Magenta, text("Magenta")),
|
||||
bgcolor(Color::MagentaLight, text("MagentaLight")),
|
||||
bgcolor(Color::Red, text("Red")),
|
||||
bgcolor(Color::RedLight, text("RedLight")),
|
||||
bgcolor(Color::Yellow, text("Yellow")),
|
||||
bgcolor(Color::YellowLight, text("YellowLight")),
|
||||
}),
|
||||
}),
|
||||
}) |
|
||||
border;
|
||||
|
||||
auto palette_256_color_display = text("256 colors palette:");
|
||||
{
|
||||
std::vector<std::vector<ColorInfo>> info_columns = ColorInfoSorted2D();
|
||||
Elements columns;
|
||||
for (auto& column : info_columns) {
|
||||
Elements column_elements;
|
||||
for (auto& it : column) {
|
||||
column_elements.push_back(
|
||||
text(" ") | bgcolor(Color(Color::Palette256(it.index_256))));
|
||||
}
|
||||
columns.push_back(hbox(std::move(column_elements)));
|
||||
}
|
||||
palette_256_color_display = vbox({
|
||||
palette_256_color_display,
|
||||
separator(),
|
||||
vbox(columns),
|
||||
}) |
|
||||
border;
|
||||
}
|
||||
|
||||
// True color display.
|
||||
auto true_color_display = text("TrueColors: 24bits:");
|
||||
{
|
||||
int saturation = 255;
|
||||
Elements array;
|
||||
for (int value = 0; value < 255; value += 16) {
|
||||
Elements line;
|
||||
for (int hue = 0; hue < 255; hue += 6) {
|
||||
line.push_back(text("▀") //
|
||||
| color(Color::HSV(hue, saturation, value)) //
|
||||
| bgcolor(Color::HSV(hue, saturation, value + 8)));
|
||||
}
|
||||
array.push_back(hbox(std::move(line)));
|
||||
}
|
||||
true_color_display = vbox({
|
||||
true_color_display,
|
||||
separator(),
|
||||
vbox(std::move(array)),
|
||||
}) |
|
||||
border;
|
||||
}
|
||||
|
||||
return flexbox(
|
||||
{
|
||||
basic_color_display,
|
||||
palette_256_color_display,
|
||||
true_color_display,
|
||||
},
|
||||
FlexboxConfig().SetGap(1, 1));
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Gauges
|
||||
// ---------------------------------------------------------------------------
|
||||
auto render_gauge = [&shift](int delta) {
|
||||
float progress = (shift + delta) % 500 / 500.f;
|
||||
return hbox({
|
||||
text(std::to_string(int(progress * 100)) + "% ") |
|
||||
size(WIDTH, EQUAL, 5),
|
||||
gauge(progress),
|
||||
});
|
||||
};
|
||||
|
||||
auto gauge_component = Renderer([render_gauge] {
|
||||
return vbox({
|
||||
render_gauge(0) | color(Color::Black),
|
||||
render_gauge(100) | color(Color::GrayDark),
|
||||
render_gauge(50) | color(Color::GrayLight),
|
||||
render_gauge(6894) | color(Color::White),
|
||||
separator(),
|
||||
render_gauge(6841) | color(Color::Blue),
|
||||
render_gauge(9813) | color(Color::BlueLight),
|
||||
render_gauge(98765) | color(Color::Cyan),
|
||||
render_gauge(98) | color(Color::CyanLight),
|
||||
render_gauge(9846) | color(Color::Green),
|
||||
render_gauge(1122) | color(Color::GreenLight),
|
||||
render_gauge(84) | color(Color::Magenta),
|
||||
render_gauge(645) | color(Color::MagentaLight),
|
||||
render_gauge(568) | color(Color::Red),
|
||||
render_gauge(2222) | color(Color::RedLight),
|
||||
render_gauge(220) | color(Color::Yellow),
|
||||
render_gauge(348) | color(Color::YellowLight),
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Paragraph
|
||||
// ---------------------------------------------------------------------------
|
||||
auto make_box = [](size_t dimx, size_t dimy) {
|
||||
std::string title = std::to_string(dimx) + "x" + std::to_string(dimy);
|
||||
return window(text(title) | hcenter | bold,
|
||||
text("content") | hcenter | dim) |
|
||||
size(WIDTH, EQUAL, dimx) | size(HEIGHT, EQUAL, dimy);
|
||||
};
|
||||
|
||||
auto paragraph_renderer_left = Renderer([&] {
|
||||
std::string str =
|
||||
"Lorem Ipsum is simply dummy text of the printing and typesetting "
|
||||
"industry.\nLorem Ipsum has been the industry's standard dummy text "
|
||||
"ever since the 1500s, when an unknown printer took a galley of type "
|
||||
"and scrambled it to make a type specimen book.";
|
||||
return vbox({
|
||||
window(text("Align left:"), paragraphAlignLeft(str)),
|
||||
window(text("Align center:"), paragraphAlignCenter(str)),
|
||||
window(text("Align right:"), paragraphAlignRight(str)),
|
||||
window(text("Align justify:"), paragraphAlignJustify(str)),
|
||||
window(text("Side by side"), hbox({
|
||||
paragraph(str),
|
||||
separator(),
|
||||
paragraph(str),
|
||||
})),
|
||||
window(text("Elements with different size:"),
|
||||
flexbox({
|
||||
make_box(10, 5),
|
||||
make_box(9, 4),
|
||||
make_box(8, 4),
|
||||
make_box(6, 3),
|
||||
make_box(10, 5),
|
||||
make_box(9, 4),
|
||||
make_box(8, 4),
|
||||
make_box(6, 3),
|
||||
make_box(10, 5),
|
||||
make_box(9, 4),
|
||||
make_box(8, 4),
|
||||
make_box(6, 3),
|
||||
})),
|
||||
}) |
|
||||
vscroll_indicator | yframe | flex;
|
||||
});
|
||||
|
||||
auto paragraph_renderer_right = Renderer([] {
|
||||
return paragraph("<--- This vertical bar is resizable using the mouse") |
|
||||
center;
|
||||
});
|
||||
|
||||
int paragraph_renderer_split_position = Terminal::Size().dimx / 2;
|
||||
auto paragraph_renderer_group =
|
||||
ResizableSplitLeft(paragraph_renderer_left, paragraph_renderer_right,
|
||||
¶graph_renderer_split_position);
|
||||
auto paragraph_renderer_group_renderer =
|
||||
Renderer(paragraph_renderer_group,
|
||||
[&] { return paragraph_renderer_group->Render(); });
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Tabs
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
int tab_index = 0;
|
||||
std::vector<std::string> tab_entries = {
|
||||
"htop", "color", "spinner", "gauge", "compiler", "paragraph",
|
||||
};
|
||||
auto tab_selection =
|
||||
Menu(&tab_entries, &tab_index, MenuOption::HorizontalAnimated());
|
||||
auto tab_content = Container::Tab(
|
||||
{
|
||||
htop,
|
||||
color_tab_renderer,
|
||||
spinner_tab_renderer,
|
||||
gauge_component,
|
||||
compiler_renderer,
|
||||
paragraph_renderer_group_renderer,
|
||||
},
|
||||
&tab_index);
|
||||
|
||||
auto exit_button =
|
||||
Button("Exit", [&] { screen.Exit(); }, ButtonOption::Animated());
|
||||
|
||||
auto main_container = Container::Vertical({
|
||||
Container::Horizontal({
|
||||
tab_selection,
|
||||
exit_button,
|
||||
}),
|
||||
tab_content,
|
||||
});
|
||||
|
||||
auto main_renderer = Renderer(main_container, [&] {
|
||||
return vbox({
|
||||
text("FTXUI Demo") | bold | hcenter,
|
||||
hbox({
|
||||
tab_selection->Render() | flex,
|
||||
exit_button->Render(),
|
||||
}),
|
||||
tab_content->Render() | flex,
|
||||
});
|
||||
});
|
||||
|
||||
Loop loop(&screen, main_renderer);
|
||||
while (!loop.HasQuitted()) {
|
||||
// Update the state of the application.
|
||||
shift++;
|
||||
|
||||
// Request a new frame to be drawn.
|
||||
screen.RequestAnimationFrame();
|
||||
|
||||
// Execute events, and draw the next frame.
|
||||
loop.RunOnce();
|
||||
|
||||
// Sleep for a short duration to control the frame rate (60 FPS).
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000 / 60));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
68
ftxui/examples/component/input.cpp
Normal file
68
ftxui/examples/component/input.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
// 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.
|
||||
#include <memory> // for allocator, __shared_ptr_access
|
||||
#include <string> // for char_traits, operator+, string, basic_string
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Input, Renderer, Vertical
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/component_options.hpp" // for InputOption
|
||||
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for text, hbox, separator, Element, operator|, vbox, border
|
||||
#include "ftxui/util/ref.hpp" // for Ref
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
|
||||
// The data:
|
||||
std::string first_name;
|
||||
std::string last_name;
|
||||
std::string password;
|
||||
std::string phoneNumber;
|
||||
|
||||
// The basic input components:
|
||||
Component input_first_name = Input(&first_name, "first name");
|
||||
Component input_last_name = Input(&last_name, "last name");
|
||||
|
||||
// The password input component:
|
||||
InputOption password_option;
|
||||
password_option.password = true;
|
||||
Component input_password = Input(&password, "password", password_option);
|
||||
|
||||
// The phone number input component:
|
||||
// We are using `CatchEvent` to filter out non-digit characters.
|
||||
Component input_phone_number = Input(&phoneNumber, "phone number");
|
||||
input_phone_number |= CatchEvent([&](Event event) {
|
||||
return event.is_character() && !std::isdigit(event.character()[0]);
|
||||
});
|
||||
input_phone_number |= CatchEvent([&](Event event) {
|
||||
return event.is_character() && phoneNumber.size() > 10;
|
||||
});
|
||||
|
||||
// The component tree:
|
||||
auto component = Container::Vertical({
|
||||
input_first_name,
|
||||
input_last_name,
|
||||
input_password,
|
||||
input_phone_number,
|
||||
});
|
||||
|
||||
// Tweak how the component tree is rendered:
|
||||
auto renderer = Renderer(component, [&] {
|
||||
return vbox({
|
||||
hbox(text(" First name : "), input_first_name->Render()),
|
||||
hbox(text(" Last name : "), input_last_name->Render()),
|
||||
hbox(text(" Password : "), input_password->Render()),
|
||||
hbox(text(" Phone num : "), input_phone_number->Render()),
|
||||
separator(),
|
||||
text("Hello " + first_name + " " + last_name),
|
||||
text("Your password is " + password),
|
||||
text("Your phone number is " + phoneNumber),
|
||||
}) |
|
||||
border;
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
screen.Loop(renderer);
|
||||
}
|
||||
30
ftxui/examples/component/input_in_frame.cpp
Normal file
30
ftxui/examples/component/input_in_frame.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright 2021 Arthur Sonzogni. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSE file.
|
||||
#include <memory> // for allocator, __shared_ptr_access
|
||||
#include <string> // for string, basic_string, operator+, to_string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Input, Renderer, Vertical
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, Element, size, border, frame, vscroll_indicator, HEIGHT, LESS_THAN
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
|
||||
Component input_list = Container::Vertical({});
|
||||
std::vector<std::string> items(100, "");
|
||||
for (size_t i = 0; i < items.size(); ++i) {
|
||||
input_list->Add(Input(&(items[i]), "placeholder " + std::to_string(i)));
|
||||
}
|
||||
|
||||
auto renderer = Renderer(input_list, [&] {
|
||||
return input_list->Render() | vscroll_indicator | frame | border |
|
||||
size(HEIGHT, LESS_THAN, 10);
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
screen.Loop(renderer);
|
||||
}
|
||||
97
ftxui/examples/component/input_style.cpp
Normal file
97
ftxui/examples/component/input_style.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
// 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.
|
||||
#include <ftxui/dom/linear_gradient.hpp> // for LinearGradient
|
||||
#include <ftxui/screen/color.hpp> // for Color, Color::White, Color::Red, Color::Blue, Color::Black, Color::GrayDark, ftxui
|
||||
#include <functional> // for function
|
||||
#include <string> // for allocator, string
|
||||
#include <utility> // for move
|
||||
|
||||
#include "ftxui/component/component.hpp" // for Input, Horizontal, Vertical, operator|
|
||||
#include "ftxui/component/component_base.hpp" // for Component
|
||||
#include "ftxui/component/component_options.hpp" // for InputState, InputOption
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for operator|=, Element, bgcolor, operator|, separatorEmpty, color, borderEmpty, separator, text, center, dim, hbox, vbox, border, borderDouble, borderRounded
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
|
||||
InputOption style_1 = InputOption::Default();
|
||||
|
||||
InputOption style_2 = InputOption::Spacious();
|
||||
|
||||
InputOption style_3 = InputOption::Spacious();
|
||||
style_3.transform = [](InputState state) {
|
||||
state.element |= borderEmpty;
|
||||
|
||||
if (state.is_placeholder) {
|
||||
state.element |= dim;
|
||||
}
|
||||
|
||||
if (state.focused) {
|
||||
state.element |= borderDouble;
|
||||
state.element |= bgcolor(Color::White);
|
||||
state.element |= color(Color::Black);
|
||||
} else if (state.hovered) {
|
||||
state.element |= borderRounded;
|
||||
state.element |= bgcolor(LinearGradient(90, Color::Blue, Color::Red));
|
||||
state.element |= color(Color::White);
|
||||
} else {
|
||||
state.element |= border;
|
||||
state.element |= bgcolor(LinearGradient(0, Color::Blue, Color::Red));
|
||||
state.element |= color(Color::White);
|
||||
}
|
||||
|
||||
return state.element;
|
||||
};
|
||||
|
||||
InputOption style_4 = InputOption::Spacious();
|
||||
style_4.transform = [](InputState state) {
|
||||
state.element = hbox({
|
||||
text("Theorem") | center | borderEmpty | bgcolor(Color::Red),
|
||||
separatorEmpty(),
|
||||
separator() | color(Color::White),
|
||||
separatorEmpty(),
|
||||
std::move(state.element),
|
||||
});
|
||||
|
||||
state.element |= borderEmpty;
|
||||
if (state.is_placeholder) {
|
||||
state.element |= dim;
|
||||
}
|
||||
|
||||
if (state.focused) {
|
||||
state.element |= bgcolor(Color::Black);
|
||||
} else {
|
||||
state.element |= bgcolor(Color::Blue);
|
||||
}
|
||||
|
||||
if (state.hovered) {
|
||||
state.element |= bgcolor(Color::GrayDark);
|
||||
}
|
||||
|
||||
return vbox({state.element, separatorEmpty()});
|
||||
};
|
||||
|
||||
auto generateUiFromStyle = [&](InputOption style) {
|
||||
auto first_name = new std::string(); // Leaked
|
||||
auto middle_name = new std::string(); // Leaked
|
||||
auto last_name = new std::string(); // Leaked
|
||||
return Container::Vertical({
|
||||
Input(first_name, "first name", style),
|
||||
Input(middle_name, "middle name", style),
|
||||
Input(last_name, "last name", style),
|
||||
}) |
|
||||
borderEmpty;
|
||||
};
|
||||
|
||||
auto ui = Container::Horizontal({
|
||||
generateUiFromStyle(style_1),
|
||||
generateUiFromStyle(style_2),
|
||||
generateUiFromStyle(style_3),
|
||||
generateUiFromStyle(style_4),
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
screen.Loop(ui);
|
||||
}
|
||||
55
ftxui/examples/component/linear_gradient_gallery.cpp
Normal file
55
ftxui/examples/component/linear_gradient_gallery.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
// 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.
|
||||
#include <ftxui/component/component_base.hpp> // for ComponentBase, Component
|
||||
#include <ftxui/dom/elements.hpp> // for operator|, Element, flex, bgcolor, text, vbox, center
|
||||
#include <ftxui/dom/linear_gradient.hpp> // for LinearGradient
|
||||
#include <ftxui/screen/color.hpp> // for Color, Color::Blue, Color::Red
|
||||
#include <memory> // for __shared_ptr_access, shared_ptr
|
||||
#include <string> // for allocator, operator+, char_traits, string, to_string
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Slider, Renderer, Vertical
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto screen = ScreenInteractive::Fullscreen();
|
||||
|
||||
int angle = 180.f;
|
||||
float start = 0.f;
|
||||
float end = 1.f;
|
||||
|
||||
std::string slider_angle_text;
|
||||
std::string slider_start_text;
|
||||
std::string slider_end_text;
|
||||
|
||||
auto slider_angle = Slider(&slider_angle_text, &angle, 0, 360);
|
||||
auto slider_start = Slider(&slider_start_text, &start, 0.f, 1.f, 0.05f);
|
||||
auto slider_end = Slider(&slider_end_text, &end, 0.f, 1.f, 0.05f);
|
||||
|
||||
auto layout = Container::Vertical({
|
||||
slider_angle,
|
||||
slider_start,
|
||||
slider_end,
|
||||
});
|
||||
|
||||
auto renderer = Renderer(layout, [&] {
|
||||
slider_angle_text = "angle = " + std::to_string(angle) + "°";
|
||||
slider_start_text = "start = " + std::to_string(int(start * 100)) + "%";
|
||||
slider_end_text = "end = " + std::to_string(int(end * 100)) + "%";
|
||||
|
||||
auto background = text("Gradient") | center |
|
||||
bgcolor(LinearGradient()
|
||||
.Angle(angle)
|
||||
.Stop(Color::Blue, start)
|
||||
.Stop(Color::Red, end));
|
||||
return vbox({
|
||||
background | flex,
|
||||
layout->Render(),
|
||||
}) |
|
||||
flex;
|
||||
});
|
||||
|
||||
screen.Loop(renderer);
|
||||
}
|
||||
41
ftxui/examples/component/maybe.cpp
Normal file
41
ftxui/examples/component/maybe.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
// 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.
|
||||
#include <string> // for string, allocator, basic_string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for operator|, Maybe, Checkbox, Radiobox, Renderer, Vertical
|
||||
#include "ftxui/component/component_base.hpp" // for Component
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for Element, border, color, operator|, text
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::Red
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
int main() {
|
||||
std::vector<std::string> entries = {
|
||||
"entry 1",
|
||||
"entry 2",
|
||||
"entry 3",
|
||||
};
|
||||
int menu_1_selected = 0;
|
||||
int menu_2_selected = 0;
|
||||
|
||||
bool menu_1_show = false;
|
||||
bool menu_2_show = false;
|
||||
|
||||
auto layout = Container::Vertical({
|
||||
Checkbox("Show menu_1", &menu_1_show),
|
||||
Radiobox(&entries, &menu_1_selected) | border | Maybe(&menu_1_show),
|
||||
Checkbox("Show menu_2", &menu_2_show),
|
||||
Radiobox(&entries, &menu_2_selected) | border | Maybe(&menu_2_show),
|
||||
|
||||
Renderer([] {
|
||||
return text("You found the secret combinaison!") | color(Color::Red);
|
||||
}) | Maybe([&] { return menu_1_selected == 1 && menu_2_selected == 2; }),
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
screen.Loop(layout);
|
||||
}
|
||||
32
ftxui/examples/component/menu.cpp
Normal file
32
ftxui/examples/component/menu.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
// 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.
|
||||
#include <functional> // for function
|
||||
#include <iostream> // for basic_ostream::operator<<, operator<<, endl, basic_ostream, basic_ostream<>::__ostream_type, cout, ostream
|
||||
#include <string> // for string, basic_string, allocator
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Menu
|
||||
#include "ftxui/component/component_options.hpp" // for MenuOption
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
|
||||
std::vector<std::string> entries = {
|
||||
"entry 1",
|
||||
"entry 2",
|
||||
"entry 3",
|
||||
};
|
||||
int selected = 0;
|
||||
|
||||
MenuOption option;
|
||||
option.on_enter = screen.ExitLoopClosure();
|
||||
auto menu = Menu(&entries, &selected, option);
|
||||
|
||||
screen.Loop(menu);
|
||||
|
||||
std::cout << "Selected element = " << selected << std::endl;
|
||||
}
|
||||
79
ftxui/examples/component/menu2.cpp
Normal file
79
ftxui/examples/component/menu2.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
// 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.
|
||||
#include <functional> // for function
|
||||
#include <memory> // for allocator, __shared_ptr_access
|
||||
#include <string> // for string, basic_string, operator+, to_string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Menu, Horizontal, Renderer
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/component_options.hpp" // for MenuOption
|
||||
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for text, separator, bold, hcenter, vbox, hbox, gauge, Element, operator|, border
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
|
||||
std::vector<std::string> left_menu_entries = {
|
||||
"0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%",
|
||||
};
|
||||
std::vector<std::string> right_menu_entries = {
|
||||
"0%", "1%", "2%", "3%", "4%", "5%", "6%", "7%", "8%", "9%", "10%",
|
||||
};
|
||||
|
||||
auto menu_option = MenuOption();
|
||||
menu_option.on_enter = screen.ExitLoopClosure();
|
||||
|
||||
int left_menu_selected = 0;
|
||||
int right_menu_selected = 0;
|
||||
Component left_menu_ =
|
||||
Menu(&left_menu_entries, &left_menu_selected, menu_option);
|
||||
Component right_menu_ =
|
||||
Menu(&right_menu_entries, &right_menu_selected, menu_option);
|
||||
|
||||
Component container = Container::Horizontal({
|
||||
left_menu_,
|
||||
right_menu_,
|
||||
});
|
||||
|
||||
auto renderer = Renderer(container, [&] {
|
||||
int sum = left_menu_selected * 10 + right_menu_selected;
|
||||
return vbox({
|
||||
// -------- Top panel --------------
|
||||
hbox({
|
||||
// -------- Left Menu --------------
|
||||
vbox({
|
||||
hcenter(bold(text("Percentage by 10%"))),
|
||||
separator(),
|
||||
left_menu_->Render(),
|
||||
}),
|
||||
separator(),
|
||||
// -------- Right Menu --------------
|
||||
vbox({
|
||||
hcenter(bold(text("Percentage by 1%"))),
|
||||
separator(),
|
||||
right_menu_->Render(),
|
||||
}),
|
||||
separator(),
|
||||
}),
|
||||
separator(),
|
||||
// -------- Bottom panel --------------
|
||||
vbox({
|
||||
hbox({
|
||||
text(" gauge : "),
|
||||
gauge(sum / 100.0),
|
||||
}),
|
||||
hbox({
|
||||
text(" text : "),
|
||||
text(std::to_string(sum) + " %"),
|
||||
}),
|
||||
}),
|
||||
}) |
|
||||
border;
|
||||
});
|
||||
|
||||
screen.Loop(renderer);
|
||||
}
|
||||
83
ftxui/examples/component/menu_entries.cpp
Normal file
83
ftxui/examples/component/menu_entries.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
// 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.
|
||||
#include <functional> // for function
|
||||
#include <iostream> // for basic_ostream::operator<<, operator<<, endl, basic_ostream, basic_ostream<>::__ostream_type, cout, ostream
|
||||
#include <memory> // for allocator, shared_ptr, __shared_ptr_access
|
||||
#include <string> // for char_traits, to_string, operator+, string, basic_string
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for MenuEntry, Renderer, Vertical
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/component_options.hpp" // for MenuEntryOption
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, Element, separator, text, hbox, size, frame, color, vbox, HEIGHT, LESS_THAN, bold, border, inverted
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::Blue, Color::Cyan, Color::Green, Color::Red, Color::Yellow
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
// Define a special style for some menu entry.
|
||||
MenuEntryOption Colored(ftxui::Color c) {
|
||||
MenuEntryOption option;
|
||||
option.transform = [c](EntryState state) {
|
||||
state.label = (state.active ? "> " : " ") + state.label;
|
||||
Element e = text(state.label) | color(c);
|
||||
if (state.focused) {
|
||||
e = e | inverted;
|
||||
}
|
||||
if (state.active) {
|
||||
e = e | bold;
|
||||
}
|
||||
return e;
|
||||
};
|
||||
return option;
|
||||
}
|
||||
|
||||
int main() {
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
|
||||
int selected = 0;
|
||||
auto menu = Container::Vertical(
|
||||
{
|
||||
MenuEntry(" 1. improve"),
|
||||
MenuEntry(" 2. tolerant"),
|
||||
MenuEntry(" 3. career"),
|
||||
MenuEntry(" 4. cast"),
|
||||
MenuEntry(" 5. question"),
|
||||
|
||||
Renderer([] { return separator(); }),
|
||||
|
||||
MenuEntry(" 6. rear", Colored(Color::Red)),
|
||||
MenuEntry(" 7. drown", Colored(Color::Yellow)),
|
||||
MenuEntry(" 8. nail", Colored(Color::Green)),
|
||||
MenuEntry(" 9. quit", Colored(Color::Cyan)),
|
||||
MenuEntry("10. decorative", Colored(Color::Blue)),
|
||||
|
||||
Renderer([] { return separator(); }),
|
||||
|
||||
MenuEntry("11. costume"),
|
||||
MenuEntry("12. pick"),
|
||||
MenuEntry("13. oral"),
|
||||
MenuEntry("14. minister"),
|
||||
MenuEntry("15. football"),
|
||||
MenuEntry("16. welcome"),
|
||||
MenuEntry("17. copper"),
|
||||
MenuEntry("18. inhabitant"),
|
||||
MenuEntry("19. fortune"),
|
||||
},
|
||||
&selected);
|
||||
|
||||
// Display together the menu with a border
|
||||
auto renderer = Renderer(menu, [&] {
|
||||
return vbox({
|
||||
hbox(text("selected = "), text(std::to_string(selected))),
|
||||
separator(),
|
||||
menu->Render() | frame | size(HEIGHT, LESS_THAN, 10),
|
||||
}) |
|
||||
border;
|
||||
});
|
||||
|
||||
screen.Loop(renderer);
|
||||
|
||||
std::cout << "Selected element = " << selected << std::endl;
|
||||
}
|
||||
65
ftxui/examples/component/menu_entries_animated.cpp
Normal file
65
ftxui/examples/component/menu_entries_animated.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
// 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.
|
||||
#include <iostream> // for basic_ostream::operator<<, operator<<, endl, basic_ostream, basic_ostream<>::__ostream_type, cout, ostream
|
||||
#include <memory> // for shared_ptr, __shared_ptr_access
|
||||
#include <string> // for to_string, allocator
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for MenuEntryAnimated, Renderer, Vertical
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/component_options.hpp" // for MenuEntryAnimated
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, separator, Element, Decorator, color, text, hbox, size, bold, frame, inverted, vbox, HEIGHT, LESS_THAN, border
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::Blue, Color::Cyan, Color::Green, Color::Red, Color::Yellow
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
// Define a special style for some menu entry.
|
||||
MenuEntryOption Colored(ftxui::Color c) {
|
||||
MenuEntryOption option;
|
||||
option.animated_colors.foreground.enabled = true;
|
||||
option.animated_colors.background.enabled = true;
|
||||
option.animated_colors.background.active = c;
|
||||
option.animated_colors.background.inactive = Color::Black;
|
||||
option.animated_colors.foreground.active = Color::White;
|
||||
option.animated_colors.foreground.inactive = c;
|
||||
return option;
|
||||
}
|
||||
|
||||
int main() {
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
|
||||
int selected = 0;
|
||||
auto menu = Container::Vertical(
|
||||
{
|
||||
MenuEntry(" 1. rear", Colored(Color::Red)),
|
||||
MenuEntry(" 2. drown", Colored(Color::Yellow)),
|
||||
MenuEntry(" 3. nail", Colored(Color::Green)),
|
||||
MenuEntry(" 4. quit", Colored(Color::Cyan)),
|
||||
MenuEntry(" 5. decorative", Colored(Color::Blue)),
|
||||
MenuEntry(" 7. costume"),
|
||||
MenuEntry(" 8. pick"),
|
||||
MenuEntry(" 9. oral"),
|
||||
MenuEntry("11. minister"),
|
||||
MenuEntry("12. football"),
|
||||
MenuEntry("13. welcome"),
|
||||
MenuEntry("14. copper"),
|
||||
MenuEntry("15. inhabitant"),
|
||||
},
|
||||
&selected);
|
||||
|
||||
// Display together the menu with a border
|
||||
auto renderer = Renderer(menu, [&] {
|
||||
return vbox({
|
||||
hbox(text("selected = "), text(std::to_string(selected))),
|
||||
separator(),
|
||||
menu->Render() | frame,
|
||||
}) |
|
||||
border | bgcolor(Color::Black);
|
||||
});
|
||||
|
||||
screen.Loop(renderer);
|
||||
|
||||
std::cout << "Selected element = " << selected << std::endl;
|
||||
}
|
||||
33
ftxui/examples/component/menu_in_frame.cpp
Normal file
33
ftxui/examples/component/menu_in_frame.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
// 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.
|
||||
#include <memory> // for shared_ptr, __shared_ptr_access
|
||||
#include <string> // for string, basic_string, operator+, to_string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Radiobox, Renderer
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, Element, size, border, frame, HEIGHT, LESS_THAN
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
int main() {
|
||||
std::vector<std::string> entries;
|
||||
int selected = 0;
|
||||
|
||||
for (int i = 0; i < 30; ++i) {
|
||||
entries.push_back("Entry " + std::to_string(i));
|
||||
}
|
||||
auto radiobox = Menu(&entries, &selected);
|
||||
auto renderer = Renderer(radiobox, [&] {
|
||||
return radiobox->Render() | vscroll_indicator | frame |
|
||||
size(HEIGHT, LESS_THAN, 10) | border;
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
screen.Loop(renderer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
31
ftxui/examples/component/menu_in_frame_horizontal.cpp
Normal file
31
ftxui/examples/component/menu_in_frame_horizontal.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
// 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.
|
||||
#include <memory> // for shared_ptr, __shared_ptr_access
|
||||
#include <string> // for string, basic_string, operator+, to_string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Radiobox, Renderer
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, Element, size, border, frame, HEIGHT, LESS_THAN
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
int main() {
|
||||
std::vector<std::string> entries;
|
||||
int selected = 0;
|
||||
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
entries.push_back(std::to_string(i));
|
||||
}
|
||||
auto radiobox = Menu(&entries, &selected, MenuOption::Horizontal());
|
||||
auto renderer = Renderer(
|
||||
radiobox, [&] { return radiobox->Render() | hscroll_indicator | frame; });
|
||||
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
screen.Loop(renderer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
77
ftxui/examples/component/menu_multiple.cpp
Normal file
77
ftxui/examples/component/menu_multiple.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
// 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.
|
||||
#include <stdlib.h> // for EXIT_SUCCESS
|
||||
#include <memory> // for allocator, __shared_ptr_access
|
||||
#include <string> // for string, operator+, basic_string, to_string, char_traits
|
||||
#include <vector> // for vector, __alloc_traits<>::value_type
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Menu, Renderer, Horizontal, Vertical
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for text, Element, operator|, window, flex, vbox
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
Component Window(std::string title, Component component) {
|
||||
return Renderer(component, [component, title] { //
|
||||
return window(text(title), component->Render()) | flex;
|
||||
});
|
||||
}
|
||||
|
||||
int main() {
|
||||
int menu_selected[] = {0, 0, 0};
|
||||
std::vector<std::vector<std::string>> menu_entries = {
|
||||
{
|
||||
"Ananas",
|
||||
"Raspberry",
|
||||
"Citrus",
|
||||
},
|
||||
{
|
||||
"Potatoes",
|
||||
"Weat",
|
||||
"Rise",
|
||||
},
|
||||
{
|
||||
"Carrot",
|
||||
"Lettuce",
|
||||
"Tomato",
|
||||
},
|
||||
};
|
||||
|
||||
int menu_selected_global = 0;
|
||||
auto menu_global = Container::Vertical(
|
||||
{
|
||||
Window("Menu 1", Menu(&menu_entries[0], &menu_selected[0])),
|
||||
Window("Menu 2", Menu(&menu_entries[1], &menu_selected[1])),
|
||||
Window("Menu 3", Menu(&menu_entries[2], &menu_selected[2])),
|
||||
},
|
||||
&menu_selected_global);
|
||||
|
||||
auto info = Renderer([&] {
|
||||
int g = menu_selected_global;
|
||||
std::string value = menu_entries[g][menu_selected[g]];
|
||||
return window(text("Content"), //
|
||||
vbox({
|
||||
text("menu_selected_global = " + std::to_string(g)),
|
||||
text("menu_selected[0] = " +
|
||||
std::to_string(menu_selected[0])),
|
||||
text("menu_selected[1] = " +
|
||||
std::to_string(menu_selected[1])),
|
||||
text("menu_selected[2] = " +
|
||||
std::to_string(menu_selected[2])),
|
||||
text("Value = " + value),
|
||||
})) |
|
||||
flex;
|
||||
});
|
||||
|
||||
auto global = Container::Horizontal({
|
||||
menu_global,
|
||||
info,
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
screen.Loop(global);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
266
ftxui/examples/component/menu_style.cpp
Normal file
266
ftxui/examples/component/menu_style.cpp
Normal file
@@ -0,0 +1,266 @@
|
||||
// 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.
|
||||
#include <array> // for array
|
||||
#include <chrono> // for milliseconds
|
||||
#include <functional> // for function
|
||||
#include <memory> // for __shared_ptr_access, shared_ptr, allocator
|
||||
#include <string> // for string, char_traits, operator+, basic_string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/animation.hpp" // for ElasticOut, Linear
|
||||
#include "ftxui/component/component.hpp" // for Menu, Horizontal, Renderer, Vertical
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/component_options.hpp" // for MenuOption, EntryState, MenuEntryOption, AnimatedColorOption, AnimatedColorsOption, UnderlineOption
|
||||
#include "ftxui/component/mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for separator, operator|, Element, text, bgcolor, hbox, bold, color, filler, border, vbox, borderDouble, dim, flex, hcenter
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::Red, Color::Black, Color::Yellow, Color::Blue, Color::Default, Color::White
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
Component VMenu1(std::vector<std::string>* entries, int* selected);
|
||||
Component VMenu2(std::vector<std::string>* entries, int* selected);
|
||||
Component VMenu3(std::vector<std::string>* entries, int* selected);
|
||||
Component VMenu4(std::vector<std::string>* entries, int* selected);
|
||||
Component VMenu5(std::vector<std::string>* entries, int* selected);
|
||||
Component VMenu6(std::vector<std::string>* entries, int* selected);
|
||||
Component VMenu7(std::vector<std::string>* entries, int* selected);
|
||||
Component VMenu8(std::vector<std::string>* entries, int* selected);
|
||||
Component HMenu1(std::vector<std::string>* entries, int* selected);
|
||||
Component HMenu2(std::vector<std::string>* entries, int* selected);
|
||||
Component HMenu3(std::vector<std::string>* entries, int* selected);
|
||||
Component HMenu4(std::vector<std::string>* entries, int* selected);
|
||||
Component HMenu5(std::vector<std::string>* entries, int* selected);
|
||||
|
||||
int main() {
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
|
||||
std::vector<std::string> entries{
|
||||
"Monkey", "Dog", "Cat", "Bird", "Elephant", "Cat",
|
||||
};
|
||||
std::array<int, 12> selected = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
auto vmenu_1_ = VMenu1(&entries, &selected[0]);
|
||||
auto vmenu_2_ = VMenu2(&entries, &selected[1]);
|
||||
auto vmenu_3_ = VMenu3(&entries, &selected[2]);
|
||||
auto vmenu_4_ = VMenu4(&entries, &selected[3]);
|
||||
auto vmenu_5_ = VMenu5(&entries, &selected[4]);
|
||||
auto vmenu_6_ = VMenu6(&entries, &selected[5]);
|
||||
auto vmenu_7_ = VMenu7(&entries, &selected[6]);
|
||||
auto vmenu_8_ = VMenu8(&entries, &selected[7]);
|
||||
|
||||
auto hmenu_1_ = HMenu1(&entries, &selected[8]);
|
||||
auto hmenu_2_ = HMenu2(&entries, &selected[9]);
|
||||
auto hmenu_3_ = HMenu3(&entries, &selected[10]);
|
||||
auto hmenu_4_ = HMenu4(&entries, &selected[11]);
|
||||
auto hmenu_5_ = HMenu5(&entries, &selected[12]);
|
||||
|
||||
auto container = Container::Vertical({
|
||||
Container::Horizontal({
|
||||
vmenu_1_,
|
||||
vmenu_2_,
|
||||
vmenu_3_,
|
||||
vmenu_4_,
|
||||
vmenu_5_,
|
||||
vmenu_6_,
|
||||
vmenu_7_,
|
||||
vmenu_8_,
|
||||
}),
|
||||
hmenu_1_,
|
||||
hmenu_2_,
|
||||
hmenu_3_,
|
||||
hmenu_4_,
|
||||
hmenu_5_,
|
||||
});
|
||||
|
||||
auto renderer = Renderer(container, [&] {
|
||||
return //
|
||||
hbox({
|
||||
vbox({
|
||||
hbox({
|
||||
vmenu_1_->Render(),
|
||||
separator(),
|
||||
vmenu_2_->Render(),
|
||||
separator(),
|
||||
vmenu_3_->Render(),
|
||||
separator(),
|
||||
vmenu_4_->Render(),
|
||||
separator(),
|
||||
vmenu_5_->Render(),
|
||||
vmenu_6_->Render(),
|
||||
separator(),
|
||||
vmenu_7_->Render(),
|
||||
separator(),
|
||||
vmenu_8_->Render(),
|
||||
}),
|
||||
separator(),
|
||||
hmenu_1_->Render(),
|
||||
separator(),
|
||||
hmenu_2_->Render(),
|
||||
separator(),
|
||||
hmenu_3_->Render(),
|
||||
separator(),
|
||||
hmenu_4_->Render(),
|
||||
hmenu_5_->Render(),
|
||||
}) | border,
|
||||
filler(),
|
||||
});
|
||||
});
|
||||
|
||||
screen.Loop(renderer);
|
||||
}
|
||||
|
||||
Component VMenu1(std::vector<std::string>* entries, int* selected) {
|
||||
auto option = MenuOption::Vertical();
|
||||
option.entries_option.transform = [](EntryState state) {
|
||||
state.label = (state.active ? "> " : " ") + state.label;
|
||||
Element e = text(state.label);
|
||||
if (state.focused) {
|
||||
e = e | bgcolor(Color::Blue);
|
||||
}
|
||||
if (state.active) {
|
||||
e = e | bold;
|
||||
}
|
||||
return e;
|
||||
};
|
||||
return Menu(entries, selected, option);
|
||||
}
|
||||
|
||||
Component VMenu2(std::vector<std::string>* entries, int* selected) {
|
||||
auto option = MenuOption::Vertical();
|
||||
option.entries_option.transform = [](EntryState state) {
|
||||
state.label += (state.active ? " <" : " ");
|
||||
Element e = hbox(filler(), text(state.label));
|
||||
if (state.focused) {
|
||||
e = e | bgcolor(Color::Red);
|
||||
}
|
||||
if (state.active) {
|
||||
e = e | bold;
|
||||
}
|
||||
return e;
|
||||
};
|
||||
return Menu(entries, selected, option);
|
||||
}
|
||||
|
||||
Component VMenu3(std::vector<std::string>* entries, int* selected) {
|
||||
auto option = MenuOption::Vertical();
|
||||
option.entries_option.transform = [](EntryState state) {
|
||||
Element e = state.active ? text("[" + state.label + "]")
|
||||
: text(" " + state.label + " ");
|
||||
if (state.focused) {
|
||||
e = e | bold;
|
||||
}
|
||||
|
||||
if (state.focused) {
|
||||
e = e | color(Color::Blue);
|
||||
}
|
||||
if (state.active) {
|
||||
e = e | bold;
|
||||
}
|
||||
return e;
|
||||
};
|
||||
return Menu(entries, selected, option);
|
||||
}
|
||||
|
||||
Component VMenu4(std::vector<std::string>* entries, int* selected) {
|
||||
auto option = MenuOption::Vertical();
|
||||
option.entries_option.transform = [](EntryState state) {
|
||||
if (state.active && state.focused) {
|
||||
return text(state.label) | color(Color::Yellow) | bgcolor(Color::Black) |
|
||||
bold;
|
||||
}
|
||||
|
||||
if (state.active) {
|
||||
return text(state.label) | color(Color::Yellow) | bgcolor(Color::Black);
|
||||
}
|
||||
if (state.focused) {
|
||||
return text(state.label) | color(Color::Black) | bgcolor(Color::Yellow) |
|
||||
bold;
|
||||
}
|
||||
return text(state.label) | color(Color::Black) | bgcolor(Color::Yellow);
|
||||
};
|
||||
return Menu(entries, selected, option);
|
||||
}
|
||||
|
||||
Component VMenu5(std::vector<std::string>* entries, int* selected) {
|
||||
auto option = MenuOption::Vertical();
|
||||
option.entries_option.transform = [](EntryState state) {
|
||||
auto element = text(state.label);
|
||||
if (state.active && state.focused) {
|
||||
return element | borderDouble;
|
||||
}
|
||||
if (state.active) {
|
||||
return element | border;
|
||||
}
|
||||
if (state.focused) {
|
||||
return element | bold;
|
||||
}
|
||||
return element;
|
||||
};
|
||||
return Menu(entries, selected, option);
|
||||
}
|
||||
|
||||
Component VMenu6(std::vector<std::string>* entries, int* selected) {
|
||||
auto option = MenuOption::VerticalAnimated();
|
||||
option.underline.color_inactive = Color::Default;
|
||||
option.underline.color_active = Color::Red;
|
||||
option.underline.SetAnimationFunction(animation::easing::Linear);
|
||||
return Menu(entries, selected, option);
|
||||
}
|
||||
|
||||
Component VMenu7(std::vector<std::string>* entries, int* selected) {
|
||||
auto option = MenuOption::Vertical();
|
||||
option.entries_option.animated_colors.foreground.enabled = true;
|
||||
option.entries_option.animated_colors.background.enabled = true;
|
||||
option.entries_option.animated_colors.background.active = Color::Red;
|
||||
option.entries_option.animated_colors.background.inactive = Color::Black;
|
||||
option.entries_option.animated_colors.foreground.active = Color::White;
|
||||
option.entries_option.animated_colors.foreground.inactive = Color::Red;
|
||||
return Menu(entries, selected, option);
|
||||
}
|
||||
|
||||
Component VMenu8(std::vector<std::string>* entries, int* selected) {
|
||||
auto option = MenuOption::Vertical();
|
||||
option.entries_option.animated_colors.foreground.Set(
|
||||
Color::Red, Color::White, std::chrono::milliseconds(500));
|
||||
return Menu(entries, selected, option);
|
||||
}
|
||||
|
||||
Component HMenu1(std::vector<std::string>* entries, int* selected) {
|
||||
return Menu(entries, selected, MenuOption::Horizontal());
|
||||
}
|
||||
|
||||
Component HMenu2(std::vector<std::string>* entries, int* selected) {
|
||||
return Menu(entries, selected, MenuOption::Toggle());
|
||||
}
|
||||
|
||||
Component HMenu3(std::vector<std::string>* entries, int* selected) {
|
||||
auto option = MenuOption::Toggle();
|
||||
option.elements_infix = [] { return text(" 🮣🮠 "); };
|
||||
|
||||
return Menu(entries, selected, option);
|
||||
}
|
||||
|
||||
Component HMenu4(std::vector<std::string>* entries, int* selected) {
|
||||
return Menu(entries, selected, MenuOption::HorizontalAnimated());
|
||||
}
|
||||
|
||||
Component HMenu5(std::vector<std::string>* entries, int* selected) {
|
||||
auto option = MenuOption::HorizontalAnimated();
|
||||
option.underline.SetAnimation(std::chrono::milliseconds(1500),
|
||||
animation::easing::ElasticOut);
|
||||
option.entries_option.transform = [](EntryState state) {
|
||||
Element e = text(state.label) | hcenter | flex;
|
||||
if (state.active && state.focused) {
|
||||
e = e | bold;
|
||||
}
|
||||
if (!state.focused && !state.active) {
|
||||
e = e | dim;
|
||||
}
|
||||
return e;
|
||||
};
|
||||
option.underline.color_inactive = Color::Default;
|
||||
option.underline.color_active = Color::Red;
|
||||
return Menu(entries, selected, option);
|
||||
}
|
||||
94
ftxui/examples/component/menu_underline_animated_gallery.cpp
Normal file
94
ftxui/examples/component/menu_underline_animated_gallery.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
// 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.
|
||||
#include <chrono> // for operator""ms, literals
|
||||
#include <memory> // for allocator, shared_ptr, __shared_ptr_access
|
||||
#include <string> // for string, operator+, to_string, basic_string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/animation.hpp" // for BackOut, Duration
|
||||
#include "ftxui/component/component.hpp" // for Menu, Renderer, Vertical
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/component_options.hpp" // for MenuOption, UnderlineOption
|
||||
#include "ftxui/component/mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for text, Element, operator|, borderEmpty, inverted
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::Blue, Color::Red
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
Component DummyComponent(int id) {
|
||||
return Renderer([id](bool focused) {
|
||||
auto t = text("component " + std::to_string(id));
|
||||
if (focused) {
|
||||
t = t | inverted;
|
||||
}
|
||||
return t;
|
||||
});
|
||||
}
|
||||
|
||||
Component Text(const std::string& t) {
|
||||
return Renderer([t] { return text(t) | borderEmpty; });
|
||||
}
|
||||
|
||||
int main() {
|
||||
using namespace std::literals;
|
||||
std::vector<std::string> tab_values{
|
||||
"Tab 1", "Tab 2", "Tab 3", "A very very long tab", "탭",
|
||||
};
|
||||
int tab_selected = 0;
|
||||
|
||||
auto container = Container::Vertical({});
|
||||
|
||||
int frame_count = 0;
|
||||
container->Add(Renderer(
|
||||
[&] { return text("Frame count: " + std::to_string(frame_count++)); }));
|
||||
|
||||
{
|
||||
auto option = MenuOption::HorizontalAnimated();
|
||||
container->Add(Text("This demonstrate the Menu component"));
|
||||
container->Add(Menu(&tab_values, &tab_selected, option));
|
||||
}
|
||||
|
||||
{
|
||||
container->Add(Text("Set underline color to blue"));
|
||||
auto option = MenuOption::HorizontalAnimated();
|
||||
option.underline.color_inactive = Color::Blue;
|
||||
container->Add(Menu(&tab_values, &tab_selected, option));
|
||||
}
|
||||
|
||||
{
|
||||
container->Add(Text("Set underline active color to red"));
|
||||
auto option = MenuOption::HorizontalAnimated();
|
||||
option.underline.color_active = Color::Red;
|
||||
container->Add(Menu(&tab_values, &tab_selected, option));
|
||||
}
|
||||
|
||||
{
|
||||
container->Add(Text("Set animation duration to 0ms"));
|
||||
auto option = MenuOption::HorizontalAnimated();
|
||||
option.underline.SetAnimationDuration(0ms);
|
||||
container->Add(Menu(&tab_values, &tab_selected, option));
|
||||
}
|
||||
|
||||
{
|
||||
container->Add(Text("Set animation easing function to back-out"));
|
||||
auto option = MenuOption::HorizontalAnimated();
|
||||
option.underline.SetAnimationFunction(animation::easing::BackOut);
|
||||
option.underline.SetAnimationDuration(350ms);
|
||||
container->Add(Menu(&tab_values, &tab_selected, option));
|
||||
}
|
||||
|
||||
// option.underline_animation_follower_delay = 250ms
|
||||
{
|
||||
container->Add(Text("Add delay to desynchronize animation"));
|
||||
auto option = MenuOption::HorizontalAnimated();
|
||||
option.underline.follower_delay = 250ms;
|
||||
container->Add(Menu(&tab_values, &tab_selected, option));
|
||||
}
|
||||
|
||||
container->SetActiveChild(container->ChildAt(2));
|
||||
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
screen.Loop(container);
|
||||
}
|
||||
82
ftxui/examples/component/modal_dialog.cpp
Normal file
82
ftxui/examples/component/modal_dialog.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
// Copyright 2022 Arthur Sonzogni. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSE file.
|
||||
#include <ftxui/component/component_options.hpp> // for ButtonOption
|
||||
#include <ftxui/component/mouse.hpp> // for ftxui
|
||||
#include <functional> // for function
|
||||
#include <memory> // for allocator, shared_ptr
|
||||
|
||||
#include "ftxui/component/component.hpp" // for Button, operator|=, Renderer, Vertical, Modal
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive, Component
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, separator, text, size, Element, vbox, border, GREATER_THAN, WIDTH, center, HEIGHT
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
auto button_style = ButtonOption::Animated();
|
||||
|
||||
// Definition of the main component. The details are not important.
|
||||
Component MainComponent(std::function<void()> show_modal,
|
||||
std::function<void()> exit) {
|
||||
auto component = Container::Vertical({
|
||||
Button("Show modal", show_modal, button_style),
|
||||
Button("Quit", exit, button_style),
|
||||
});
|
||||
// Polish how the two buttons are rendered:
|
||||
component |= Renderer([&](Element inner) {
|
||||
return vbox({
|
||||
text("Main component"),
|
||||
separator(),
|
||||
inner,
|
||||
}) //
|
||||
| size(WIDTH, GREATER_THAN, 15) //
|
||||
| size(HEIGHT, GREATER_THAN, 15) //
|
||||
| border //
|
||||
| center; //
|
||||
});
|
||||
return component;
|
||||
}
|
||||
|
||||
// Definition of the modal component. The details are not important.
|
||||
Component ModalComponent(std::function<void()> do_nothing,
|
||||
std::function<void()> hide_modal) {
|
||||
auto component = Container::Vertical({
|
||||
Button("Do nothing", do_nothing, button_style),
|
||||
Button("Quit modal", hide_modal, button_style),
|
||||
});
|
||||
// Polish how the two buttons are rendered:
|
||||
component |= Renderer([&](Element inner) {
|
||||
return vbox({
|
||||
text("Modal component "),
|
||||
separator(),
|
||||
inner,
|
||||
}) //
|
||||
| size(WIDTH, GREATER_THAN, 30) //
|
||||
| border; //
|
||||
});
|
||||
return component;
|
||||
}
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
|
||||
// State of the application:
|
||||
bool modal_shown = false;
|
||||
|
||||
// Some actions modifying the state:
|
||||
auto show_modal = [&] { modal_shown = true; };
|
||||
auto hide_modal = [&] { modal_shown = false; };
|
||||
auto exit = screen.ExitLoopClosure();
|
||||
auto do_nothing = [&] {};
|
||||
|
||||
// Instanciate the main and modal components:
|
||||
auto main_component = MainComponent(show_modal, exit);
|
||||
auto modal_component = ModalComponent(do_nothing, hide_modal);
|
||||
|
||||
// Use the `Modal` function to use together the main component and its modal
|
||||
// window. The |modal_shown| boolean controls whether the modal is shown or
|
||||
// not.
|
||||
main_component |= Modal(modal_component, &modal_shown);
|
||||
|
||||
screen.Loop(main_component);
|
||||
return 0;
|
||||
}
|
||||
93
ftxui/examples/component/modal_dialog_custom.cpp
Normal file
93
ftxui/examples/component/modal_dialog_custom.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
// 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.
|
||||
#include <memory> // for allocator, shared_ptr, __shared_ptr_access
|
||||
#include <string> // for string, basic_string, char_traits, operator+
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Button, Renderer, Horizontal, Tab
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, Element, filler, text, hbox, separator, center, vbox, bold, border, clear_under, dbox, size, GREATER_THAN, HEIGHT
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
|
||||
// There are two layers. One at depth = 0 and the modal window at depth = 1;
|
||||
int depth = 0;
|
||||
|
||||
// The current rating of FTXUI.
|
||||
std::string rating = "3/5 stars";
|
||||
|
||||
// At depth=0, two buttons. One for rating FTXUI and one for quitting.
|
||||
auto button_rate_ftxui = Button("Rate FTXUI", [&] { depth = 1; });
|
||||
auto button_quit = Button("Quit", screen.ExitLoopClosure());
|
||||
|
||||
auto depth_0_container = Container::Horizontal({
|
||||
button_rate_ftxui,
|
||||
button_quit,
|
||||
});
|
||||
auto depth_0_renderer = Renderer(depth_0_container, [&] {
|
||||
return vbox({
|
||||
text("Modal dialog example"),
|
||||
separator(),
|
||||
text("☆☆☆ FTXUI:" + rating + " ☆☆☆") | bold,
|
||||
filler(),
|
||||
hbox({
|
||||
button_rate_ftxui->Render(),
|
||||
filler(),
|
||||
button_quit->Render(),
|
||||
}),
|
||||
}) |
|
||||
border | size(HEIGHT, GREATER_THAN, 18) | center;
|
||||
});
|
||||
|
||||
// At depth=1, The "modal" window.
|
||||
std::vector<std::string> rating_labels = {
|
||||
"1/5 stars", "2/5 stars", "3/5 stars", "4/5 stars", "5/5 stars",
|
||||
};
|
||||
auto on_rating = [&](std::string new_rating) {
|
||||
rating = new_rating;
|
||||
depth = 0;
|
||||
};
|
||||
auto depth_1_container = Container::Horizontal({
|
||||
Button(&rating_labels[0], [&] { on_rating(rating_labels[0]); }),
|
||||
Button(&rating_labels[1], [&] { on_rating(rating_labels[1]); }),
|
||||
Button(&rating_labels[2], [&] { on_rating(rating_labels[2]); }),
|
||||
Button(&rating_labels[3], [&] { on_rating(rating_labels[3]); }),
|
||||
Button(&rating_labels[4], [&] { on_rating(rating_labels[4]); }),
|
||||
});
|
||||
|
||||
auto depth_1_renderer = Renderer(depth_1_container, [&] {
|
||||
return vbox({
|
||||
text("Do you like FTXUI?"),
|
||||
separator(),
|
||||
hbox(depth_1_container->Render()),
|
||||
}) |
|
||||
border;
|
||||
});
|
||||
|
||||
auto main_container = Container::Tab(
|
||||
{
|
||||
depth_0_renderer,
|
||||
depth_1_renderer,
|
||||
},
|
||||
&depth);
|
||||
|
||||
auto main_renderer = Renderer(main_container, [&] {
|
||||
Element document = depth_0_renderer->Render();
|
||||
|
||||
if (depth == 1) {
|
||||
document = dbox({
|
||||
document,
|
||||
depth_1_renderer->Render() | clear_under | center,
|
||||
});
|
||||
}
|
||||
return document;
|
||||
});
|
||||
|
||||
screen.Loop(main_renderer);
|
||||
return 0;
|
||||
}
|
||||
50
ftxui/examples/component/nested_screen.cpp
Normal file
50
ftxui/examples/component/nested_screen.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
// 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.
|
||||
#include <memory> // for allocator, shared_ptr, __shared_ptr_access
|
||||
#include <string> // for operator+, string, char_traits, basic_string
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Button, Vertical, Renderer
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for separator, text, Element, operator|, vbox, border
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
void Nested(std::string path) {
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
auto back_button = Button("Back", screen.ExitLoopClosure());
|
||||
auto goto_1 = Button("Goto /1", [path] { Nested(path + "/1"); });
|
||||
auto goto_2 = Button("Goto /2", [path] { Nested(path + "/2"); });
|
||||
auto goto_3 = Button("Goto /3", [path] { Nested(path + "/3"); });
|
||||
auto layout = Container::Vertical({
|
||||
back_button,
|
||||
goto_1,
|
||||
goto_2,
|
||||
goto_3,
|
||||
});
|
||||
auto renderer = Renderer(layout, [&] {
|
||||
return vbox({
|
||||
text("path: " + path),
|
||||
separator(),
|
||||
back_button->Render(),
|
||||
goto_1->Render(),
|
||||
goto_2->Render(),
|
||||
goto_3->Render(),
|
||||
}) |
|
||||
border;
|
||||
});
|
||||
screen.Loop(renderer);
|
||||
}
|
||||
|
||||
int main() {
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
auto button_quit = Button("Quit", screen.ExitLoopClosure());
|
||||
auto button_nested = Button("Nested", [] { Nested(""); });
|
||||
screen.Loop(Container::Vertical({
|
||||
button_quit,
|
||||
button_nested,
|
||||
}));
|
||||
return 0;
|
||||
}
|
||||
66
ftxui/examples/component/print_key_press.cpp
Normal file
66
ftxui/examples/component/print_key_press.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
// 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.
|
||||
|
||||
#include <stddef.h> // for size_t
|
||||
#include <algorithm> // for max
|
||||
#include <memory> // for allocator, shared_ptr
|
||||
#include <string> // for char_traits, operator+, string, basic_string, to_string
|
||||
#include <utility> // for move
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for CatchEvent, Renderer
|
||||
#include "ftxui/component/event.hpp" // for Event
|
||||
#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Middle, Mouse::None, Mouse::Pressed, Mouse::Released, Mouse::Right, Mouse::WheelDown, Mouse::WheelUp
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for text, vbox, window, Element, Elements
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
std::string Code(Event event) {
|
||||
std::string codes;
|
||||
for (auto& it : event.input()) {
|
||||
codes += " " + std::to_string((unsigned int)it);
|
||||
}
|
||||
return codes;
|
||||
}
|
||||
|
||||
int main() {
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
|
||||
std::vector<Event> keys;
|
||||
|
||||
auto left_column = Renderer([&] {
|
||||
Elements children = {
|
||||
text("Codes"),
|
||||
separator(),
|
||||
};
|
||||
for (size_t i = std::max(0, (int)keys.size() - 20); i < keys.size(); ++i) {
|
||||
children.push_back(text(Code(keys[i])));
|
||||
}
|
||||
return vbox(children);
|
||||
});
|
||||
|
||||
auto right_column = Renderer([&] {
|
||||
Elements children = {
|
||||
text("Event"),
|
||||
separator(),
|
||||
};
|
||||
for (size_t i = std::max(0, (int)keys.size() - 20); i < keys.size(); ++i) {
|
||||
children.push_back(text(keys[i].DebugString()));
|
||||
}
|
||||
return vbox(children);
|
||||
});
|
||||
|
||||
int split_size = 40;
|
||||
auto component = ResizableSplitLeft(left_column, right_column, &split_size);
|
||||
component |= border;
|
||||
|
||||
component |= CatchEvent([&](Event event) {
|
||||
keys.push_back(event);
|
||||
return false;
|
||||
});
|
||||
|
||||
screen.Loop(component);
|
||||
}
|
||||
25
ftxui/examples/component/radiobox.cpp
Normal file
25
ftxui/examples/component/radiobox.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
// 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.
|
||||
#include <string> // for string, allocator, basic_string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Radiobox
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
int main() {
|
||||
std::vector<std::string> radiobox_list = {
|
||||
"Use gcc",
|
||||
"Use clang",
|
||||
"Use emscripten",
|
||||
"Use tcc",
|
||||
};
|
||||
int selected = 0;
|
||||
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
screen.Loop(Radiobox(&radiobox_list, &selected));
|
||||
return 0;
|
||||
}
|
||||
33
ftxui/examples/component/radiobox_in_frame.cpp
Normal file
33
ftxui/examples/component/radiobox_in_frame.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
// 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.
|
||||
#include <memory> // for shared_ptr, __shared_ptr_access
|
||||
#include <string> // for string, basic_string, operator+, to_string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Radiobox, Renderer
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, Element, size, border, frame, HEIGHT, LESS_THAN
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
int main() {
|
||||
std::vector<std::string> entries;
|
||||
int selected = 0;
|
||||
|
||||
for (int i = 0; i < 30; ++i) {
|
||||
entries.push_back("RadioBox " + std::to_string(i));
|
||||
}
|
||||
auto radiobox = Radiobox(&entries, &selected);
|
||||
auto renderer = Renderer(radiobox, [&] {
|
||||
return radiobox->Render() | vscroll_indicator | frame |
|
||||
size(HEIGHT, LESS_THAN, 10) | border;
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
screen.Loop(renderer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
50
ftxui/examples/component/renderer.cpp
Normal file
50
ftxui/examples/component/renderer.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
// 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.
|
||||
#include <memory> // for shared_ptr, allocator, __shared_ptr_access
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Renderer, Button, Vertical
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, Element, text, bold, border, center, color
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::Red
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
|
||||
// A Renderer() is a component using a lambda function as a parameter to
|
||||
// render itself.
|
||||
|
||||
// 1. Example of focusable renderer:
|
||||
auto renderer_focusable = Renderer([](bool focused) {
|
||||
if (focused) {
|
||||
return text("FOCUSABLE RENDERER()") | center | bold | border;
|
||||
} else {
|
||||
return text(" Focusable renderer() ") | center | border;
|
||||
}
|
||||
});
|
||||
|
||||
// 2. Examples of a non focusable renderer.
|
||||
auto renderer_non_focusable = Renderer([&] {
|
||||
return text("~~~~~ Non Focusable renderer() ~~~~~"); //
|
||||
});
|
||||
|
||||
// 3. Renderer can wrap other components to redefine their Render() function.
|
||||
auto button = Button("Wrapped quit button", screen.ExitLoopClosure());
|
||||
auto renderer_wrap = Renderer(button, [&] {
|
||||
if (button->Focused()) {
|
||||
return button->Render() | bold | color(Color::Red);
|
||||
} else {
|
||||
return button->Render();
|
||||
}
|
||||
});
|
||||
|
||||
// Let's renderer everyone:
|
||||
screen.Loop(Container::Vertical({
|
||||
renderer_focusable,
|
||||
renderer_non_focusable,
|
||||
renderer_wrap,
|
||||
}));
|
||||
}
|
||||
38
ftxui/examples/component/resizable_split.cpp
Normal file
38
ftxui/examples/component/resizable_split.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
// 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.
|
||||
#include <memory> // for shared_ptr, allocator, __shared_ptr_access
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Renderer, ResizableSplitBottom, ResizableSplitLeft, ResizableSplitRight, ResizableSplitTop
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for Element, operator|, text, center, border
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
int main() {
|
||||
auto screen = ScreenInteractive::Fullscreen();
|
||||
|
||||
auto middle = Renderer([] { return text("middle") | center; });
|
||||
auto left = Renderer([] { return text("Left") | center; });
|
||||
auto right = Renderer([] { return text("right") | center; });
|
||||
auto top = Renderer([] { return text("top") | center; });
|
||||
auto bottom = Renderer([] { return text("bottom") | center; });
|
||||
|
||||
int left_size = 20;
|
||||
int right_size = 20;
|
||||
int top_size = 10;
|
||||
int bottom_size = 10;
|
||||
|
||||
auto container = middle;
|
||||
container = ResizableSplitLeft(left, container, &left_size);
|
||||
container = ResizableSplitRight(right, container, &right_size);
|
||||
container = ResizableSplitTop(top, container, &top_size);
|
||||
container = ResizableSplitBottom(bottom, container, &bottom_size);
|
||||
|
||||
auto renderer =
|
||||
Renderer(container, [&] { return container->Render() | border; });
|
||||
|
||||
screen.Loop(renderer);
|
||||
}
|
||||
113
ftxui/examples/component/scrollbar.cpp
Normal file
113
ftxui/examples/component/scrollbar.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
// 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.
|
||||
#include <ftxui/component/component.hpp>
|
||||
#include <ftxui/component/screen_interactive.hpp>
|
||||
#include <string>
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
Component DummyWindowContent() {
|
||||
class Impl : public ComponentBase {
|
||||
private:
|
||||
float scroll_x = 0.1;
|
||||
float scroll_y = 0.1;
|
||||
|
||||
public:
|
||||
Impl() {
|
||||
auto content = Renderer([=] {
|
||||
const std::string lorem =
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed "
|
||||
"do eiusmod tempor incididunt ut labore et dolore magna "
|
||||
"aliqua. Ut enim ad minim veniam, quis nostrud exercitation "
|
||||
"ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis "
|
||||
"aute irure dolor in reprehenderit in voluptate velit esse "
|
||||
"cillum dolore eu fugiat nulla pariatur. Excepteur sint "
|
||||
"occaecat cupidatat non proident, sunt in culpa qui officia "
|
||||
"deserunt mollit anim id est laborum.";
|
||||
return vbox({
|
||||
text(lorem.substr(0, -1)), text(lorem.substr(5, -1)), text(""),
|
||||
text(lorem.substr(10, -1)), text(lorem.substr(15, -1)), text(""),
|
||||
text(lorem.substr(20, -1)), text(lorem.substr(25, -1)), text(""),
|
||||
text(lorem.substr(30, -1)), text(lorem.substr(35, -1)), text(""),
|
||||
text(lorem.substr(40, -1)), text(lorem.substr(45, -1)), text(""),
|
||||
text(lorem.substr(50, -1)), text(lorem.substr(55, -1)), text(""),
|
||||
text(lorem.substr(60, -1)), text(lorem.substr(65, -1)), text(""),
|
||||
text(lorem.substr(70, -1)), text(lorem.substr(75, -1)), text(""),
|
||||
text(lorem.substr(80, -1)), text(lorem.substr(85, -1)), text(""),
|
||||
text(lorem.substr(90, -1)), text(lorem.substr(95, -1)), text(""),
|
||||
text(lorem.substr(100, -1)), text(lorem.substr(105, -1)), text(""),
|
||||
text(lorem.substr(110, -1)), text(lorem.substr(115, -1)), text(""),
|
||||
text(lorem.substr(120, -1)), text(lorem.substr(125, -1)), text(""),
|
||||
text(lorem.substr(130, -1)), text(lorem.substr(135, -1)), text(""),
|
||||
text(lorem.substr(140, -1)),
|
||||
});
|
||||
});
|
||||
|
||||
auto scrollable_content = Renderer(content, [&, content] {
|
||||
return content->Render() | focusPositionRelative(scroll_x, scroll_y) |
|
||||
frame | flex;
|
||||
});
|
||||
|
||||
SliderOption<float> option_x;
|
||||
option_x.value = &scroll_x;
|
||||
option_x.min = 0.f;
|
||||
option_x.max = 1.f;
|
||||
option_x.increment = 0.1f;
|
||||
option_x.direction = Direction::Right;
|
||||
option_x.color_active = Color::Blue;
|
||||
option_x.color_inactive = Color::BlueLight;
|
||||
auto scrollbar_x = Slider(option_x);
|
||||
|
||||
SliderOption<float> option_y;
|
||||
option_y.value = &scroll_y;
|
||||
option_y.min = 0.f;
|
||||
option_y.max = 1.f;
|
||||
option_y.increment = 0.1f;
|
||||
option_y.direction = Direction::Down;
|
||||
option_y.color_active = Color::Yellow;
|
||||
option_y.color_inactive = Color::YellowLight;
|
||||
auto scrollbar_y = Slider(option_y);
|
||||
|
||||
Add(Container::Vertical({
|
||||
Container::Horizontal({
|
||||
scrollable_content,
|
||||
scrollbar_y,
|
||||
}) | flex,
|
||||
Container::Horizontal({
|
||||
scrollbar_x,
|
||||
Renderer([] { return text(L"x"); }),
|
||||
}),
|
||||
}));
|
||||
}
|
||||
};
|
||||
return Make<Impl>();
|
||||
}
|
||||
|
||||
int main() {
|
||||
auto window_1 = Window({
|
||||
.inner = DummyWindowContent(),
|
||||
.title = "First window",
|
||||
.width = 80,
|
||||
.height = 30,
|
||||
});
|
||||
|
||||
auto window_2 = Window({
|
||||
.inner = DummyWindowContent(),
|
||||
.title = "My window",
|
||||
.left = 40,
|
||||
.top = 20,
|
||||
.width = 80,
|
||||
.height = 30,
|
||||
});
|
||||
|
||||
auto window_container = Container::Stacked({
|
||||
window_1,
|
||||
window_2,
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::Fullscreen();
|
||||
screen.Loop(window_container);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
87
ftxui/examples/component/selection.cpp
Normal file
87
ftxui/examples/component/selection.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
// 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.
|
||||
#include <string> // for char_traits, operator+, string, basic_string
|
||||
|
||||
#include "ftxui/component/component.hpp" // for Input, Renderer, Vertical
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/component_options.hpp" // for InputOption
|
||||
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for text, hbox, separator, Element, operator|, vbox, border
|
||||
#include "ftxui/util/ref.hpp" // for Ref
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
Element LoremIpsum() {
|
||||
return vbox({
|
||||
text("FTXUI: A powerful library for building user interfaces."),
|
||||
text("Enjoy a rich set of components and a declarative style."),
|
||||
text("Create beautiful and responsive UIs with minimal effort."),
|
||||
text("Join the community and experience the power of FTXUI."),
|
||||
});
|
||||
}
|
||||
|
||||
int main() {
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
|
||||
auto quit =
|
||||
Button("Quit", screen.ExitLoopClosure(), ButtonOption::Animated());
|
||||
|
||||
int selection_change_counter = 0;
|
||||
std::string selection_content = "";
|
||||
screen.SelectionChange([&] {
|
||||
selection_change_counter++;
|
||||
selection_content = screen.GetSelection();
|
||||
});
|
||||
|
||||
// The components:
|
||||
auto renderer = Renderer(quit, [&] {
|
||||
return vbox({
|
||||
text("Select changed: " + std::to_string(selection_change_counter) +
|
||||
" times"),
|
||||
text("Currently selected: "),
|
||||
paragraph(selection_content) | vscroll_indicator | frame | border |
|
||||
size(HEIGHT, EQUAL, 10),
|
||||
window(text("Horizontal split"), hbox({
|
||||
LoremIpsum(),
|
||||
separator(),
|
||||
LoremIpsum(),
|
||||
separator(),
|
||||
LoremIpsum(),
|
||||
})),
|
||||
window(text("Vertical split"), vbox({
|
||||
LoremIpsum(),
|
||||
separator(),
|
||||
LoremIpsum(),
|
||||
separator(),
|
||||
LoremIpsum(),
|
||||
})),
|
||||
window(text("Grid split with different style"),
|
||||
vbox({
|
||||
hbox({
|
||||
LoremIpsum(),
|
||||
separator(),
|
||||
LoremIpsum() //
|
||||
| selectionBackgroundColor(Color::Yellow) //
|
||||
| selectionColor(Color::Black) //
|
||||
| selectionStyleReset,
|
||||
separator(),
|
||||
LoremIpsum() | selectionColor(Color::Blue),
|
||||
}),
|
||||
separator(),
|
||||
hbox({
|
||||
LoremIpsum() | selectionColor(Color::Red),
|
||||
separator(),
|
||||
LoremIpsum() | selectionStyle([](Pixel& pixel) {
|
||||
pixel.underlined_double = true;
|
||||
}),
|
||||
separator(),
|
||||
LoremIpsum(),
|
||||
}),
|
||||
})),
|
||||
quit->Render(),
|
||||
});
|
||||
});
|
||||
|
||||
screen.Loop(renderer);
|
||||
}
|
||||
16
ftxui/examples/component/slider.cpp
Normal file
16
ftxui/examples/component/slider.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Slider
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
int main() {
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
int value = 50;
|
||||
auto slider = Slider("Value:", &value, 0, 100, 1);
|
||||
screen.Loop(slider);
|
||||
}
|
||||
|
||||
// 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.
|
||||
49
ftxui/examples/component/slider_direction.cpp
Normal file
49
ftxui/examples/component/slider_direction.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
// 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.
|
||||
#include <array> // for array
|
||||
#include <cmath> // for sin
|
||||
#include <ftxui/component/component_base.hpp> // for ComponentBase
|
||||
#include <ftxui/component/component_options.hpp> // for SliderOption
|
||||
#include <ftxui/dom/direction.hpp> // for Direction, Direction::Up
|
||||
#include <ftxui/dom/elements.hpp> // for size, GREATER_THAN, HEIGHT
|
||||
#include <ftxui/util/ref.hpp> // for ConstRef, Ref
|
||||
#include <memory> // for shared_ptr, __shared_ptr_access
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Horizontal, Slider, operator|=
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
int main() {
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
std::array<int, 30> values;
|
||||
for (size_t i = 0; i < values.size(); ++i) {
|
||||
values[i] = 50 + 20 * std::sin(i * 0.3);
|
||||
}
|
||||
|
||||
auto layout_horizontal = Container::Horizontal({});
|
||||
for (auto& value : values) {
|
||||
// In C++17:
|
||||
SliderOption<int> option;
|
||||
option.value = &value;
|
||||
option.max = 100;
|
||||
option.increment = 5;
|
||||
option.direction = Direction::Up;
|
||||
layout_horizontal->Add(Slider<int>(option));
|
||||
|
||||
/* In C++20:
|
||||
layout_horizontal->Add(Slider<int>({
|
||||
.value = &values[i],
|
||||
.max = 100,
|
||||
.increment = 5,
|
||||
.direction = Direction::Up,
|
||||
}));
|
||||
*/
|
||||
}
|
||||
|
||||
layout_horizontal |= size(HEIGHT, GREATER_THAN, 20);
|
||||
|
||||
screen.Loop(layout_horizontal);
|
||||
}
|
||||
61
ftxui/examples/component/slider_rgb.cpp
Normal file
61
ftxui/examples/component/slider_rgb.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
// 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.
|
||||
#include <memory> // for allocator, shared_ptr, __shared_ptr_access
|
||||
#include <string> // for char_traits, operator+, to_string
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Slider, Renderer, Vertical
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for separator, operator|, Element, size, text, vbox, xflex, bgcolor, hbox, GREATER_THAN, WIDTH, border, HEIGHT, LESS_THAN
|
||||
#include "ftxui/screen/color.hpp" // for Color
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
Element ColorTile(int red, int green, int blue) {
|
||||
return text("") | size(WIDTH, GREATER_THAN, 14) |
|
||||
size(HEIGHT, GREATER_THAN, 7) | bgcolor(Color::RGB(red, green, blue));
|
||||
}
|
||||
|
||||
Element ColorString(int red, int green, int blue) {
|
||||
return text("RGB = (" + //
|
||||
std::to_string(red) + "," + //
|
||||
std::to_string(green) + "," + //
|
||||
std::to_string(blue) + ")" //
|
||||
);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int red = 128;
|
||||
int green = 25;
|
||||
int blue = 100;
|
||||
auto slider_red = Slider("Red :", &red, 0, 255, 1);
|
||||
auto slider_green = Slider("Green:", &green, 0, 255, 1);
|
||||
auto slider_blue = Slider("Blue :", &blue, 0, 255, 1);
|
||||
|
||||
auto container = Container::Vertical({
|
||||
slider_red,
|
||||
slider_green,
|
||||
slider_blue,
|
||||
});
|
||||
|
||||
auto renderer = Renderer(container, [&] {
|
||||
return hbox({
|
||||
ColorTile(red, green, blue),
|
||||
separator(),
|
||||
vbox({
|
||||
slider_red->Render(),
|
||||
separator(),
|
||||
slider_green->Render(),
|
||||
separator(),
|
||||
slider_blue->Render(),
|
||||
separator(),
|
||||
ColorString(red, green, blue),
|
||||
}) | xflex,
|
||||
}) |
|
||||
border | size(WIDTH, LESS_THAN, 80);
|
||||
});
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
screen.Loop(renderer);
|
||||
}
|
||||
70
ftxui/examples/component/tab_horizontal.cpp
Normal file
70
ftxui/examples/component/tab_horizontal.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
// 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.
|
||||
#include <memory> // for allocator, __shared_ptr_access, shared_ptr
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Radiobox, Renderer, Tab, Toggle, Vertical
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for Element, separator, operator|, vbox, border
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
int main() {
|
||||
std::vector<std::string> tab_values{
|
||||
"tab_1",
|
||||
"tab_2",
|
||||
"tab_3",
|
||||
};
|
||||
int tab_selected = 0;
|
||||
auto tab_toggle = Toggle(&tab_values, &tab_selected);
|
||||
|
||||
std::vector<std::string> tab_1_entries{
|
||||
"Forest",
|
||||
"Water",
|
||||
"I don't know",
|
||||
};
|
||||
int tab_1_selected = 0;
|
||||
|
||||
std::vector<std::string> tab_2_entries{
|
||||
"Hello",
|
||||
"Hi",
|
||||
"Hay",
|
||||
};
|
||||
int tab_2_selected = 0;
|
||||
|
||||
std::vector<std::string> tab_3_entries{
|
||||
"Table",
|
||||
"Nothing",
|
||||
"Is",
|
||||
"Empty",
|
||||
};
|
||||
int tab_3_selected = 0;
|
||||
auto tab_container = Container::Tab(
|
||||
{
|
||||
Radiobox(&tab_1_entries, &tab_1_selected),
|
||||
Radiobox(&tab_2_entries, &tab_2_selected),
|
||||
Radiobox(&tab_3_entries, &tab_3_selected),
|
||||
},
|
||||
&tab_selected);
|
||||
|
||||
auto container = Container::Vertical({
|
||||
tab_toggle,
|
||||
tab_container,
|
||||
});
|
||||
|
||||
auto renderer = Renderer(container, [&] {
|
||||
return vbox({
|
||||
tab_toggle->Render(),
|
||||
separator(),
|
||||
tab_container->Render(),
|
||||
}) |
|
||||
border;
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
screen.Loop(renderer);
|
||||
}
|
||||
70
ftxui/examples/component/tab_vertical.cpp
Normal file
70
ftxui/examples/component/tab_vertical.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
// 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.
|
||||
#include <memory> // for allocator, __shared_ptr_access, shared_ptr
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Radiobox, Horizontal, Menu, Renderer, Tab
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for Element, separator, hbox, operator|, border
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
int main() {
|
||||
std::vector<std::string> tab_values{
|
||||
"tab_1",
|
||||
"tab_2",
|
||||
"tab_3",
|
||||
};
|
||||
int tab_selected = 0;
|
||||
auto tab_menu = Menu(&tab_values, &tab_selected);
|
||||
|
||||
std::vector<std::string> tab_1_entries{
|
||||
"Forest",
|
||||
"Water",
|
||||
"I don't know",
|
||||
};
|
||||
int tab_1_selected = 0;
|
||||
|
||||
std::vector<std::string> tab_2_entries{
|
||||
"Hello",
|
||||
"Hi",
|
||||
"Hay",
|
||||
};
|
||||
int tab_2_selected = 0;
|
||||
|
||||
std::vector<std::string> tab_3_entries{
|
||||
"Table",
|
||||
"Nothing",
|
||||
"Is",
|
||||
"Empty",
|
||||
};
|
||||
int tab_3_selected = 0;
|
||||
auto tab_container = Container::Tab(
|
||||
{
|
||||
Radiobox(&tab_1_entries, &tab_1_selected),
|
||||
Radiobox(&tab_2_entries, &tab_2_selected),
|
||||
Radiobox(&tab_3_entries, &tab_3_selected),
|
||||
},
|
||||
&tab_selected);
|
||||
|
||||
auto container = Container::Horizontal({
|
||||
tab_menu,
|
||||
tab_container,
|
||||
});
|
||||
|
||||
auto renderer = Renderer(container, [&] {
|
||||
return hbox({
|
||||
tab_menu->Render(),
|
||||
separator(),
|
||||
tab_container->Render(),
|
||||
}) |
|
||||
border;
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
screen.Loop(renderer);
|
||||
}
|
||||
34
ftxui/examples/component/textarea.cpp
Normal file
34
ftxui/examples/component/textarea.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
// 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.
|
||||
#include <memory> // for allocator, __shared_ptr_access, shared_ptr
|
||||
#include <string> // for string
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Input, Renderer, ResizableSplitLeft
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase, Component
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, separator, text, Element, flex, vbox, border
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
|
||||
std::string content_1;
|
||||
std::string content_2;
|
||||
auto textarea_1 = Input(&content_1);
|
||||
auto textarea_2 = Input(&content_2);
|
||||
int size = 50;
|
||||
auto layout = ResizableSplitLeft(textarea_1, textarea_2, &size);
|
||||
|
||||
auto component = Renderer(layout, [&] {
|
||||
return vbox({
|
||||
text("Input:"),
|
||||
separator(),
|
||||
layout->Render() | flex,
|
||||
}) |
|
||||
border;
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::Fullscreen();
|
||||
screen.Loop(component);
|
||||
}
|
||||
64
ftxui/examples/component/toggle.cpp
Normal file
64
ftxui/examples/component/toggle.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
// 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.
|
||||
#include <memory> // for allocator, __shared_ptr_access
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Toggle, Renderer, Vertical
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for text, hbox, vbox, Element
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
int main() {
|
||||
std::vector<std::string> toggle_1_entries = {
|
||||
"On",
|
||||
"Off",
|
||||
};
|
||||
std::vector<std::string> toggle_2_entries = {
|
||||
"Enabled",
|
||||
"Disabled",
|
||||
};
|
||||
std::vector<std::string> toggle_3_entries = {
|
||||
"10€",
|
||||
"0€",
|
||||
};
|
||||
std::vector<std::string> toggle_4_entries = {
|
||||
"Nothing",
|
||||
"One element",
|
||||
"Several elements",
|
||||
};
|
||||
|
||||
int toggle_1_selected = 0;
|
||||
int toggle_2_selected = 0;
|
||||
int toggle_3_selected = 0;
|
||||
int toggle_4_selected = 0;
|
||||
Component toggle_1 = Toggle(&toggle_1_entries, &toggle_1_selected);
|
||||
Component toggle_2 = Toggle(&toggle_2_entries, &toggle_2_selected);
|
||||
Component toggle_3 = Toggle(&toggle_3_entries, &toggle_3_selected);
|
||||
Component toggle_4 = Toggle(&toggle_4_entries, &toggle_4_selected);
|
||||
|
||||
auto container = Container::Vertical({
|
||||
toggle_1,
|
||||
toggle_2,
|
||||
toggle_3,
|
||||
toggle_4,
|
||||
});
|
||||
|
||||
auto renderer = Renderer(container, [&] {
|
||||
return vbox({
|
||||
text("Choose your options:"),
|
||||
text(""),
|
||||
hbox(text(" * Poweroff on startup : "), toggle_1->Render()),
|
||||
hbox(text(" * Out of process : "), toggle_2->Render()),
|
||||
hbox(text(" * Price of the information : "), toggle_3->Render()),
|
||||
hbox(text(" * Number of elements : "), toggle_4->Render()),
|
||||
});
|
||||
});
|
||||
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
screen.Loop(renderer);
|
||||
}
|
||||
89
ftxui/examples/component/window.cpp
Normal file
89
ftxui/examples/component/window.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
// 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.
|
||||
#include <ftxui/component/component.hpp>
|
||||
#include <ftxui/component/screen_interactive.hpp>
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
}
|
||||
60
ftxui/examples/component/with_restored_io.cpp
Normal file
60
ftxui/examples/component/with_restored_io.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
// Copyright 2022 Arthur Sonzogni. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSE file.
|
||||
#include <cstdlib> // for system, EXIT_SUCCESS
|
||||
#include <iostream> // for operator<<, basic_ostream, basic_ostream::operator<<, cout, endl, flush, ostream, basic_ostream<>::__ostream_type, cin
|
||||
#include <memory> // for shared_ptr, __shared_ptr_access, allocator
|
||||
#include <string> // for getline, string
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Button, Horizontal, Renderer
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, filler, Element, borderEmpty, hbox, size, paragraph, vbox, LESS_THAN, border, center, HEIGHT, WIDTH
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
|
||||
auto screen = ScreenInteractive::Fullscreen();
|
||||
|
||||
// When pressing this button, "screen.WithRestoredIO" will execute the
|
||||
// temporarily uninstall the terminal hook and execute the provided callback
|
||||
// function. This allow running the application in a non-interactive mode.
|
||||
auto btn_run = Button("Execute with restored IO", screen.WithRestoredIO([] {
|
||||
std::cout << "This is a child program using stdin/stdout." << std::endl;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
std::cout << "Please enter 10 strings (" << i << "/10)" << std::flush;
|
||||
std::string input;
|
||||
std::getline(std::cin, input);
|
||||
}
|
||||
}));
|
||||
|
||||
auto btn_quit = Button("Quit", screen.ExitLoopClosure());
|
||||
|
||||
auto layout = Container::Horizontal({
|
||||
btn_run,
|
||||
btn_quit,
|
||||
});
|
||||
|
||||
auto renderer = Renderer(layout, [&] {
|
||||
auto explanation = paragraph(
|
||||
"After clicking this button, the ScreenInteractive will be "
|
||||
"suspended and access to stdin/stdout will temporarilly be "
|
||||
"restore for running a function.");
|
||||
auto element = vbox({
|
||||
explanation | borderEmpty,
|
||||
hbox({
|
||||
btn_run->Render(),
|
||||
filler(),
|
||||
btn_quit->Render(),
|
||||
}),
|
||||
});
|
||||
|
||||
element = element | borderEmpty | border | size(WIDTH, LESS_THAN, 80) |
|
||||
size(HEIGHT, LESS_THAN, 20) | center;
|
||||
return element;
|
||||
});
|
||||
|
||||
screen.Loop(renderer);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
38
ftxui/examples/dom/CMakeLists.txt
Normal file
38
ftxui/examples/dom/CMakeLists.txt
Normal file
@@ -0,0 +1,38 @@
|
||||
set(DIRECTORY_LIB dom)
|
||||
|
||||
example(border)
|
||||
example(border_colored)
|
||||
example(border_style)
|
||||
example(canvas)
|
||||
example(color_gallery)
|
||||
example(color_info_palette256)
|
||||
example(color_truecolor_HSV)
|
||||
example(color_truecolor_RGB)
|
||||
example(dbox)
|
||||
example(gauge)
|
||||
example(gauge_direction)
|
||||
example(graph)
|
||||
example(gridbox)
|
||||
example(hflow)
|
||||
example(html_like)
|
||||
example(linear_gradient)
|
||||
example(package_manager)
|
||||
example(paragraph)
|
||||
example(separator)
|
||||
example(separator_style)
|
||||
example(size)
|
||||
example(spinner)
|
||||
example(style_blink)
|
||||
example(style_bold)
|
||||
example(style_color)
|
||||
example(style_dim)
|
||||
example(style_gallery)
|
||||
example(style_hyperlink)
|
||||
example(style_inverted)
|
||||
example(style_italic)
|
||||
example(style_strikethrough)
|
||||
example(style_underlined)
|
||||
example(style_underlined_double)
|
||||
example(table)
|
||||
example(vbox_hbox)
|
||||
example(vflow)
|
||||
38
ftxui/examples/dom/border.cpp
Normal file
38
ftxui/examples/dom/border.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
// 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.
|
||||
#include <stdlib.h> // for EXIT_SUCCESS
|
||||
#include <ftxui/dom/elements.hpp> // for text, operator|, vbox, border, Element, Fit, hbox
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <memory> // for allocator
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto document = //
|
||||
hbox({
|
||||
vbox({
|
||||
text("Line 1"),
|
||||
text("Line 2"),
|
||||
text("Line 3"),
|
||||
}) | border,
|
||||
|
||||
vbox({
|
||||
text("Line 4"),
|
||||
text("Line 5"),
|
||||
text("Line 6"),
|
||||
}) | border,
|
||||
|
||||
vbox({
|
||||
text("Line 7"),
|
||||
text("Line 8"),
|
||||
text("Line 9"),
|
||||
}) | border,
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
39
ftxui/examples/dom/border_colored.cpp
Normal file
39
ftxui/examples/dom/border_colored.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// 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.
|
||||
#include <ftxui/dom/elements.hpp> // for operator|, text, Element, Fit, borderDouble, borderHeavy, borderLight, borderRounded, vbox
|
||||
#include <ftxui/screen/screen.hpp> // for Screen
|
||||
#include <iostream> // for endl, cout, ostream
|
||||
#include <memory> // for allocator
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
|
||||
auto make_boxed = [] {
|
||||
return vbox({
|
||||
text("borderLight") | borderStyled(LIGHT, Color::Red),
|
||||
text("borderDashed") | borderStyled(DASHED, Color::Green),
|
||||
text("borderHeavy") | borderStyled(HEAVY, Color::Blue),
|
||||
text("borderDouble") | borderStyled(DOUBLE, Color::Yellow),
|
||||
text("borderRounded") | borderStyled(ROUNDED, Color::Cyan),
|
||||
});
|
||||
};
|
||||
|
||||
auto document = hbox({
|
||||
make_boxed(),
|
||||
separator() | color(Color::Red),
|
||||
make_boxed(),
|
||||
separator() | color(Color::Red),
|
||||
make_boxed(),
|
||||
}) |
|
||||
borderStyled(ROUNDED, Color::Red);
|
||||
|
||||
auto screen =
|
||||
Screen::Create(Dimension::Fit(document), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
std::cout << std::endl;
|
||||
}
|
||||
28
ftxui/examples/dom/border_style.cpp
Normal file
28
ftxui/examples/dom/border_style.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
// 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.
|
||||
#include <ftxui/dom/elements.hpp> // for operator|, text, Element, Fit, borderDouble, borderHeavy, borderLight, borderRounded, vbox
|
||||
#include <ftxui/screen/screen.hpp> // for Screen
|
||||
#include <iostream> // for endl, cout, ostream
|
||||
#include <memory> // for allocator
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
|
||||
auto document = vbox({
|
||||
text("borderLight") | borderLight,
|
||||
text("borderDashed") | borderDashed,
|
||||
text("borderHeavy") | borderHeavy,
|
||||
text("borderDouble") | borderDouble,
|
||||
text("borderRounded") | borderRounded,
|
||||
});
|
||||
|
||||
auto screen =
|
||||
Screen::Create(Dimension::Fit(document), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
std::cout << std::endl;
|
||||
}
|
||||
50
ftxui/examples/dom/canvas.cpp
Normal file
50
ftxui/examples/dom/canvas.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
// 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.
|
||||
#include <stdio.h> // for getchar
|
||||
#include <cmath> // for cos
|
||||
#include <ftxui/dom/elements.hpp> // for Fit, canvas, operator|, border, Element
|
||||
#include <ftxui/screen/screen.hpp> // for Pixel, Screen
|
||||
#include <vector> // for vector, allocator
|
||||
|
||||
#include "ftxui/dom/canvas.hpp" // for Canvas
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::Red, Color::Blue, Color::Green, ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
|
||||
auto c = Canvas(100, 100);
|
||||
|
||||
c.DrawText(0, 0, "This is a canvas", [](Pixel& p) {
|
||||
p.foreground_color = Color::Red;
|
||||
p.underlined = true;
|
||||
});
|
||||
|
||||
// Triangle:
|
||||
c.DrawPointLine(10, 10, 80, 10, Color::Red);
|
||||
c.DrawPointLine(80, 10, 80, 40, Color::Blue);
|
||||
c.DrawPointLine(80, 40, 10, 10, Color::Green);
|
||||
|
||||
// Circle, not filled and filled:
|
||||
c.DrawPointCircle(30, 50, 20);
|
||||
c.DrawPointCircleFilled(40, 40, 10);
|
||||
|
||||
// Plot a function:
|
||||
std::vector<int> ys(100);
|
||||
for (int x = 0; x < 100; x++) {
|
||||
ys[x] = int(80 + 20 * cos(x * 0.2));
|
||||
}
|
||||
for (int x = 0; x < 99; x++) {
|
||||
c.DrawPointLine(x, ys[x], x + 1, ys[x + 1], Color::Red);
|
||||
}
|
||||
|
||||
auto document = canvas(&c) | border;
|
||||
|
||||
auto screen = Screen::Create(Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
getchar();
|
||||
|
||||
return 0;
|
||||
}
|
||||
141
ftxui/examples/dom/color_gallery.cpp
Normal file
141
ftxui/examples/dom/color_gallery.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
// 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.
|
||||
#include <ftxui/screen/color_info.hpp> // for ColorInfo
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <ftxui/screen/terminal.hpp> // for ColorSupport, Color, Palette16, Palette256, TrueColor
|
||||
#include <memory> // for allocator, shared_ptr
|
||||
#include <utility> // for move
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/dom/elements.hpp" // for text, bgcolor, color, vbox, hbox, separator, operator|, Elements, Element, Fit, border
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::Black, Color::Blue, Color::BlueLight, Color::Cyan, Color::CyanLight, Color::Default, Color::GrayDark, Color::GrayLight, Color::Green, Color::GreenLight, Color::Magenta, Color::MagentaLight, Color::Red, Color::RedLight, Color::White, Color::Yellow, Color::YellowLight, Color::Palette256, ftxui
|
||||
|
||||
using namespace ftxui;
|
||||
#include "./color_info_sorted_2d.ipp" // for ColorInfoSorted2D
|
||||
|
||||
int main() {
|
||||
// clang-format off
|
||||
auto basic_color_display =
|
||||
vbox(
|
||||
text("16 color palette:"),
|
||||
separator(),
|
||||
hbox(
|
||||
vbox(
|
||||
color(Color::Default, text("Default")),
|
||||
color(Color::Black, text("Black")),
|
||||
color(Color::GrayDark, text("GrayDark")),
|
||||
color(Color::GrayLight, text("GrayLight")),
|
||||
color(Color::White, text("White")),
|
||||
color(Color::Blue, text("Blue")),
|
||||
color(Color::BlueLight, text("BlueLight")),
|
||||
color(Color::Cyan, text("Cyan")),
|
||||
color(Color::CyanLight, text("CyanLight")),
|
||||
color(Color::Green, text("Green")),
|
||||
color(Color::GreenLight, text("GreenLight")),
|
||||
color(Color::Magenta, text("Magenta")),
|
||||
color(Color::MagentaLight, text("MagentaLight")),
|
||||
color(Color::Red, text("Red")),
|
||||
color(Color::RedLight, text("RedLight")),
|
||||
color(Color::Yellow, text("Yellow")),
|
||||
color(Color::YellowLight, text("YellowLight"))
|
||||
),
|
||||
vbox(
|
||||
bgcolor(Color::Default, text("Default")),
|
||||
bgcolor(Color::Black, text("Black")),
|
||||
bgcolor(Color::GrayDark, text("GrayDark")),
|
||||
bgcolor(Color::GrayLight, text("GrayLight")),
|
||||
bgcolor(Color::White, text("White")),
|
||||
bgcolor(Color::Blue, text("Blue")),
|
||||
bgcolor(Color::BlueLight, text("BlueLight")),
|
||||
bgcolor(Color::Cyan, text("Cyan")),
|
||||
bgcolor(Color::CyanLight, text("CyanLight")),
|
||||
bgcolor(Color::Green, text("Green")),
|
||||
bgcolor(Color::GreenLight, text("GreenLight")),
|
||||
bgcolor(Color::Magenta, text("Magenta")),
|
||||
bgcolor(Color::MagentaLight, text("MagentaLight")),
|
||||
bgcolor(Color::Red, text("Red")),
|
||||
bgcolor(Color::RedLight, text("RedLight")),
|
||||
bgcolor(Color::Yellow, text("Yellow")),
|
||||
bgcolor(Color::YellowLight, text("YellowLight"))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// clang-format on
|
||||
auto palette_256_color_display = text("256 colors palette:");
|
||||
{
|
||||
std::vector<std::vector<ColorInfo>> info_columns = ColorInfoSorted2D();
|
||||
Elements columns;
|
||||
for (auto& column : info_columns) {
|
||||
Elements column_elements;
|
||||
for (auto& it : column) {
|
||||
column_elements.push_back(
|
||||
text(" ") | bgcolor(Color(Color::Palette256(it.index_256))));
|
||||
}
|
||||
columns.push_back(hbox(std::move(column_elements)));
|
||||
}
|
||||
palette_256_color_display = vbox({
|
||||
palette_256_color_display,
|
||||
separator(),
|
||||
vbox(columns),
|
||||
});
|
||||
}
|
||||
|
||||
// True color display.
|
||||
auto true_color_display = text("TrueColors: 24bits:");
|
||||
{
|
||||
const int max_value = 255;
|
||||
const int value_increment = 8;
|
||||
const int hue_increment = 6;
|
||||
int saturation = max_value;
|
||||
Elements array;
|
||||
for (int value = 0; value < max_value; value += 2 * value_increment) {
|
||||
Elements line;
|
||||
for (int hue = 0; hue < max_value; hue += hue_increment) {
|
||||
line.push_back(
|
||||
text("▀") //
|
||||
| color(Color::HSV(hue, saturation, value)) //
|
||||
| bgcolor(Color::HSV(hue, saturation, value + value_increment)));
|
||||
}
|
||||
array.push_back(hbox(std::move(line)));
|
||||
}
|
||||
true_color_display = vbox({
|
||||
true_color_display,
|
||||
separator(),
|
||||
vbox(std::move(array)),
|
||||
});
|
||||
}
|
||||
|
||||
auto terminal_info =
|
||||
vbox({
|
||||
Terminal::ColorSupport() >= Terminal::Color::Palette16
|
||||
? text(" 16 color palette support : Yes")
|
||||
: text(" 16 color palette support : No"),
|
||||
Terminal::ColorSupport() >= Terminal::Color::Palette256
|
||||
? text("256 color palette support : Yes")
|
||||
: text("256 color palette support : No"),
|
||||
Terminal::ColorSupport() >= Terminal::Color::TrueColor
|
||||
? text(" True color support : Yes")
|
||||
: text(" True color support : No"),
|
||||
}) |
|
||||
border;
|
||||
|
||||
auto document = vbox({hbox({
|
||||
basic_color_display,
|
||||
text(" "),
|
||||
palette_256_color_display,
|
||||
text(" "),
|
||||
true_color_display,
|
||||
}),
|
||||
terminal_info});
|
||||
// clang-format on
|
||||
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
|
||||
screen.Print();
|
||||
|
||||
return 0;
|
||||
}
|
||||
39
ftxui/examples/dom/color_info_palette256.cpp
Normal file
39
ftxui/examples/dom/color_info_palette256.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// 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.
|
||||
#include <ftxui/dom/elements.hpp> // for text, bgcolor, hbox, operator|, Elements, Fit, vbox, Element
|
||||
#include <ftxui/screen/color_info.hpp> // for ColorInfo
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <utility> // for move
|
||||
#include <vector> // for vector, allocator
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::Palette256, ftxui
|
||||
|
||||
using namespace ftxui;
|
||||
#include "./color_info_sorted_2d.ipp" // for ColorInfoSorted2D
|
||||
|
||||
int main() {
|
||||
std::vector<std::vector<ColorInfo>> info_columns = ColorInfoSorted2D();
|
||||
|
||||
// Draw every columns
|
||||
Elements columns_elements;
|
||||
for (auto& column : info_columns) {
|
||||
Elements column_elements;
|
||||
for (auto& it : column) {
|
||||
column_elements.push_back(hbox({
|
||||
text(" ") | bgcolor(Color(Color::Palette256(it.index_256))),
|
||||
text(it.name),
|
||||
}));
|
||||
}
|
||||
columns_elements.push_back(vbox(std::move(column_elements)));
|
||||
}
|
||||
auto document = hbox(std::move(columns_elements));
|
||||
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
|
||||
screen.Print();
|
||||
|
||||
return 0;
|
||||
}
|
||||
53
ftxui/examples/dom/color_info_sorted_2d.ipp
Normal file
53
ftxui/examples/dom/color_info_sorted_2d.ipp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <ftxui/screen/color_info.hpp> // for ftxui::ColorInfo
|
||||
|
||||
std::vector<std::vector<ftxui::ColorInfo>> ColorInfoSorted2D() {
|
||||
// Acquire the color information for the palette256.
|
||||
std::vector<ftxui::ColorInfo> info_gray;
|
||||
std::vector<ftxui::ColorInfo> info_color;
|
||||
for (int i = 16; i < 256; ++i) {
|
||||
ftxui::ColorInfo info = GetColorInfo(ftxui::Color::Palette256(i));
|
||||
if (info.saturation == 0)
|
||||
info_gray.push_back(info);
|
||||
else
|
||||
info_color.push_back(info);
|
||||
}
|
||||
|
||||
// Sort info_color by hue.
|
||||
std::sort(
|
||||
info_color.begin(), info_color.end(),
|
||||
[](const ftxui::ColorInfo& A, const ftxui::ColorInfo& B) { return A.hue < B.hue; });
|
||||
|
||||
// Make 8 colums, one gray and seven colored.
|
||||
std::vector<std::vector<ftxui::ColorInfo>> info_columns(8);
|
||||
info_columns[0] = info_gray;
|
||||
for (size_t i = 0; i < info_color.size(); ++i) {
|
||||
info_columns[1 + 7 * i / info_color.size()].push_back(info_color[i]);
|
||||
}
|
||||
|
||||
// Minimize discontinuities for every columns.
|
||||
for (auto& column : info_columns) {
|
||||
std::sort(column.begin(), column.end(),
|
||||
[](const ftxui::ColorInfo& A, const ftxui::ColorInfo& B) {
|
||||
return A.value < B.value;
|
||||
});
|
||||
for (int i = 0; i < int(column.size()) - 1; ++i) {
|
||||
int best_index = i + 1;
|
||||
int best_distance = 255 * 255 * 3;
|
||||
for (int j = i + 1; j < column.size(); ++j) {
|
||||
int dx = column[i].red - column[j].red;
|
||||
int dy = column[i].green - column[j].green;
|
||||
int dz = column[i].blue - column[j].blue;
|
||||
int distance = dx * dx + dy * dy + dz * dz;
|
||||
if (best_distance > distance) {
|
||||
best_distance = distance;
|
||||
best_index = j;
|
||||
}
|
||||
}
|
||||
std::swap(column[i + 1], column[best_index]);
|
||||
}
|
||||
}
|
||||
|
||||
return std::move(info_columns);
|
||||
}
|
||||
35
ftxui/examples/dom/color_truecolor_HSV.cpp
Normal file
35
ftxui/examples/dom/color_truecolor_HSV.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
// 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.
|
||||
#include <ftxui/dom/elements.hpp> // for operator|, Elements, Fit, bgcolor, color, hbox, text, vbox, Element
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <memory> // for allocator
|
||||
#include <utility> // for move
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for Color, ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
|
||||
int saturation = 255;
|
||||
Elements array;
|
||||
for (int value = 0; value < 255; value += 20) {
|
||||
Elements line;
|
||||
for (int hue = 0; hue < 255; hue += 2) {
|
||||
line.push_back(text("▀") //
|
||||
| color(Color::HSV(hue, saturation, value)) //
|
||||
| bgcolor(Color::HSV(hue, saturation, value + 10)));
|
||||
}
|
||||
array.push_back(hbox(std::move(line)));
|
||||
}
|
||||
|
||||
auto document = vbox(std::move(array));
|
||||
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
|
||||
screen.Print();
|
||||
|
||||
return 0;
|
||||
}
|
||||
53
ftxui/examples/dom/color_truecolor_RGB.cpp
Normal file
53
ftxui/examples/dom/color_truecolor_RGB.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
// 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.
|
||||
#include <ftxui/dom/elements.hpp> // for hbox, text, bgcolor, operator|, vbox, Elements, window, Element, Fit
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <memory> // for allocator
|
||||
#include <utility> // for move
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for Color, ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
|
||||
Elements red_line;
|
||||
Elements green_line;
|
||||
Elements blue_line;
|
||||
Elements cyan_line;
|
||||
Elements magenta_line;
|
||||
Elements yellow_line;
|
||||
|
||||
for (int value = 0; value < 255; value += 3) {
|
||||
int v = value * value / 255;
|
||||
red_line.push_back(text(" ") | bgcolor(Color::RGB(v, 0, 0)));
|
||||
green_line.push_back(text(" ") | bgcolor(Color::RGB(0, v, 0)));
|
||||
blue_line.push_back(text(" ") | bgcolor(Color::RGB(0, 0, v)));
|
||||
cyan_line.push_back(text(" ") | bgcolor(Color::RGB(0, v, v)));
|
||||
magenta_line.push_back(text(" ") | bgcolor(Color::RGB(v, 0, v)));
|
||||
yellow_line.push_back(text(" ") | bgcolor(Color::RGB(v, v, 0)));
|
||||
}
|
||||
|
||||
auto document = vbox({
|
||||
window(text("Primary colors"),
|
||||
vbox({
|
||||
hbox({text("Red line :"), hbox(std::move(red_line))}),
|
||||
hbox({text("Green line :"), hbox(std::move(green_line))}),
|
||||
hbox({text("Blue line :"), hbox(std::move(blue_line))}),
|
||||
})),
|
||||
window(text("Secondary colors"),
|
||||
vbox({
|
||||
hbox({text("cyan line :"), hbox(std::move(cyan_line))}),
|
||||
hbox({text("magenta line:"), hbox(std::move(magenta_line))}),
|
||||
hbox({text("Yellow line :"), hbox(std::move(yellow_line))}),
|
||||
})),
|
||||
});
|
||||
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
|
||||
screen.Print();
|
||||
|
||||
return 0;
|
||||
}
|
||||
29
ftxui/examples/dom/dbox.cpp
Normal file
29
ftxui/examples/dom/dbox.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
// 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.
|
||||
#include <ftxui/dom/elements.hpp> // for text, operator|, border, Element, vbox, center, Fit, dbox
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <memory> // for allocator
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto document = dbox({
|
||||
vbox({
|
||||
text("line_1"),
|
||||
text("line_2"),
|
||||
text("line_3"),
|
||||
text("line_4"),
|
||||
text("line_5"),
|
||||
}) | border,
|
||||
text("overlay") | border | center,
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
|
||||
screen.Print();
|
||||
|
||||
return 0;
|
||||
}
|
||||
36
ftxui/examples/dom/gauge.cpp
Normal file
36
ftxui/examples/dom/gauge.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
// 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.
|
||||
#include <chrono> // for operator""s, chrono_literals
|
||||
#include <ftxui/dom/elements.hpp> // for text, gauge, operator|, flex, hbox, Element
|
||||
#include <ftxui/screen/screen.hpp> // for Screen
|
||||
#include <iostream> // for cout, endl, ostream
|
||||
#include <string> // for allocator, char_traits, operator+, operator<<, string, to_string, basic_string
|
||||
#include <thread> // for sleep_for
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
std::string reset_position;
|
||||
for (float percentage = 0.0f; percentage <= 1.0f; percentage += 0.002f) {
|
||||
std::string data_downloaded =
|
||||
std::to_string(int(percentage * 5000)) + "/5000";
|
||||
auto document = hbox({
|
||||
text("downloading:"),
|
||||
gauge(percentage) | flex,
|
||||
text(" " + data_downloaded),
|
||||
});
|
||||
auto screen = Screen(100, 1);
|
||||
Render(screen, document);
|
||||
std::cout << reset_position;
|
||||
screen.Print();
|
||||
reset_position = screen.ResetPosition();
|
||||
|
||||
std::this_thread::sleep_for(0.01s);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
78
ftxui/examples/dom/gauge_direction.cpp
Normal file
78
ftxui/examples/dom/gauge_direction.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
// Copyright 2022 Arthur Sonzogni. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSE file.
|
||||
#include <chrono> // for operator""s, chrono_literals
|
||||
#include <ftxui/dom/elements.hpp> // for filler, operator|, separator, text, border, Element, vbox, vtext, hbox, center, gaugeDown, gaugeLeft, gaugeRight, gaugeUp
|
||||
#include <ftxui/screen/screen.hpp> // for Screen
|
||||
#include <iostream> // for cout, endl, ostream
|
||||
#include <string> // for allocator, operator+, operator<<, string, to_string
|
||||
#include <thread> // for sleep_for
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
std::string reset_position;
|
||||
for (float percentage = 0.0f; percentage <= 1.0f; percentage += 0.002f) {
|
||||
std::string data_downloaded =
|
||||
std::to_string(int(percentage * 5000)) + "/5000";
|
||||
|
||||
auto gauge_up = //
|
||||
hbox({
|
||||
vtext("gauge vertical"),
|
||||
separator(),
|
||||
gaugeUp(percentage),
|
||||
}) |
|
||||
border;
|
||||
|
||||
auto gauge_down = //
|
||||
hbox({
|
||||
vtext("gauge vertical"),
|
||||
separator(),
|
||||
gaugeDown(percentage),
|
||||
}) |
|
||||
border;
|
||||
|
||||
auto gauge_right = //
|
||||
vbox({
|
||||
text("gauge horizontal"),
|
||||
separator(),
|
||||
gaugeRight(percentage),
|
||||
}) |
|
||||
border;
|
||||
|
||||
auto gauge_left = //
|
||||
vbox({
|
||||
text("gauge horizontal"),
|
||||
separator(),
|
||||
gaugeLeft(percentage),
|
||||
}) |
|
||||
border;
|
||||
|
||||
auto document = hbox({
|
||||
gauge_up,
|
||||
filler(),
|
||||
vbox({
|
||||
gauge_right,
|
||||
filler(),
|
||||
text(data_downloaded) | border | center,
|
||||
filler(),
|
||||
gauge_left,
|
||||
}),
|
||||
filler(),
|
||||
gauge_down,
|
||||
});
|
||||
|
||||
auto screen = Screen(32, 16);
|
||||
Render(screen, document);
|
||||
std::cout << reset_position;
|
||||
screen.Print();
|
||||
reset_position = screen.ResetPosition();
|
||||
|
||||
std::this_thread::sleep_for(0.01s);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
87
ftxui/examples/dom/graph.cpp
Normal file
87
ftxui/examples/dom/graph.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
// 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.
|
||||
#include <chrono> // for operator""s, chrono_literals
|
||||
#include <cmath> // for sin
|
||||
#include <ftxui/dom/elements.hpp> // for graph, operator|, separator, color, Element, vbox, flex, inverted, operator|=, Fit, hbox, size, border, GREATER_THAN, HEIGHT
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <functional> // for ref, reference_wrapper
|
||||
#include <iostream> // for cout, ostream
|
||||
#include <memory> // for shared_ptr
|
||||
#include <string> // for operator<<, string
|
||||
#include <thread> // for sleep_for
|
||||
#include <utility> // for ignore
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::BlueLight, Color::RedLight, Color::YellowLight, ftxui
|
||||
|
||||
class Graph {
|
||||
public:
|
||||
std::vector<int> operator()(int width, int height) const {
|
||||
std::vector<int> output(width);
|
||||
for (int i = 0; i < width; ++i) {
|
||||
float v = 0;
|
||||
v += 0.1f * sin((i + shift) * 0.1f); // NOLINT
|
||||
v += 0.2f * sin((i + shift + 10) * 0.15f); // NOLINT
|
||||
v += 0.1f * sin((i + shift) * 0.03f); // NOLINT
|
||||
v *= height; // NOLINT
|
||||
v += 0.5f * height; // NOLINT
|
||||
output[i] = static_cast<int>(v);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
int shift = 0;
|
||||
};
|
||||
|
||||
std::vector<int> triangle(int width, int height) {
|
||||
std::vector<int> output(width);
|
||||
for (int i = 0; i < width; ++i) {
|
||||
output[i] = i % (height - 4) + 2;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
Graph my_graph;
|
||||
|
||||
std::string reset_position;
|
||||
for (int i = 0;; ++i) {
|
||||
std::ignore = i;
|
||||
auto document = hbox({
|
||||
vbox({
|
||||
graph(std::ref(my_graph)),
|
||||
separator(),
|
||||
graph(triangle) | inverted,
|
||||
}) | flex,
|
||||
separator(),
|
||||
vbox({
|
||||
graph(std::ref(my_graph)) | color(Color::BlueLight),
|
||||
separator(),
|
||||
graph(std::ref(my_graph)) | color(Color::RedLight),
|
||||
separator(),
|
||||
graph(std::ref(my_graph)) | color(Color::YellowLight),
|
||||
}) | flex,
|
||||
});
|
||||
|
||||
document |= border;
|
||||
|
||||
const int min_width = 40;
|
||||
document |= size(HEIGHT, GREATER_THAN, min_width);
|
||||
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
std::cout << reset_position;
|
||||
screen.Print();
|
||||
reset_position = screen.ResetPosition();
|
||||
|
||||
const auto sleep_time = 0.03s;
|
||||
std::this_thread::sleep_for(sleep_time);
|
||||
my_graph.shift++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
48
ftxui/examples/dom/gridbox.cpp
Normal file
48
ftxui/examples/dom/gridbox.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright 2021 Arthur Sonzogni. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSE file.
|
||||
#include <stdio.h> // for getchar
|
||||
#include <ftxui/dom/elements.hpp> // for Elements, gridbox, Fit, operator|, text, border, Element
|
||||
#include <ftxui/screen/screen.hpp> // for Screen
|
||||
#include <memory> // for allocator, shared_ptr
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto cell = [](const char* t) { return text(t) | border; };
|
||||
auto document = //
|
||||
gridbox({
|
||||
{
|
||||
cell("north-west"),
|
||||
cell("north"),
|
||||
cell("north-east"),
|
||||
},
|
||||
{
|
||||
cell("center-west"),
|
||||
gridbox({
|
||||
{
|
||||
cell("center-north-west"),
|
||||
cell("center-north-east"),
|
||||
},
|
||||
{
|
||||
cell("center-south-west"),
|
||||
cell("center-south-east"),
|
||||
},
|
||||
}),
|
||||
cell("center-east"),
|
||||
},
|
||||
{
|
||||
cell("south-west"),
|
||||
cell("south"),
|
||||
cell("south-east"),
|
||||
},
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
getchar();
|
||||
|
||||
return 0;
|
||||
}
|
||||
52
ftxui/examples/dom/hflow.cpp
Normal file
52
ftxui/examples/dom/hflow.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
// 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.
|
||||
#include <stdio.h> // for getchar
|
||||
#include <ftxui/dom/elements.hpp> // for operator|, size, Element, text, hcenter, Decorator, Fit, WIDTH, hflow, window, EQUAL, GREATER_THAN, HEIGHT, bold, border, dim, LESS_THAN
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <string> // for allocator, char_traits, operator+, to_string, string
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto make_box = [](int dimx, int dimy) {
|
||||
std::string title = std::to_string(dimx) + "x" + std::to_string(dimy);
|
||||
return window(text(title) | hcenter | bold,
|
||||
text("content") | hcenter | dim) |
|
||||
size(WIDTH, EQUAL, dimx) | size(HEIGHT, EQUAL, dimy);
|
||||
};
|
||||
|
||||
auto style = size(WIDTH, GREATER_THAN, 20) | border |
|
||||
size(HEIGHT, GREATER_THAN, 30) | size(WIDTH, LESS_THAN, 50);
|
||||
|
||||
auto document = hflow({
|
||||
make_box(7, 7),
|
||||
make_box(7, 5),
|
||||
make_box(5, 7),
|
||||
make_box(10, 4),
|
||||
make_box(10, 4),
|
||||
make_box(10, 4),
|
||||
make_box(10, 4),
|
||||
make_box(11, 4),
|
||||
make_box(11, 4),
|
||||
make_box(11, 4),
|
||||
make_box(11, 4),
|
||||
make_box(12, 4),
|
||||
make_box(12, 5),
|
||||
make_box(12, 4),
|
||||
make_box(13, 4),
|
||||
make_box(13, 3),
|
||||
make_box(13, 3),
|
||||
make_box(10, 3),
|
||||
}) |
|
||||
style;
|
||||
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
getchar();
|
||||
|
||||
return 0;
|
||||
}
|
||||
59
ftxui/examples/dom/html_like.cpp
Normal file
59
ftxui/examples/dom/html_like.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
// 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.
|
||||
#include <chrono> // for operator""s, chrono_literals
|
||||
#include <ftxui/screen/screen.hpp> // for Screen
|
||||
#include <iostream> // for cout, ostream
|
||||
#include <string> // for allocator, operator<<, string
|
||||
#include <thread> // for sleep_for
|
||||
|
||||
#include "ftxui/dom/elements.hpp" // for paragraph, text, operator|, Element, border, Fit, color, hflow, spinner, vbox, bold, dim, underlined
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/box.hpp" // for ftxui
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::Red
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
auto img1 = []() { return text("img") | border; };
|
||||
auto img2 = []() { return vbox({text("big"), text("image")}) | border; };
|
||||
|
||||
std::string reset_position;
|
||||
for (int i = 0;; ++i) {
|
||||
auto document = //
|
||||
hflow(
|
||||
paragraph("Hello world! Here is an image:"), img1(),
|
||||
paragraph(" Here is a text "), text("underlined ") | underlined,
|
||||
paragraph(" Here is a text "), text("bold ") | bold,
|
||||
paragraph("Hello world! Here is an image:"), img2(),
|
||||
paragraph(
|
||||
"Le Lorem Ipsum est simplement du faux texte employé dans la "
|
||||
"composition et la mise en page avant impression. Le Lorem "
|
||||
"Ipsum est le faux texte standard de l'imprimerie depuis les "
|
||||
"années 1500, quand un imprimeur anonyme assembla ensemble "
|
||||
"des morceaux de texte pour réaliser un livre spécimen de "
|
||||
"polices de texte. Il n'a pas fait que survivre cinq siècles, "
|
||||
"mais s'est aussi adapté à la bureautique informatique, sans "
|
||||
"que son contenu n'en soit modifié. Il a été popularisé dans "
|
||||
"les années 1960 grâce à la vente de feuilles Letraset "
|
||||
"contenant des passages du Lorem Ipsum, et, plus récemment, "
|
||||
"par son inclusion dans des applications de mise en page de "
|
||||
"texte, comme Aldus PageMaker."),
|
||||
paragraph(" Here is a text "), text("dim ") | dim,
|
||||
paragraph("Hello world! Here is an image:"), img1(),
|
||||
paragraph(" Here is a text "), text("red ") | color(Color::Red),
|
||||
paragraph(" A spinner "), spinner(6, i / 10)) |
|
||||
border;
|
||||
|
||||
auto screen = Screen::Create(Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
std::cout << reset_position;
|
||||
screen.Print();
|
||||
reset_position = screen.ResetPosition();
|
||||
|
||||
std::this_thread::sleep_for(0.01s);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
25
ftxui/examples/dom/linear_gradient.cpp
Normal file
25
ftxui/examples/dom/linear_gradient.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
// 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.
|
||||
#include <ftxui/dom/elements.hpp> // for bgcolor, operator|, operator|=, text, center, Element
|
||||
#include <ftxui/dom/linear_gradient.hpp> // for LinearGradient::Stop, LinearGradient
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <memory> // for allocator, shared_ptr
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::DeepPink1, Color::DeepSkyBlue1, Color::Yellow, ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto document = text("gradient") | center;
|
||||
|
||||
document |= bgcolor(LinearGradient()
|
||||
.Angle(45)
|
||||
.Stop(Color::DeepPink1)
|
||||
.Stop(Color::DeepSkyBlue1));
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Full());
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
|
||||
return 0;
|
||||
}
|
||||
150
ftxui/examples/dom/package_manager.cpp
Normal file
150
ftxui/examples/dom/package_manager.cpp
Normal file
@@ -0,0 +1,150 @@
|
||||
// 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.
|
||||
#include <chrono> // for operator""s, chrono_literals
|
||||
#include <ftxui/dom/elements.hpp> // for operator|, text, Element, hbox, bold, color, filler, separator, vbox, window, gauge, Fit, size, dim, EQUAL, WIDTH
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <iostream> // for cout, endl, ostream
|
||||
#include <list> // for list, operator==, _List_iterator, _List_iterator<>::_Self
|
||||
#include <memory> // for allocator, shared_ptr, allocator_traits<>::value_type
|
||||
#include <string> // for string, operator<<, to_string
|
||||
#include <thread> // for sleep_for
|
||||
#include <utility> // for move
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::Green, Color::Red, Color::RedLight, ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
|
||||
struct Task {
|
||||
std::string name;
|
||||
int number_of_threads;
|
||||
int downloaded;
|
||||
int size;
|
||||
};
|
||||
|
||||
std::list<Task> remaining_tasks = {
|
||||
{"contact server ", 10, 0, 6 * 25},
|
||||
{"download index.html ", 10, 0, 9 * 25},
|
||||
{"download script.js ", 1, 0, 3 * 25},
|
||||
{"download style.js ", 1, 0, 4 * 25},
|
||||
{"download image.png ", 1, 0, 5 * 25},
|
||||
{"download big_1.png ", 1, 0, 30 * 25},
|
||||
{"download icon_1.png ", 1, 0, 7 * 25},
|
||||
{"download icon_2.png ", 1, 0, 8 * 25},
|
||||
{"download big_2.png ", 1, 0, 30 * 25},
|
||||
{"download small_1.png ", 1, 0, 10 * 25},
|
||||
{"download small_2.png ", 1, 0, 11 * 25},
|
||||
{"download small_3.png ", 1, 0, 12 * 25},
|
||||
};
|
||||
|
||||
std::list<Task> displayed_task;
|
||||
|
||||
int remaining_threads = 12;
|
||||
|
||||
int nb_queued = (int)remaining_tasks.size();
|
||||
int nb_active = 0;
|
||||
int nb_done = 0;
|
||||
|
||||
auto to_text = [](int number) {
|
||||
return text(std::to_string(number)) | size(WIDTH, EQUAL, 3);
|
||||
};
|
||||
|
||||
auto renderTask = [&](const Task& task) {
|
||||
auto style = (task.downloaded == task.size) ? dim : bold;
|
||||
return hbox({
|
||||
text(task.name) | style,
|
||||
separator(),
|
||||
to_text(task.downloaded),
|
||||
text("/"),
|
||||
to_text(task.size),
|
||||
separator(),
|
||||
gauge(task.downloaded / float(task.size)),
|
||||
});
|
||||
};
|
||||
|
||||
auto renderSummary = [&]() {
|
||||
auto summary = vbox({
|
||||
hbox({
|
||||
text("- done: "),
|
||||
to_text(nb_done) | bold,
|
||||
}) | color(Color::Green),
|
||||
hbox({
|
||||
text("- active: "),
|
||||
to_text(nb_active) | bold,
|
||||
}) | color(Color::RedLight),
|
||||
hbox({
|
||||
text("- queue: "),
|
||||
to_text(nb_queued) | bold,
|
||||
}) | color(Color::Red),
|
||||
});
|
||||
|
||||
return window(text(" Summary "), summary);
|
||||
};
|
||||
|
||||
auto render = [&]() {
|
||||
std::vector<Element> entries;
|
||||
for (auto& task : displayed_task) {
|
||||
entries.push_back(renderTask(task));
|
||||
}
|
||||
|
||||
return vbox({
|
||||
// List of tasks.
|
||||
window(text(" Task "), vbox(std::move(entries))),
|
||||
|
||||
// Summary.
|
||||
hbox({
|
||||
renderSummary(),
|
||||
filler(),
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
auto updateModel = [&]() {
|
||||
for (auto& task : displayed_task) {
|
||||
if (task.downloaded != task.size) {
|
||||
task.downloaded++;
|
||||
} else if (task.number_of_threads) {
|
||||
remaining_threads += task.number_of_threads;
|
||||
task.number_of_threads = 0;
|
||||
nb_active--;
|
||||
nb_done++;
|
||||
}
|
||||
}
|
||||
|
||||
if (remaining_tasks.size() &&
|
||||
remaining_tasks.front().number_of_threads <= remaining_threads) {
|
||||
remaining_threads -= remaining_tasks.front().number_of_threads;
|
||||
displayed_task.push_back(remaining_tasks.front());
|
||||
remaining_tasks.pop_front();
|
||||
nb_queued--;
|
||||
nb_active++;
|
||||
}
|
||||
};
|
||||
|
||||
std::string reset_position;
|
||||
for (;;) {
|
||||
// Draw.
|
||||
auto document = render();
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
std::cout << reset_position;
|
||||
screen.Print();
|
||||
reset_position = screen.ResetPosition();
|
||||
|
||||
// Simulate time.
|
||||
using namespace std::chrono_literals;
|
||||
std::this_thread::sleep_for(0.01s);
|
||||
|
||||
// Exit
|
||||
if (nb_active + nb_queued == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Update the model for the next frame.
|
||||
updateModel();
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
53
ftxui/examples/dom/paragraph.cpp
Normal file
53
ftxui/examples/dom/paragraph.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
// 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.
|
||||
#include <chrono> // for operator""s, chrono_literals
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <iostream> // for cout, ostream
|
||||
#include <memory> // for allocator, shared_ptr
|
||||
#include <string> // for string, operator<<
|
||||
#include <thread> // for sleep_for
|
||||
|
||||
#include "ftxui/dom/elements.hpp" // for hflow, paragraph, separator, hbox, vbox, filler, operator|, border, Element
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/box.hpp" // for ftxui
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
std::string p =
|
||||
R"(In probability theory and statistics, Bayes' theorem (alternatively Bayes' law or Bayes' rule) describes the probability of an event, based on prior knowledge of conditions that might be related to the event. For example, if cancer is related to age, then, using Bayes' theorem, a person's age can be used to more accurately assess the probability that they have cancer, compared to the assessment of the probability of cancer made without knowledge of the person's age. One of the many applications of Bayes' theorem is Bayesian inference, a particular approach to statistical inference. When applied, the probabilities involved in Bayes' theorem may have different probability interpretations. With the Bayesian probability interpretation the theorem expresses how a subjective degree of belief should rationally change to account for availability of related evidence. Bayesian inference is fundamental to Bayesian statistics.)";
|
||||
|
||||
std::string reset_position;
|
||||
while (true) {
|
||||
auto document = vbox({
|
||||
hflow(paragraph(p)),
|
||||
separator(),
|
||||
hflow(paragraph(p)),
|
||||
separator(),
|
||||
hbox({
|
||||
hflow(paragraph(p)),
|
||||
separator(),
|
||||
hflow(paragraph(p)),
|
||||
}),
|
||||
}) |
|
||||
border;
|
||||
|
||||
document = vbox(filler(), document);
|
||||
|
||||
// auto screen = Screen::Create(Dimension::Fit(document));
|
||||
// Render(screen, document);
|
||||
// screen.Print();
|
||||
// getchar();
|
||||
|
||||
auto screen = Screen::Create(Dimension::Full());
|
||||
Render(screen, document);
|
||||
std::cout << reset_position;
|
||||
screen.Print();
|
||||
reset_position = screen.ResetPosition();
|
||||
|
||||
std::this_thread::sleep_for(0.01s);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
30
ftxui/examples/dom/separator.cpp
Normal file
30
ftxui/examples/dom/separator.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// 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.
|
||||
#include <ftxui/dom/elements.hpp> // for text, center, separator, operator|, flex, Element, vbox, Fit, hbox, border
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <memory> // for allocator
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto document = hbox({
|
||||
text("left-column"),
|
||||
separator(),
|
||||
vbox({
|
||||
center(text("top")) | flex,
|
||||
separator(),
|
||||
center(text("bottom")),
|
||||
}) | flex,
|
||||
separator(),
|
||||
text("right-column"),
|
||||
}) |
|
||||
border;
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
|
||||
return 0;
|
||||
}
|
||||
46
ftxui/examples/dom/separator_style.cpp
Normal file
46
ftxui/examples/dom/separator_style.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
// 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.
|
||||
#include <ftxui/screen/screen.hpp> // for Screen
|
||||
#include <iostream> // for endl, cout, ostream
|
||||
#include <memory> // for allocator
|
||||
|
||||
#include "ftxui/dom/elements.hpp" // for text, hbox, separatorDouble, separatorHeavy, separatorLight, vbox, operator|, Element, Fit, borderDouble, borderHeavy, borderLight
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/box.hpp" // for ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
|
||||
auto document = vbox({
|
||||
vbox({
|
||||
text("separatorLight"),
|
||||
separatorLight(),
|
||||
hbox(text("left"), separatorLight(), text("right")),
|
||||
}) | borderLight,
|
||||
|
||||
vbox({
|
||||
text("separatorDashed"),
|
||||
separatorDashed(),
|
||||
hbox(text("left"), separatorDashed(), text("right")),
|
||||
}) | borderDashed,
|
||||
|
||||
vbox({
|
||||
text("separatorHeavy"),
|
||||
separatorHeavy(),
|
||||
hbox(text("left"), separatorHeavy(), text("right")),
|
||||
}) | borderHeavy,
|
||||
|
||||
vbox({
|
||||
text("separatorDouble"),
|
||||
separatorDouble(),
|
||||
hbox(text("left"), separatorDouble(), text("right")),
|
||||
}) | borderDouble,
|
||||
});
|
||||
|
||||
auto screen =
|
||||
Screen::Create(Dimension::Fit(document), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
std::cout << std::endl;
|
||||
}
|
||||
31
ftxui/examples/dom/size.cpp
Normal file
31
ftxui/examples/dom/size.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
// 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.
|
||||
#include <ftxui/dom/elements.hpp> // for operator|, text, Element, hcenter, Fit, hbox, size, window, Elements, bold, dim, EQUAL, WIDTH
|
||||
#include <ftxui/screen/screen.hpp> // for Screen
|
||||
#include <memory> // for allocator, shared_ptr
|
||||
#include <string> // for string, to_string
|
||||
#include <utility> // for move
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto make_box = [](const std::string& title) {
|
||||
return window(text(title) | hcenter | bold,
|
||||
text("content") | hcenter | dim);
|
||||
};
|
||||
|
||||
Elements content;
|
||||
for (int x = 3; x < 30; ++x) {
|
||||
content.push_back(make_box(std::to_string(x)) | size(WIDTH, EQUAL, x));
|
||||
}
|
||||
|
||||
auto document = hbox(std::move(content));
|
||||
auto screen = Screen::Create(Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
|
||||
return 0;
|
||||
}
|
||||
47
ftxui/examples/dom/spinner.cpp
Normal file
47
ftxui/examples/dom/spinner.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
// 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.
|
||||
#include <chrono> // for operator""s, chrono_literals
|
||||
#include <ftxui/dom/elements.hpp> // for Element, operator|, separator, filler, hbox, size, spinner, text, vbox, bold, border, Fit, EQUAL, WIDTH
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <iostream> // for cout, endl, ostream
|
||||
#include <string> // for to_string, operator<<, string
|
||||
#include <thread> // for sleep_for
|
||||
#include <utility> // for move
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
std::string reset_position;
|
||||
for (int index = 0; index < 200; ++index) {
|
||||
std::vector<Element> entries;
|
||||
for (int i = 0; i < 23; ++i) {
|
||||
if (i != 0) {
|
||||
entries.push_back(separator());
|
||||
}
|
||||
entries.push_back( //
|
||||
hbox({
|
||||
text(std::to_string(i)) | size(WIDTH, EQUAL, 2),
|
||||
separator(),
|
||||
spinner(i, index) | bold,
|
||||
}));
|
||||
}
|
||||
auto document = hbox({
|
||||
vbox(std::move(entries)) | border,
|
||||
filler(),
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
std::cout << reset_position;
|
||||
screen.Print();
|
||||
reset_position = screen.ResetPosition();
|
||||
|
||||
std::this_thread::sleep_for(0.1s);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
24
ftxui/examples/dom/style_blink.cpp
Normal file
24
ftxui/examples/dom/style_blink.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
// 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.
|
||||
#include <ftxui/dom/elements.hpp> // for text, operator|, blink, Fit, hbox, Element
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <memory> // for allocator
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto document = //
|
||||
hbox({
|
||||
text("This text is "),
|
||||
text("blink") | blink,
|
||||
text(". Do you like it?"),
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
|
||||
return 0;
|
||||
}
|
||||
24
ftxui/examples/dom/style_bold.cpp
Normal file
24
ftxui/examples/dom/style_bold.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
// 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.
|
||||
#include <ftxui/dom/elements.hpp> // for text, operator|, bold, Fit, hbox, Element
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <memory> // for allocator
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto document = //
|
||||
hbox({
|
||||
text("This text is "),
|
||||
text("bold") | bold,
|
||||
text(". Do you like it?"),
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
|
||||
return 0;
|
||||
}
|
||||
67
ftxui/examples/dom/style_color.cpp
Normal file
67
ftxui/examples/dom/style_color.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
// 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.
|
||||
#include <ftxui/dom/linear_gradient.hpp> // for LinearGradient
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <memory> // for allocator
|
||||
|
||||
#include "ftxui/dom/elements.hpp" // for text, bgcolor, color, vbox, filler, Fit, hbox
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for Color, operator""_rgb, Color::Black, Color::Blue, Color::BlueLight, Color::Cyan, Color::CyanLight, Color::DeepSkyBlue4, Color::Default, Color::GrayDark, Color::GrayLight, Color::Green, Color::GreenLight, Color::Magenta, Color::MagentaLight, Color::Red, Color::RedLight, Color::SkyBlue1, Color::White, Color::Yellow, Color::YellowLight, ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto document = hbox({
|
||||
vbox({
|
||||
color(Color::Default, text("Default")),
|
||||
color(Color::Black, text("Black")),
|
||||
color(Color::GrayDark, text("GrayDark")),
|
||||
color(Color::GrayLight, text("GrayLight")),
|
||||
color(Color::White, text("White")),
|
||||
color(Color::Blue, text("Blue")),
|
||||
color(Color::BlueLight, text("BlueLight")),
|
||||
color(Color::Cyan, text("Cyan")),
|
||||
color(Color::CyanLight, text("CyanLight")),
|
||||
color(Color::Green, text("Green")),
|
||||
color(Color::GreenLight, text("GreenLight")),
|
||||
color(Color::Magenta, text("Magenta")),
|
||||
color(Color::MagentaLight, text("MagentaLight")),
|
||||
color(Color::Red, text("Red")),
|
||||
color(Color::RedLight, text("RedLight")),
|
||||
color(Color::Yellow, text("Yellow")),
|
||||
color(Color::YellowLight, text("YellowLight")),
|
||||
color(0x66ff66_rgb, text("Phosphor")),
|
||||
color(LinearGradient(Color::SkyBlue1, Color::DeepSkyBlue4),
|
||||
text("Skyblue to DeepSkyBlue")),
|
||||
}),
|
||||
vbox({
|
||||
bgcolor(Color::Default, text("Default")),
|
||||
bgcolor(Color::Black, text("Black")),
|
||||
bgcolor(Color::GrayDark, text("GrayDark")),
|
||||
bgcolor(Color::GrayLight, text("GrayLight")),
|
||||
bgcolor(Color::White, text("White")),
|
||||
bgcolor(Color::Blue, text("Blue")),
|
||||
bgcolor(Color::BlueLight, text("BlueLight")),
|
||||
bgcolor(Color::Cyan, text("Cyan")),
|
||||
bgcolor(Color::CyanLight, text("CyanLight")),
|
||||
bgcolor(Color::Green, text("Green")),
|
||||
bgcolor(Color::GreenLight, text("GreenLight")),
|
||||
bgcolor(Color::Magenta, text("Magenta")),
|
||||
bgcolor(Color::MagentaLight, text("MagentaLight")),
|
||||
bgcolor(Color::Red, text("Red")),
|
||||
bgcolor(Color::RedLight, text("RedLight")),
|
||||
bgcolor(Color::Yellow, text("Yellow")),
|
||||
bgcolor(Color::YellowLight, text("YellowLight")),
|
||||
bgcolor(0x66ff66_rgb, text("Phosphor")),
|
||||
bgcolor(LinearGradient(Color::SkyBlue1, Color::DeepSkyBlue4),
|
||||
text("Skyblue to DeepSkyBlue")),
|
||||
}),
|
||||
filler(),
|
||||
});
|
||||
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
|
||||
return 0;
|
||||
}
|
||||
24
ftxui/examples/dom/style_dim.cpp
Normal file
24
ftxui/examples/dom/style_dim.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
// 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.
|
||||
#include <ftxui/dom/elements.hpp> // for text, operator|, dim, Fit, hbox, Element
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <memory> // for allocator
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto document = //
|
||||
hbox({
|
||||
text("This text is "),
|
||||
text("dim") | dim,
|
||||
text(". Do you like it?"),
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
|
||||
return 0;
|
||||
}
|
||||
35
ftxui/examples/dom/style_gallery.cpp
Normal file
35
ftxui/examples/dom/style_gallery.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
// 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.
|
||||
#include <ftxui/dom/elements.hpp> // for text, operator|, Element, bgcolor, color, blink, bold, dim, inverted, underlined, Fit, hbox
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <memory> // for allocator
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::Blue, ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
// clang-format off
|
||||
auto document =
|
||||
hbox({
|
||||
text("normal") , text(" ") ,
|
||||
text("bold") | bold , text(" ") ,
|
||||
text("italic") | italic , text(" ") ,
|
||||
text("dim") | dim , text(" ") ,
|
||||
text("inverted") | inverted , text(" ") ,
|
||||
text("underlined") | underlined , text(" ") ,
|
||||
text("underlinedDouble") | underlinedDouble , text(" ") ,
|
||||
text("blink") | blink , text(" ") ,
|
||||
text("strikethrough") | strikethrough , text(" ") ,
|
||||
text("color") | color(Color::Blue) , text(" ") ,
|
||||
text("bgcolor") | bgcolor(Color::Blue) , text(" ") ,
|
||||
text("hyperlink") | hyperlink("https://github.com/ArthurSonzogni/FTXUI"),
|
||||
});
|
||||
// clang-format on
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
|
||||
return 0;
|
||||
}
|
||||
24
ftxui/examples/dom/style_hyperlink.cpp
Normal file
24
ftxui/examples/dom/style_hyperlink.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
// 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.
|
||||
#include <ftxui/dom/elements.hpp> // for text, operator|, bold, Fit, hbox, Element
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <memory> // for allocator
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto document = //
|
||||
hbox({
|
||||
text("This text is an "),
|
||||
text("hyperlink") | hyperlink("https://www.google.com"),
|
||||
text(". Do you like it?"),
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
|
||||
return 0;
|
||||
}
|
||||
23
ftxui/examples/dom/style_inverted.cpp
Normal file
23
ftxui/examples/dom/style_inverted.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
// 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.
|
||||
#include <ftxui/dom/elements.hpp> // for text, operator|, inverted, Fit, hbox, Element
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <memory> // for allocator
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto document = hbox({
|
||||
text("This text is "),
|
||||
text("inverted") | inverted,
|
||||
text(". Do you like it?"),
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
|
||||
return 0;
|
||||
}
|
||||
23
ftxui/examples/dom/style_italic.cpp
Normal file
23
ftxui/examples/dom/style_italic.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
// Copyright 2025 Arthur Sonzogni. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSE file.
|
||||
#include <ftxui/dom/elements.hpp> // for text, operator|, inverted, Fit, hbox, Element
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <memory> // for allocator
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto document = hbox({
|
||||
text("This text is "),
|
||||
text("italic") | italic,
|
||||
text(". Do you like it?"),
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
|
||||
return 0;
|
||||
}
|
||||
24
ftxui/examples/dom/style_strikethrough.cpp
Normal file
24
ftxui/examples/dom/style_strikethrough.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
// 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.
|
||||
#include <ftxui/dom/elements.hpp> // for text, operator|, strikethrough, Fit, hbox, Element
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <memory> // for allocator
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto document = //
|
||||
hbox({
|
||||
text("This text is "),
|
||||
text("strikethrough") | strikethrough,
|
||||
text(". Do you like it?"),
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
|
||||
return 0;
|
||||
}
|
||||
24
ftxui/examples/dom/style_underlined.cpp
Normal file
24
ftxui/examples/dom/style_underlined.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
// 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.
|
||||
#include <ftxui/dom/elements.hpp> // for text, operator|, underlined, Fit, hbox, Element
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <memory> // for allocator
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto document = //
|
||||
hbox({
|
||||
text("This text is "),
|
||||
text("underlined") | underlined,
|
||||
text(". Do you like it?"),
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
|
||||
return 0;
|
||||
}
|
||||
24
ftxui/examples/dom/style_underlined_double.cpp
Normal file
24
ftxui/examples/dom/style_underlined_double.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
// 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.
|
||||
#include <ftxui/dom/elements.hpp> // for text, operator|, underlinedDouble, Fit, hbox, Element
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <memory> // for allocator
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto document = //
|
||||
hbox({
|
||||
text("This text is "),
|
||||
text("underlinedDouble") | underlinedDouble,
|
||||
text(". Do you like it?"),
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
|
||||
return 0;
|
||||
}
|
||||
65
ftxui/examples/dom/table.cpp
Normal file
65
ftxui/examples/dom/table.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
// 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.
|
||||
#include <ftxui/dom/elements.hpp> // for color, Fit, LIGHT, align_right, bold, DOUBLE
|
||||
#include <ftxui/dom/table.hpp> // for Table, TableSelection
|
||||
#include <ftxui/screen/screen.hpp> // for Screen
|
||||
#include <iostream> // for endl, cout, ostream
|
||||
#include <string> // for basic_string, allocator, string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::Blue, Color::Cyan, Color::White, ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
|
||||
auto table = Table({
|
||||
{"Version", "Marketing name", "Release date", "API level", "Runtime"},
|
||||
{"2.3", "Gingerbread", "February 9 2011", "10", "Dalvik 1.4.0"},
|
||||
{"4.0", "Ice Cream Sandwich", "October 19 2011", "15", "Dalvik"},
|
||||
{"4.1", "Jelly Bean", "July 9 2012", "16", "Dalvik"},
|
||||
{"4.2", "Jelly Bean", "November 13 2012", "17", "Dalvik"},
|
||||
{"4.3", "Jelly Bean", "July 24 2013", "18", "Dalvik"},
|
||||
{"4.4", "KitKat", "October 31 2013", "19", "Dalvik and ART"},
|
||||
{"5.0", "Lollipop", "November 3 2014", "21", "ART"},
|
||||
{"5.1", "Lollipop", "March 9 2015", "22", "ART"},
|
||||
{"6.0", "Marshmallow", "October 5 2015", "23", "ART"},
|
||||
{"7.0", "Nougat", "August 22 2016", "24", "ART"},
|
||||
{"7.1", "Nougat", "October 4 2016", "25", "ART"},
|
||||
{"8.0", "Oreo", "August 21 2017", "26", "ART"},
|
||||
{"8.1", "Oreo", "December 5 2017", "27", "ART"},
|
||||
{"9", "Pie", "August 6 2018", "28", "ART"},
|
||||
{"10", "10", "September 3 2019", "29", "ART"},
|
||||
{"11", "11", "September 8 2020", "30", "ART"},
|
||||
});
|
||||
|
||||
table.SelectAll().Border(LIGHT);
|
||||
|
||||
// Add border around the first column.
|
||||
table.SelectColumn(0).Border(LIGHT);
|
||||
|
||||
// Make first row bold with a double border.
|
||||
table.SelectRow(0).Decorate(bold);
|
||||
table.SelectRow(0).SeparatorVertical(LIGHT);
|
||||
table.SelectRow(0).Border(DOUBLE);
|
||||
|
||||
// Align right the "Release date" column.
|
||||
table.SelectColumn(2).DecorateCells(align_right);
|
||||
|
||||
// Select row from the second to the last.
|
||||
auto content = table.SelectRows(1, -1);
|
||||
// Alternate in between 3 colors.
|
||||
content.DecorateCellsAlternateRow(color(Color::Blue), 3, 0);
|
||||
content.DecorateCellsAlternateRow(color(Color::Cyan), 3, 1);
|
||||
content.DecorateCellsAlternateRow(color(Color::White), 3, 2);
|
||||
|
||||
auto document = table.Render();
|
||||
auto screen =
|
||||
Screen::Create(Dimension::Fit(document, /*extend_beyond_screen=*/true));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
std::cout << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
40
ftxui/examples/dom/vbox_hbox.cpp
Normal file
40
ftxui/examples/dom/vbox_hbox.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
// 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.
|
||||
#include <stdio.h> // for getchar
|
||||
#include <ftxui/dom/elements.hpp> // for filler, text, hbox, vbox
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <memory> // for allocator
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto document = //
|
||||
vbox({
|
||||
hbox({
|
||||
text("north-west"),
|
||||
filler(),
|
||||
text("north-east"),
|
||||
}),
|
||||
filler(),
|
||||
hbox({
|
||||
filler(),
|
||||
text("center"),
|
||||
filler(),
|
||||
}),
|
||||
filler(),
|
||||
hbox({
|
||||
text("south-west"),
|
||||
filler(),
|
||||
text("south-east"),
|
||||
}),
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Full());
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
getchar();
|
||||
|
||||
return 0;
|
||||
}
|
||||
49
ftxui/examples/dom/vflow.cpp
Normal file
49
ftxui/examples/dom/vflow.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
// 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.
|
||||
#include <stdio.h> // for getchar
|
||||
#include <ftxui/dom/elements.hpp> // for operator|, Element, size, text, hcenter, Fit, vflow, window, EQUAL, bold, border, dim, HEIGHT, WIDTH
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <string> // for allocator, char_traits, operator+, to_string, string
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for ftxui
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto make_box = [](int dimx, int dimy) {
|
||||
std::string title = std::to_string(dimx) + "x" + std::to_string(dimy);
|
||||
return window(text(title) | hcenter | bold,
|
||||
text("content") | hcenter | dim) |
|
||||
size(WIDTH, EQUAL, dimx) | size(HEIGHT, EQUAL, dimy);
|
||||
};
|
||||
|
||||
auto document = vflow({
|
||||
make_box(7, 7),
|
||||
make_box(7, 5),
|
||||
make_box(5, 7),
|
||||
make_box(10, 4),
|
||||
make_box(10, 4),
|
||||
make_box(10, 4),
|
||||
make_box(10, 4),
|
||||
make_box(11, 4),
|
||||
make_box(11, 4),
|
||||
make_box(11, 4),
|
||||
make_box(11, 4),
|
||||
make_box(12, 4),
|
||||
make_box(12, 5),
|
||||
make_box(12, 4),
|
||||
make_box(13, 4),
|
||||
make_box(13, 3),
|
||||
make_box(13, 3),
|
||||
make_box(10, 3),
|
||||
}) |
|
||||
border;
|
||||
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
getchar();
|
||||
|
||||
return 0;
|
||||
}
|
||||
85
ftxui/examples/html/test.html.disabled
Normal file
85
ftxui/examples/html/test.html.disabled
Normal file
@@ -0,0 +1,85 @@
|
||||
<!doctype html>
|
||||
<html lang="en_US">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
|
||||
|
||||
<style>
|
||||
html, body, textarea{
|
||||
margin:0;
|
||||
padding:0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow:hidden;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color:gray;
|
||||
};
|
||||
|
||||
textarea {
|
||||
white-space: pre-wrap;
|
||||
background-color:white;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script type="text/c++">
|
||||
#include <iostream>
|
||||
|
||||
#include <ftxui/screen/screen.hpp>
|
||||
#include <ftxui/dom/elements.hpp>
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto document =
|
||||
hbox(
|
||||
window(text(" main frame ") | hcenter,
|
||||
vbox(
|
||||
text("Line 1"),
|
||||
text("Line 2"),
|
||||
text("Line 3"),
|
||||
vbox(
|
||||
text("Line 4"),
|
||||
text("Line 5"),
|
||||
text("Line 6")
|
||||
) | border,
|
||||
hbox(
|
||||
window(text("frame 2"),
|
||||
vbox(
|
||||
text("Line 4"),
|
||||
gauge(0.5) | border,
|
||||
text("Line 6")
|
||||
)
|
||||
),
|
||||
window(text("frame 3"),
|
||||
vbox(
|
||||
text("Line 7"),
|
||||
text("Line 8"),
|
||||
text("Line 9")
|
||||
)
|
||||
)
|
||||
),
|
||||
text("footer footer footer footer footer")
|
||||
)
|
||||
),
|
||||
filler()
|
||||
);
|
||||
auto screen = Screen::Create(Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
std::cout << screen.ToString() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<textarea id="box"></textarea>
|
||||
</body>
|
||||
<script>
|
||||
window.Module = {
|
||||
'print': function(text) {
|
||||
console.log(text);
|
||||
document.getElementById("box").value += text + '\n';
|
||||
}
|
||||
};
|
||||
</script>
|
||||
</html>
|
||||
180
ftxui/examples/index.css
Normal file
180
ftxui/examples/index.css
Normal file
@@ -0,0 +1,180 @@
|
||||
@import url(https://fonts.googleapis.com/css?family=Khula:700);
|
||||
|
||||
html {
|
||||
--toc-width: 250px;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: #EEE;
|
||||
padding: 0px;
|
||||
margin: 0px;
|
||||
font-family: Khula, Helvetica, sans-serif;
|
||||
font-size: 130%;
|
||||
}
|
||||
|
||||
.page {
|
||||
max-width: 1300px;
|
||||
margin: auto;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
a {
|
||||
box-shadow: inset 0 0 0 0 #54b3d6;
|
||||
color: #0087b9;
|
||||
margin: 0 -.25rem;
|
||||
padding: 0 .25rem;
|
||||
transition: color .3s ease-in-out,
|
||||
box-shadow .3s ease-in-out;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
box-shadow: inset 120px 0 0 0 #54b3d6;
|
||||
color: white;
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-decoration: underline;
|
||||
width: 100%;
|
||||
background-color: rgba(100, 100, 255, 0.5);
|
||||
padding: 10px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
|
||||
#selectExample {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
#selectExample,
|
||||
#selectExample option {
|
||||
font-size: 16px;
|
||||
font-family: sans-serif;
|
||||
font-weight: 700;
|
||||
line-height: 1.3;
|
||||
border: 0px;
|
||||
background-color: #bbb;
|
||||
color: black;
|
||||
}
|
||||
|
||||
#selectExample:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
#terminal {
|
||||
width: 100%;
|
||||
height 500px;
|
||||
height: calc(clamp(200px, 100vh - 300px, 900px));
|
||||
overflow: hidden;
|
||||
border: none;
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
}
|
||||
|
||||
#terminalContainer {
|
||||
overflow: hidden;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.75),
|
||||
0px 2px 80px 0px rgba(0, 0, 0, 0.50);
|
||||
background-color: black;
|
||||
}
|
||||
|
||||
.fakeButtons {
|
||||
height: 10px;
|
||||
width: 10px;
|
||||
border-radius: 50%;
|
||||
border: 1px solid #000;
|
||||
margin: 6px;
|
||||
background-color: #ff3b47;
|
||||
border-color: #9d252b;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.fakeMinimize {
|
||||
left: 11px;
|
||||
background-color: #ffc100;
|
||||
border-color: #9d802c;
|
||||
}
|
||||
|
||||
.fakeZoom {
|
||||
left: 16px;
|
||||
background-color: #00d742;
|
||||
border-color: #049931;
|
||||
}
|
||||
|
||||
.fakeMenu {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
height: 25px;
|
||||
background-color: #bbb;
|
||||
color: black;
|
||||
margin: 0 auto;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.toc-container {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: var(--toc-width);
|
||||
background: white;
|
||||
padding: 0;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
|
||||
.toc-title {
|
||||
font-weight: bold;
|
||||
margin-bottom: 5px;
|
||||
font-size: 0.9em;
|
||||
color: #555;
|
||||
|
||||
position: sticky;
|
||||
transition: position 1.0s ease-in-out;
|
||||
top: 0;
|
||||
z-index: 1;
|
||||
padding: 20px;
|
||||
margin: 0;
|
||||
|
||||
border-bottom: 1px solid #ddd;
|
||||
|
||||
/* Gradient background for the title */
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
|
||||
.toc-item {
|
||||
padding: 3px 8px;
|
||||
margin: 0;
|
||||
cursor: pointer;
|
||||
font-size: 0.85em;
|
||||
border-radius: 3px;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.toc-item:hover {
|
||||
background: #f0f0f0;
|
||||
}
|
||||
|
||||
.toc-item.selected {
|
||||
background: #e0e0e0;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
.toc-container {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.page {
|
||||
margin-left: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1025px) {
|
||||
.page {
|
||||
margin-left: calc(var(--toc-width) + 20px);
|
||||
}
|
||||
}
|
||||
37
ftxui/examples/index.html
Normal file
37
ftxui/examples/index.html
Normal file
@@ -0,0 +1,37 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>FTXUI examples WebAssembly</title>
|
||||
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>➡️</text></svg>">
|
||||
<link rel="stylesheet" href="index.css">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/xterm@4.11.0/css/xterm.css"></link>
|
||||
<script type="module" src="index.mjs"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="toc-container">
|
||||
<div class="toc-list"></div>
|
||||
</div>
|
||||
<script id="example_script"></script>
|
||||
|
||||
<div class="page">
|
||||
<p>
|
||||
<a href="https://github.com/ArthurSonzogni/FTXUI">FTXUI</a> is a simple
|
||||
functional C++ library for terminal user interface. <br/>
|
||||
This showcases the: <a
|
||||
href="https://github.com/ArthurSonzogni/FTXUI/tree/master/examples">./example/</a>
|
||||
folder. See <a id="source">source</a>.
|
||||
</p>
|
||||
|
||||
<div id="terminalContainer">
|
||||
<div class="fakeMenu">
|
||||
<div class="fakeButtons fakeClose"></div>
|
||||
<div class="fakeButtons fakeMinimize"></div>
|
||||
<div class="fakeButtons fakeZoom"></div>
|
||||
<select id="selectExample"></select>
|
||||
</div>
|
||||
<div id="terminal"></div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
160
ftxui/examples/index.mjs
Normal file
160
ftxui/examples/index.mjs
Normal file
@@ -0,0 +1,160 @@
|
||||
import xterm from 'https://cdn.jsdelivr.net/npm/xterm@4.18.0/+esm'
|
||||
import xterm_addon_webgl from 'https://cdn.jsdelivr.net/npm/xterm-addon-webgl@0.11.4/+esm'
|
||||
import xterm_addon_fit from 'https://cdn.jsdelivr.net/npm/xterm-addon-fit@0.5.0/+esm'
|
||||
|
||||
// Add COOP/COEP via a ServiceWorker to use SharedArrayBuffer
|
||||
if ("serviceWorker" in navigator && !window.crossOriginIsolated) {
|
||||
const url_sw = new URL("./sw.js", location.href);
|
||||
const registration = await navigator.serviceWorker.register(url_sw);
|
||||
window.location.reload(); // Reload to ensure the COOP/COEP headers are set.
|
||||
}
|
||||
|
||||
const example_list = "@EXAMPLES@".split(";");
|
||||
const url_search_params = new URLSearchParams(window.location.search);
|
||||
|
||||
const select = document.getElementById("selectExample");
|
||||
for(const example of example_list) {
|
||||
const option = document.createElement("option");
|
||||
option.textContent = example;
|
||||
option.value = example;
|
||||
select.appendChild(option);
|
||||
}
|
||||
const example = url_search_params.get("file") || "dom/color_gallery";
|
||||
select.selectedIndex = example_list.findIndex(path => path == example) || 0;
|
||||
select.addEventListener("change", () => {
|
||||
history.pushState({}, "", "?file=" + example_list[select.selectedIndex]);
|
||||
location.reload();
|
||||
});
|
||||
|
||||
const term_element = document.querySelector('#terminal');
|
||||
const term = new xterm.Terminal();
|
||||
term.options.scrollback = 0;
|
||||
term.open(term_element);
|
||||
const fit_addon = new xterm_addon_fit.FitAddon();
|
||||
const webgl_addon = new xterm_addon_webgl.WebglAddon();
|
||||
term.loadAddon(webgl_addon);
|
||||
term.loadAddon(fit_addon);
|
||||
|
||||
const stdin_buffer = [];
|
||||
const stdout_buffer = [];
|
||||
const stderr_buffer = [];
|
||||
|
||||
const stdin = () => {
|
||||
return stdin_buffer.shift() || 0;
|
||||
}
|
||||
|
||||
const stdout = code => {
|
||||
if (code == 0) {
|
||||
term.write(new Uint8Array(stdout_buffer));
|
||||
stdout_buffer.length = 0;
|
||||
} else {
|
||||
stdout_buffer.push(code)
|
||||
}
|
||||
}
|
||||
|
||||
const stderr = code => {
|
||||
if (code == 0 || code == 10) {
|
||||
console.error(String.fromCodePoint(...stderr_buffer));
|
||||
stderr_buffer.length = 0;
|
||||
} else {
|
||||
stderr_buffer.push(code)
|
||||
}
|
||||
}
|
||||
|
||||
const onBinary = e => {
|
||||
for(const c of e)
|
||||
stdin_buffer.push(c.charCodeAt(0));
|
||||
}
|
||||
|
||||
term.onBinary(onBinary);
|
||||
term.onData(onBinary)
|
||||
term.resize(140,43);
|
||||
|
||||
window.Module = {
|
||||
preRun: () => {
|
||||
FS.init(stdin, stdout, stderr);
|
||||
},
|
||||
postRun: [],
|
||||
onRuntimeInitialized: () => {
|
||||
if (window.Module._ftxui_on_resize == undefined)
|
||||
return;
|
||||
fit_addon.fit();
|
||||
|
||||
const resize_handler = () => {
|
||||
const {cols, rows} = fit_addon.proposeDimensions();
|
||||
term.resize(cols, rows);
|
||||
window.Module._ftxui_on_resize(cols, rows);
|
||||
fit_addon.fit();
|
||||
};
|
||||
const resize_observer = new ResizeObserver(resize_handler);
|
||||
resize_observer.observe(term_element);
|
||||
resize_handler();
|
||||
},
|
||||
};
|
||||
|
||||
const source = document.querySelector("#source");
|
||||
source.href = "https://github.com/ArthurSonzogni/FTXUI/blob/main/examples/" + example + ".cpp";
|
||||
|
||||
const words = example.split('/')
|
||||
words[1] = "ftxui_example_" + words[1] + ".js"
|
||||
document.querySelector("#example_script").src = words.join('/');
|
||||
|
||||
|
||||
// Table of Contents (TOC) for quick navigation.
|
||||
|
||||
// Get select element
|
||||
const selectEl = document.querySelector('select#selectExample');
|
||||
if (!selectEl) {
|
||||
console.error('select#selectExample not found');
|
||||
} else {
|
||||
// Get TOC container
|
||||
const tocContainer = document.querySelector('.toc-container');
|
||||
const tocList = tocContainer.querySelector('.toc-list');
|
||||
|
||||
// Group options by directory
|
||||
const groupedOptions = Array.from(selectEl.options).reduce((acc, option) => {
|
||||
const [dir, file] = option.text.split('/');
|
||||
if (!acc[dir]) {
|
||||
acc[dir] = [];
|
||||
}
|
||||
acc[dir].push({ option, file });
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
// Generate TOC items
|
||||
for (const dir in groupedOptions) {
|
||||
const dirContainer = document.createElement('div');
|
||||
|
||||
const dirHeader = document.createElement('div');
|
||||
dirHeader.textContent = dir;
|
||||
dirHeader.className = 'toc-title';
|
||||
dirContainer.appendChild(dirHeader);
|
||||
|
||||
groupedOptions[dir].forEach(({ option, file }) => {
|
||||
const tocItem = document.createElement('div');
|
||||
tocItem.textContent = file;
|
||||
tocItem.className = 'toc-item';
|
||||
|
||||
if (selectEl.options[selectEl.selectedIndex].value === option.value) {
|
||||
tocItem.classList.add('selected');
|
||||
}
|
||||
|
||||
// Click handler
|
||||
tocItem.addEventListener('click', () => {
|
||||
for(let i=0; i<selectEl.options.length; ++i) {
|
||||
if (selectEl.options[i].value == option.value) {
|
||||
selectEl.selectedIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
history.pushState({}, "", "?file=" + option.value);
|
||||
location.reload();
|
||||
});
|
||||
|
||||
dirContainer.appendChild(tocItem);
|
||||
});
|
||||
|
||||
tocList.appendChild(dirContainer);
|
||||
}
|
||||
}''
|
||||
20
ftxui/examples/run_webassembly.py
Executable file
20
ftxui/examples/run_webassembly.py
Executable file
@@ -0,0 +1,20 @@
|
||||
#! /usr/bin/python3
|
||||
from http.server import HTTPServer, SimpleHTTPRequestHandler
|
||||
import sys
|
||||
import webbrowser
|
||||
|
||||
PORT = 8888
|
||||
|
||||
class CustomHTTPRequestHandler(SimpleHTTPRequestHandler):
|
||||
def end_headers(self):
|
||||
self.send_header("cross-origin-embedder-policy", "require-corp")
|
||||
self.send_header("cross-origin-opener-policy", "same-origin")
|
||||
SimpleHTTPRequestHandler.end_headers(self)
|
||||
|
||||
with HTTPServer(("", PORT), CustomHTTPRequestHandler) as httpd:
|
||||
try:
|
||||
webbrowser.open("http://localhost:%s" % PORT)
|
||||
print("serving at port", PORT)
|
||||
httpd.serve_forever()
|
||||
finally:
|
||||
sys.exit(0)
|
||||
25
ftxui/examples/sw.js
Normal file
25
ftxui/examples/sw.js
Normal file
@@ -0,0 +1,25 @@
|
||||
// sw.js
|
||||
self.addEventListener("install", () => self.skipWaiting());
|
||||
self.addEventListener("activate", e => e.waitUntil(self.clients.claim()));
|
||||
self.addEventListener("fetch", e => {
|
||||
if (e.request.mode != 'navigate' &&
|
||||
!e.request.url.includes(".worker.js")) {
|
||||
return;
|
||||
}
|
||||
|
||||
e.respondWith((async () => {
|
||||
const response = await fetch(e.request);
|
||||
|
||||
const newHeaders = new Headers(response.headers);
|
||||
newHeaders.set("Cross-Origin-Embedder-Policy", "require-corp");
|
||||
newHeaders.set("Cross-Origin-Opener-Policy", "same-origin");
|
||||
|
||||
const moddedResponse = new Response(response.body, {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
headers: newHeaders,
|
||||
});
|
||||
|
||||
return moddedResponse;
|
||||
})());
|
||||
});
|
||||
Reference in New Issue
Block a user