examples/component/focus.cpp

    //Copyright2020ArthurSonzogni.Allrightsreserved.
    //UseofthissourcecodeisgovernedbytheMITlicensethatcanbefoundin
    //theLICENSEfile.
    #include<memory>//forallocator,shared_ptr,__shared_ptr_access
    #include<string>//foroperator+,char_traits,to_string,string
    #include<vector>//forvector

    #include"ftxui/component/captured_mouse.hpp"//forftxui
    #include"ftxui/component/component.hpp"//forSlider,Renderer,Vertical
    #include"ftxui/component/component_base.hpp"//forComponentBase
    #include"ftxui/component/screen_interactive.hpp"//forScreenInteractive
    #include"ftxui/dom/elements.hpp"//forElements,Element,operator|,separator,text,focusPositionRelative,size,border,flex,frame,bgcolor,gridbox,vbox,EQUAL,center,HEIGHT,WIDTH
    #include"ftxui/screen/color.hpp"//forColor

    usingnamespaceftxui;

    Elementmake_box(intx,inty){
    std::stringtitle="("+std::to_string(x)+","+std::to_string(y)+")";
    returntext(title)|center|size(WIDTH,EQUAL,18)|
    size(HEIGHT,EQUAL,9)|border|
    bgcolor(Color::HSV(x*255/15,255,y*255/15));
    };

    Elementmake_grid(){
    std::vector<Elements>rows;
    for(inti=0;i<15;i++){
    std::vector<Element>cols;
    for(intj=0;j<15;j++){
    cols.push_back(make_box(i,j));
    }
    rows.push_back(cols);
    }

    returngridbox(rows);
    };

    intmain(){
    floatfocus_x=0.5f;
    floatfocus_y=0.5f;

    autoslider_x=Slider("x",&focus_x,0.f,1.f,0.01f);
    autoslider_y=Slider("y",&focus_y,0.f,1.f,0.01f);

    autorenderer=Renderer(
    Container::Vertical({
    slider_x,
    slider_y,
    }),
    [&]{
    autotitle="focusPositionRelative("+//
    std::to_string(focus_x)+","+//
    std::to_string(focus_y)+")";//
    returnvbox({
    text(title),
    separator(),
    slider_x->Render(),
    slider_y->Render(),
    separator(),
    make_grid()|focusPositionRelative(focus_x,focus_y)|
    frame|flex,
    })|
    border;
    });

    autoscreen=ScreenInteractive::Fullscreen();
    screen.Loop(renderer);

    return0;
    }