examples/component/composition.cpp

    //Copyright2021ArthurSonzogni.Allrightsreserved.
    //UseofthissourcecodeisgovernedbytheMITlicensethatcanbefoundin
    //theLICENSEfile.
    #include<memory>//forallocator,shared_ptr,__shared_ptr_access
    #include<string>//foroperator+,to_string

    #include"ftxui/component/captured_mouse.hpp"//forftxui
    #include"ftxui/component/component.hpp"//forButton,Horizontal,Renderer
    #include"ftxui/component/component_base.hpp"//forComponentBase
    #include"ftxui/component/screen_interactive.hpp"//forScreenInteractive
    #include"ftxui/dom/elements.hpp"//fortext,separator,Element,operator|,vbox,border

    usingnamespaceftxui;

    //Anexampleofhowtocomposemultiplecomponentsintooneandmaintaintheir
    //interactiveness.
    intmain(){
    autoleft_count=0;
    autoright_count=0;

    autoleft_buttons=Container::Horizontal({
    Button("Decrease",[&]{left_count--;}),
    Button("Increase",[&]{left_count++;}),
    });

    autoright_buttons=Container::Horizontal({
    Button("Decrease",[&]{right_count--;}),
    Button("Increase",[&]{right_count++;}),
    });

    //Rendererdecoratesitschildwithanewrenderingfunction.Thewaythe
    //childrenreactstoeventsismaintained.
    autoleftpane=Renderer(left_buttons,[&]{
    returnvbox({
    text("Thisistheleftcontrol"),
    separator(),
    text("Leftbuttoncount:"+std::to_string(left_count)),
    left_buttons->Render(),
    })|
    border;
    });

    autorightpane=Renderer(right_buttons,[&]{
    returnvbox({
    text("Thisistherightcontrol"),
    separator(),
    text("Rightbuttoncount:"+std::to_string(right_count)),
    right_buttons->Render(),
    })|
    border;
    });

    //Containergroupscomponentstogethers.TorenderaContainer::Horizontal,
    //itrenderitschildrensidebyside.Itmaintainstheirinteractivenessand
    //providethelogictonavigatefromonetotheotherusingthearrowkeys.
    autocomposition=Container::Horizontal({leftpane,rightpane});

    autoscreen=ScreenInteractive::FitComponent();
    screen.Loop(composition);
    return0;
    }

    //ThankstoChrisMorganforthisexample!