#include <array>
#include <chrono>
#include <functional>
#include <memory>
#include <string>
#include <vector>
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
vmenu_1_->Render(),
vmenu_2_->Render(),
vmenu_3_->Render(),
vmenu_4_->Render(),
vmenu_5_->Render(),
vmenu_6_->Render(),
vmenu_7_->Render(),
vmenu_8_->Render(),
}),
hmenu_1_->Render(),
hmenu_2_->Render(),
hmenu_3_->Render(),
hmenu_4_->Render(),
hmenu_5_->Render(),
}) | border,
});
});
screen.Loop(renderer);
}
auto option = MenuOption::Vertical();
option.entries_option.transform = [](
EntryState state) {
state.label = (state.active ? "> " : " ") + state.label;
if (state.focused)
if (state.active)
return e;
};
return Menu(entries, selected, option);
}
auto option = MenuOption::Vertical();
option.entries_option.transform = [](
EntryState state) {
state.label += (state.active ? " <" : " ");
if (state.focused)
if (state.active)
return e;
};
return Menu(entries, selected, option);
}
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);
}
auto option = MenuOption::Vertical();
option.entries_option.transform = [](
EntryState state) {
if (state.active && state.focused) {
}
if (state.active) {
}
if (state.focused) {
}
};
return Menu(entries, selected, option);
}
auto option = MenuOption::Vertical();
option.entries_option.transform = [](
EntryState state) {
auto element =
text(state.label);
if (state.active && state.focused) {
}
if (state.active) {
}
if (state.focused) {
}
return element;
};
return Menu(entries, selected, option);
}
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);
}
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);
}
auto option = MenuOption::Vertical();
option.entries_option.animated_colors.foreground.Set(
Color::Red, Color::White, std::chrono::milliseconds(500));
return Menu(entries, selected, option);
}
return Menu(entries, selected, MenuOption::Horizontal());
}
return Menu(entries, selected, MenuOption::Toggle());
}
auto option = MenuOption::Toggle();
option.elements_infix = [] {
return text(
" 🮣🮠"); };
return Menu(entries, selected, option);
}
return Menu(entries, selected, MenuOption::HorizontalAnimated());
}
auto option = MenuOption::HorizontalAnimated();
option.underline.SetAnimation(std::chrono::milliseconds(1500),
animation::easing::ElasticOut);
option.entries_option.transform = [](
EntryState state) {
if (state.active && state.focused)
if (!state.focused && !state.active)
return e;
};
option.underline.color_inactive = Color::Default;
option.underline.color_active = Color::Red;
return Menu(entries, selected, option);
}
Decorator bgcolor(Color)
Decorate using a background color.
Element borderDouble(Element)
Draw a double border around the element.
Element flex(Element)
Make a child element to expand proportionally to the space left in a container.
Component Menu(MenuOption options)
A list of text. The focused element is selected.
std::shared_ptr< Node > Element
Element bold(Element)
Use a bold font, for elements with more emphasis.
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 filler()
An element that will take expand proportionally to the space left in a container.
Element dim(Element)
Use a light font, for elements with less emphasis.
Element border(Element)
Draw a border around the element.
std::shared_ptr< ComponentBase > Component
Decorator color(Color)
Decorate using a foreground color.
Element hcenter(Element)
Center an element horizontally.
Element vbox(Elements)
A container displaying elements vertically one by one.
arguments for transform from |ButtonOption|, |CheckboxOption|, |RadioboxOption|, |MenuEntryOption|,...
#include <stdlib.h>
#include <memory>
#include <string>
#include <vector>
return Renderer(component, [component, title] {
return window(text(title), component->Render()) | flex;
});
}
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);
int g = menu_selected_global;
std::string value = menu_entries[g][menu_selected[g]];
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;
}
Element window(Element title, Element content, BorderStyle border=ROUNDED)
Draw window with a title and a border around the element.