#include <functional>
#include <iostream>
#include <memory>
#include <string>
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;
}
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(); }),
},
&selected);
menu->Render() |
frame |
size(HEIGHT, LESS_THAN, 10),
}) |
border;
});
screen.Loop(renderer);
std::cout << "Selected element = " << selected << std::endl;
}
A class representing terminal colors.
Decorator size(WidthOrHeight, Constraint, int value)
Apply a constraint on the size of an element.
std::shared_ptr< Node > Element
Component MenuEntry(MenuEntryOption options)
A specific menu entry. They can be put into a Container::Vertical to form a menu.
Component Renderer(Component child, std::function< Element()>)
Return a new Component, similar to |child|, but using |render| as the Component::Render() event.
Element hbox(Elements)
A container displaying elements horizontally one by one.
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 frame(Element)
Allow an element to be displayed inside a 'virtual' area. It size can be larger than its container....
Element vbox(Elements)
A container displaying elements vertically one by one.
arguments for transform from |ButtonOption|, |CheckboxOption|, |RadioboxOption|, |MenuEntryOption|,...
#include <functional>
#include <memory>
#include <string>
#include <vector>
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%",
};
menu_option.on_enter = screen.ExitLoopClosure();
int left_menu_selected = 0;
int right_menu_selected = 0;
Menu(&left_menu_entries, &left_menu_selected, menu_option);
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({
hbox({
vbox({
hcenter(bold(text("Percentage by 10%"))),
separator(),
left_menu_->Render(),
}),
separator(),
vbox({
hcenter(bold(text("Percentage by 1%"))),
separator(),
right_menu_->Render(),
}),
separator(),
}),
separator(),
vbox({
hbox({
text(" gauge : "),
gauge(sum / 100.0),
}),
hbox({
text(" text : "),
text(std::to_string(sum) + " %"),
}),
}),
}) |
border;
});
screen.Loop(renderer);
}
std::shared_ptr< ComponentBase > Component