examples/component/toggle.cpp

    //Copyright2020ArthurSonzogni.Allrightsreserved.
    //UseofthissourcecodeisgovernedbytheMITlicensethatcanbefoundin
    //theLICENSEfile.
    #include<memory>//forallocator,__shared_ptr_access
    #include<string>//forstring,basic_string
    #include<vector>//forvector

    #include"ftxui/component/captured_mouse.hpp"//forftxui
    #include"ftxui/component/component.hpp"//forToggle,Renderer,Vertical
    #include"ftxui/component/component_base.hpp"//forComponentBase
    #include"ftxui/component/screen_interactive.hpp"//forComponent,ScreenInteractive
    #include"ftxui/dom/elements.hpp"//fortext,hbox,vbox,Element

    usingnamespaceftxui;

    intmain(){
    std::vector<std::string>toggle_1_entries={
    "On",
    "Off",
    };
    std::vector<std::string>toggle_2_entries={
    "Enabled",
    "Disabled",
    };
    std::vector<std::string>toggle_3_entries={
    "10€",
    "0€",
    };
    std::vector<std::string>toggle_4_entries={
    "Nothing",
    "Oneelement",
    "Severalelements",
    };

    inttoggle_1_selected=0;
    inttoggle_2_selected=0;
    inttoggle_3_selected=0;
    inttoggle_4_selected=0;
    Componenttoggle_1=Toggle(&toggle_1_entries,&toggle_1_selected);
    Componenttoggle_2=Toggle(&toggle_2_entries,&toggle_2_selected);
    Componenttoggle_3=Toggle(&toggle_3_entries,&toggle_3_selected);
    Componenttoggle_4=Toggle(&toggle_4_entries,&toggle_4_selected);

    autocontainer=Container::Vertical({
    toggle_1,
    toggle_2,
    toggle_3,
    toggle_4,
    });

    autorenderer=Renderer(container,[&]{
    returnvbox({
    text("Chooseyouroptions:"),
    text(""),
    hbox(text("*Poweroffonstartup:"),toggle_1->Render()),
    hbox(text("*Outofprocess:"),toggle_2->Render()),
    hbox(text("*Priceoftheinformation:"),toggle_3->Render()),
    hbox(text("*Numberofelements:"),toggle_4->Render()),
    });
    });

    autoscreen=ScreenInteractive::TerminalOutput();
    screen.Loop(renderer);
    }