examples/component/menu_style.cpp

    //Copyright2020ArthurSonzogni.Allrightsreserved.
    //UseofthissourcecodeisgovernedbytheMITlicensethatcanbefoundin
    //theLICENSEfile.
    #include<array>//forarray
    #include<chrono>//formilliseconds
    #include<functional>//forfunction
    #include<memory>//for__shared_ptr_access,shared_ptr,allocator
    #include<string>//forstring,char_traits,operator+,basic_string
    #include<vector>//forvector

    #include"ftxui/component/animation.hpp"//forElasticOut,Linear
    #include"ftxui/component/component.hpp"//forMenu,Horizontal,Renderer,Vertical
    #include"ftxui/component/component_base.hpp"//forComponentBase
    #include"ftxui/component/component_options.hpp"//forMenuOption,EntryState,MenuEntryOption,AnimatedColorOption,AnimatedColorsOption,UnderlineOption
    #include"ftxui/component/mouse.hpp"//forftxui
    #include"ftxui/component/screen_interactive.hpp"//forComponent,ScreenInteractive
    #include"ftxui/dom/elements.hpp"//forseparator,operator|,Element,text,bgcolor,hbox,bold,color,filler,border,vbox,borderDouble,dim,flex,hcenter
    #include"ftxui/screen/color.hpp"//forColor,Color::Red,Color::Black,Color::Yellow,Color::Blue,Color::Default,Color::White

    usingnamespaceftxui;

    ComponentVMenu1(std::vector<std::string>*entries,int*selected);
    ComponentVMenu2(std::vector<std::string>*entries,int*selected);
    ComponentVMenu3(std::vector<std::string>*entries,int*selected);
    ComponentVMenu4(std::vector<std::string>*entries,int*selected);
    ComponentVMenu5(std::vector<std::string>*entries,int*selected);
    ComponentVMenu6(std::vector<std::string>*entries,int*selected);
    ComponentVMenu7(std::vector<std::string>*entries,int*selected);
    ComponentVMenu8(std::vector<std::string>*entries,int*selected);
    ComponentHMenu1(std::vector<std::string>*entries,int*selected);
    ComponentHMenu2(std::vector<std::string>*entries,int*selected);
    ComponentHMenu3(std::vector<std::string>*entries,int*selected);
    ComponentHMenu4(std::vector<std::string>*entries,int*selected);
    ComponentHMenu5(std::vector<std::string>*entries,int*selected);

    intmain(){
    autoscreen=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};

    autovmenu_1_=VMenu1(&entries,&selected[0]);
    autovmenu_2_=VMenu2(&entries,&selected[1]);
    autovmenu_3_=VMenu3(&entries,&selected[2]);
    autovmenu_4_=VMenu4(&entries,&selected[3]);
    autovmenu_5_=VMenu5(&entries,&selected[4]);
    autovmenu_6_=VMenu6(&entries,&selected[5]);
    autovmenu_7_=VMenu7(&entries,&selected[6]);
    autovmenu_8_=VMenu8(&entries,&selected[7]);

    autohmenu_1_=HMenu1(&entries,&selected[8]);
    autohmenu_2_=HMenu2(&entries,&selected[9]);
    autohmenu_3_=HMenu3(&entries,&selected[10]);
    autohmenu_4_=HMenu4(&entries,&selected[11]);
    autohmenu_5_=HMenu5(&entries,&selected[12]);

    autocontainer=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_,
    });

    autorenderer=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);
    }

    ComponentVMenu1(std::vector<std::string>*entries,int*selected){
    autooption=MenuOption::Vertical();
    option.entries_option.transform=[](EntryStatestate){
    state.label=(state.active?">":"")+state.label;
    Elemente=text(state.label);
    if(state.focused)
    e=e|bgcolor(Color::Blue);
    if(state.active)
    e=e|bold;
    returne;
    };
    returnMenu(entries,selected,option);
    }

    ComponentVMenu2(std::vector<std::string>*entries,int*selected){
    autooption=MenuOption::Vertical();
    option.entries_option.transform=[](EntryStatestate){
    state.label+=(state.active?"<":"");
    Elemente=hbox(filler(),text(state.label));
    if(state.focused)
    e=e|bgcolor(Color::Red);
    if(state.active)
    e=e|bold;
    returne;
    };
    returnMenu(entries,selected,option);
    }

    ComponentVMenu3(std::vector<std::string>*entries,int*selected){
    autooption=MenuOption::Vertical();
    option.entries_option.transform=[](EntryStatestate){
    Elemente=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;
    returne;
    };
    returnMenu(entries,selected,option);
    }

    ComponentVMenu4(std::vector<std::string>*entries,int*selected){
    autooption=MenuOption::Vertical();
    option.entries_option.transform=[](EntryStatestate){
    if(state.active&&state.focused){
    returntext(state.label)|color(Color::Yellow)|bgcolor(Color::Black)|
    bold;
    }

    if(state.active){
    returntext(state.label)|color(Color::Yellow)|bgcolor(Color::Black);
    }
    if(state.focused){
    returntext(state.label)|color(Color::Black)|bgcolor(Color::Yellow)|
    bold;
    }
    returntext(state.label)|color(Color::Black)|bgcolor(Color::Yellow);
    };
    returnMenu(entries,selected,option);
    }

    ComponentVMenu5(std::vector<std::string>*entries,int*selected){
    autooption=MenuOption::Vertical();
    option.entries_option.transform=[](EntryStatestate){
    autoelement=text(state.label);
    if(state.active&&state.focused){
    returnelement|borderDouble;
    }
    if(state.active){
    returnelement|border;
    }
    if(state.focused){
    returnelement|bold;
    }
    returnelement;
    };
    returnMenu(entries,selected,option);
    }

    ComponentVMenu6(std::vector<std::string>*entries,int*selected){
    autooption=MenuOption::VerticalAnimated();
    option.underline.color_inactive=Color::Default;
    option.underline.color_active=Color::Red;
    option.underline.SetAnimationFunction(animation::easing::Linear);
    returnMenu(entries,selected,option);
    }

    ComponentVMenu7(std::vector<std::string>*entries,int*selected){
    autooption=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;
    returnMenu(entries,selected,option);
    }

    ComponentVMenu8(std::vector<std::string>*entries,int*selected){
    autooption=MenuOption::Vertical();
    option.entries_option.animated_colors.foreground.Set(
    Color::Red,Color::White,std::chrono::milliseconds(500));
    returnMenu(entries,selected,option);
    }

    ComponentHMenu1(std::vector<std::string>*entries,int*selected){
    returnMenu(entries,selected,MenuOption::Horizontal());
    }

    ComponentHMenu2(std::vector<std::string>*entries,int*selected){
    returnMenu(entries,selected,MenuOption::Toggle());
    }

    ComponentHMenu3(std::vector<std::string>*entries,int*selected){
    autooption=MenuOption::Toggle();
    option.elements_infix=[]{returntext("🮣🮠");};

    returnMenu(entries,selected,option);
    }

    ComponentHMenu4(std::vector<std::string>*entries,int*selected){
    returnMenu(entries,selected,MenuOption::HorizontalAnimated());
    }

    ComponentHMenu5(std::vector<std::string>*entries,int*selected){
    autooption=MenuOption::HorizontalAnimated();
    option.underline.SetAnimation(std::chrono::milliseconds(1500),
    animation::easing::ElasticOut);
    option.entries_option.transform=[](EntryStatestate){
    Elemente=text(state.label)|hcenter|flex;
    if(state.active&&state.focused)
    e=e|bold;
    if(!state.focused&&!state.active)
    e=e|dim;
    returne;
    };
    option.underline.color_inactive=Color::Default;
    option.underline.color_active=Color::Red;
    returnMenu(entries,selected,option);
    }