examples/component/gallery.cpp

    //Copyright2020ArthurSonzogni.Allrightsreserved.
    //UseofthissourcecodeisgovernedbytheMITlicensethatcanbefoundin
    //theLICENSEfile.
    #include<functional>//forfunction
    #include<memory>//forshared_ptr,allocator,__shared_ptr_access
    #include<string>//forstring,basic_string
    #include<vector>//forvector

    #include"ftxui/component/captured_mouse.hpp"//forftxui
    #include"ftxui/component/component.hpp"//forSlider,Checkbox,Vertical,Renderer,Button,Input,Menu,Radiobox,Toggle
    #include"ftxui/component/component_base.hpp"//forComponentBase
    #include"ftxui/component/screen_interactive.hpp"//forComponent,ScreenInteractive
    #include"ftxui/dom/elements.hpp"//forseparator,operator|,Element,size,xflex,text,WIDTH,hbox,vbox,EQUAL,border,GREATER_THAN

    usingnamespaceftxui;

    //Displayacomponentnicelywithatitleontheleft.
    ComponentWrap(std::stringname,Componentcomponent){
    returnRenderer(component,[name,component]{
    returnhbox({
    text(name)|size(WIDTH,EQUAL,8),
    separator(),
    component->Render()|xflex,
    })|
    xflex;
    });
    }

    intmain(){
    autoscreen=ScreenInteractive::FitComponent();

    //--Menu
    //----------------------------------------------------------------------
    conststd::vector<std::string>menu_entries={
    "Menu1",
    "Menu2",
    "Menu3",
    "Menu4",
    };
    intmenu_selected=0;
    automenu=Menu(&menu_entries,&menu_selected);
    menu=Wrap("Menu",menu);

    //--Toggle------------------------------------------------------------------
    inttoggle_selected=0;
    std::vector<std::string>toggle_entries={
    "Toggle_1",
    "Toggle_2",
    };
    autotoggle=Toggle(&toggle_entries,&toggle_selected);
    toggle=Wrap("Toggle",toggle);

    //--Checkbox---------------------------------------------------------------
    boolcheckbox_1_selected=false;
    boolcheckbox_2_selected=false;
    boolcheckbox_3_selected=false;
    boolcheckbox_4_selected=false;

    autocheckboxes=Container::Vertical({
    Checkbox("checkbox1",&checkbox_1_selected),
    Checkbox("checkbox2",&checkbox_2_selected),
    Checkbox("checkbox3",&checkbox_3_selected),
    Checkbox("checkbox4",&checkbox_4_selected),
    });
    checkboxes=Wrap("Checkbox",checkboxes);

    //--Radiobox---------------------------------------------------------------
    intradiobox_selected=0;
    std::vector<std::string>radiobox_entries={
    "Radiobox1",
    "Radiobox2",
    "Radiobox3",
    "Radiobox4",
    };
    autoradiobox=Radiobox(&radiobox_entries,&radiobox_selected);
    radiobox=Wrap("Radiobox",radiobox);

    //--Input------------------------------------------------------------------
    std::stringinput_label;
    autoinput=Input(&input_label,"placeholder");
    input=Wrap("Input",input);

    //--Button-----------------------------------------------------------------
    std::stringbutton_label="Quit";
    std::function<void()>on_button_clicked_;
    autobutton=Button(&button_label,screen.ExitLoopClosure());
    button=Wrap("Button",button);

    //--Slider-----------------------------------------------------------------
    intslider_value_1=12;
    intslider_value_2=56;
    intslider_value_3=128;
    autosliders=Container::Vertical({
    Slider("R:",&slider_value_1,0,256,1),
    Slider("G:",&slider_value_2,0,256,1),
    Slider("B:",&slider_value_3,0,256,1),
    });
    sliders=Wrap("Slider",sliders);

    //Alargetext:
    autolorel_ipsum=Renderer([]{
    returnvbox({
    text("Loremipsumdolorsitamet,consecteturadipiscingelit."),
    text("Seddoeiusmodtemporincididuntutlaboreetdoloremagna"
    "aliqua."),
    text("Utenimadminimveniam,quisnostrudexercitationullamco"
    "laborisnisiutaliquipexeacommodoconsequat."),
    text("Duisauteiruredolorinreprehenderitinvoluptatevelitesse"
    "cillumdoloreeufugiatnullapariatur."),
    text("Excepteursintoccaecatcupidatatnonproident,suntinculpa"
    "quiofficiadeseruntmollitanimidestlaborum."),

    });
    });
    lorel_ipsum=Wrap("LorelIpsum",lorel_ipsum);

    //--Layout
    //-----------------------------------------------------------------
    autolayout=Container::Vertical({
    menu,
    toggle,
    checkboxes,
    radiobox,
    input,
    sliders,
    button,
    lorel_ipsum,
    });

    autocomponent=Renderer(layout,[&]{
    returnvbox({
    menu->Render(),
    separator(),
    toggle->Render(),
    separator(),
    checkboxes->Render(),
    separator(),
    radiobox->Render(),
    separator(),
    input->Render(),
    separator(),
    sliders->Render(),
    separator(),
    button->Render(),
    separator(),
    lorel_ipsum->Render(),
    })|
    xflex|size(WIDTH,GREATER_THAN,40)|border;
    });

    screen.Loop(component);

    return0;
    }