examples/component/custom_loop.cpp

    //Copyright2020ArthurSonzogni.Allrightsreserved.
    //UseofthissourcecodeisgovernedbytheMITlicensethatcanbefoundin
    //theLICENSEfile.
    #include<stdlib.h>//forEXIT_SUCCESS
    #include<chrono>//formilliseconds
    #include<ftxui/component/event.hpp>//forEvent
    #include<ftxui/component/mouse.hpp>//forftxui
    #include<ftxui/dom/elements.hpp>//fortext,separator,Element,operator|,vbox,border
    #include<memory>//forallocator,shared_ptr
    #include<string>//foroperator+,to_string
    #include<thread>//forsleep_for

    #include"ftxui/component/component.hpp"//forCatchEvent,Renderer,operator|=
    #include"ftxui/component/loop.hpp"//forLoop
    #include"ftxui/component/screen_interactive.hpp"//forScreenInteractive

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

    //Createacomponentcountingthenumberofframesdrawnandeventhandled.
    intcustom_loop_count=0;
    intframe_count=0;
    intevent_count=0;
    autocomponent=Renderer([&]{
    frame_count++;
    returnvbox({
    text("Thisdemonstratesusingacustomftxui::Loop.It"),
    text("runsat100iterationsperseconds.TheFTXUIevents"),
    text("areallprocessedonceperiterationandanewframe"),
    text("isrenderedasneeded"),
    separator(),
    text("ftxuieventcount:"+std::to_string(event_count)),
    text("ftxuiframecount:"+std::to_string(frame_count)),
    text("Customloopcount:"+std::to_string(custom_loop_count)),
    })|
    border;
    });

    component|=CatchEvent([&](Event)->bool{
    event_count++;
    returnfalse;
    });

    Looploop(&screen,component);

    while(!loop.HasQuitted()){
    custom_loop_count++;
    loop.RunOnce();
    std::this_thread::sleep_for(std::chrono::milliseconds(10));
    }

    returnEXIT_SUCCESS;
    }