#include <functional>
#include <memory>
std::function<void()> exit) {
auto component = Container::Vertical({
});
component |= Renderer([&](
Element inner) {
return vbox({
text("Main component"),
separator(),
inner,
})
|
size(WIDTH, GREATER_THAN, 15)
|
size(HEIGHT, GREATER_THAN, 15)
});
return component;
}
std::function<void()> hide_modal) {
auto component = Container::Vertical({
});
text(
"Modal component "),
inner,
})
|
size(WIDTH, GREATER_THAN, 30)
});
return component;
}
int main(
int argc,
const char* argv[]) {
auto screen = ScreenInteractive::TerminalOutput();
bool modal_shown = false;
auto show_modal = [&] { modal_shown = true; };
auto hide_modal = [&] { modal_shown = false; };
auto exit = screen.ExitLoopClosure();
auto do_nothing = [&] {};
main_component |=
Modal(modal_component, &modal_shown);
screen.Loop(main_component);
return 0;
}
Component ModalComponent(std::function< void()> do_nothing, std::function< void()> hide_modal)
Component MainComponent(std::function< void()> show_modal, std::function< void()> exit)
Decorator size(WidthOrHeight, Constraint, int value)
Apply a constraint on the size of an element.
std::shared_ptr< Node > Element
Component Button(ButtonOption options)
Draw a button. Execute a function when clicked.
Component Modal(Component main, Component modal, const bool *show_modal)
Component Renderer(Component child, std::function< Element()>)
Return a new Component, similar to |child|, but using |render| as the Component::Render() event.
Element center(Element)
Center an element horizontally and vertically.
Element text(std::wstring text)
Display a piece of unicode text.
Element separator()
Draw a vertical or horizontal separation in between two other elements.
Element border(Element)
Draw a border around the element.
std::shared_ptr< ComponentBase > Component
Element vbox(Elements)
A container displaying elements vertically one by one.
#include <chrono>
#include <memory>
#include <string>
#include <vector>
return Renderer([id](bool focused) {
auto t = text("component " + std::to_string(id));
if (focused)
t = t | inverted;
return t;
});
}
return Renderer([t] { return text(t) | borderEmpty; });
}
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;
[&] {
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));
}
{
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);
}
Component Menu(MenuOption options)
A list of text. The focused element is selected.