#include <functional>
#include <memory>
auto button_style = ButtonOption::Animated();
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),
});
component |= Renderer([&](
Element inner) {
return vbox({
text("Main component"),
separator(),
inner,
})
|
size(WIDTH, GREATER_THAN, 15)
|
size(HEIGHT, GREATER_THAN, 15)
});
return component;
}
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),
});
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 = [&] {};
auto main_component = MainComponent(show_modal, exit);
auto modal_component = ModalComponent(do_nothing, hide_modal);
main_component |=
Modal(modal_component, &modal_shown);
screen.Loop(main_component);
return 0;
}
Decorator size(WidthOrHeight, Constraint, int value)
Apply a constraint on the size of an element.
std::shared_ptr< Node > Element
std::shared_ptr< ComponentBase > Component
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.
Element vbox(Elements)
A container displaying elements vertically one by one.