examples/component/scrollbar.cpp

    //Copyright2023ArthurSonzogni.Allrightsreserved.
    //UseofthissourcecodeisgovernedbytheMITlicensethatcanbefoundin
    //theLICENSEfile.
    #include<ftxui/component/component.hpp>
    #include<ftxui/component/screen_interactive.hpp>

    usingnamespaceftxui;

    ComponentDummyWindowContent(){
    classImpl:publicComponentBase{
    private:
    floatscroll_x=0.1;
    floatscroll_y=0.1;

    public:
    Impl(){
    autocontent=Renderer([=]{
    conststd::stringlorem=
    "Loremipsumdolorsitamet,consecteturadipiscingelit,sed"
    "doeiusmodtemporincididuntutlaboreetdoloremagna"
    "aliqua.Utenimadminimveniam,quisnostrudexercitation"
    "ullamcolaborisnisiutaliquipexeacommodoconsequat.Duis"
    "auteiruredolorinreprehenderitinvoluptatevelitesse"
    "cillumdoloreeufugiatnullapariatur.Excepteursint"
    "occaecatcupidatatnonproident,suntinculpaquiofficia"
    "deseruntmollitanimidestlaborum.";
    returnvbox({
    text(lorem.substr(0,-1)),text(lorem.substr(5,-1)),text(""),
    text(lorem.substr(10,-1)),text(lorem.substr(15,-1)),text(""),
    text(lorem.substr(20,-1)),text(lorem.substr(25,-1)),text(""),
    text(lorem.substr(30,-1)),text(lorem.substr(35,-1)),text(""),
    text(lorem.substr(40,-1)),text(lorem.substr(45,-1)),text(""),
    text(lorem.substr(50,-1)),text(lorem.substr(55,-1)),text(""),
    text(lorem.substr(60,-1)),text(lorem.substr(65,-1)),text(""),
    text(lorem.substr(70,-1)),text(lorem.substr(75,-1)),text(""),
    text(lorem.substr(80,-1)),text(lorem.substr(85,-1)),text(""),
    text(lorem.substr(90,-1)),text(lorem.substr(95,-1)),text(""),
    text(lorem.substr(100,-1)),text(lorem.substr(105,-1)),text(""),
    text(lorem.substr(110,-1)),text(lorem.substr(115,-1)),text(""),
    text(lorem.substr(120,-1)),text(lorem.substr(125,-1)),text(""),
    text(lorem.substr(130,-1)),text(lorem.substr(135,-1)),text(""),
    text(lorem.substr(140,-1)),
    });
    });

    autoscrollable_content=Renderer(content,[&,content]{
    returncontent->Render()|focusPositionRelative(scroll_x,scroll_y)|
    frame|flex;
    });

    SliderOption<float>option_x;
    option_x.value=&scroll_x;
    option_x.min=0.f;
    option_x.max=1.f;
    option_x.increment=0.1f;
    option_x.direction=Direction::Right;
    option_x.color_active=Color::Blue;
    option_x.color_inactive=Color::BlueLight;
    autoscrollbar_x=Slider(option_x);

    SliderOption<float>option_y;
    option_y.value=&scroll_y;
    option_y.min=0.f;
    option_y.max=1.f;
    option_y.increment=0.1f;
    option_y.direction=Direction::Down;
    option_y.color_active=Color::Yellow;
    option_y.color_inactive=Color::YellowLight;
    autoscrollbar_y=Slider(option_y);

    Add(Container::Vertical({
    Container::Horizontal({
    scrollable_content,
    scrollbar_y,
    })|flex,
    Container::Horizontal({
    scrollbar_x,
    Renderer([]{returntext(L"x");}),
    }),
    }));
    }
    };
    returnMake<Impl>();
    }

    intmain(){
    autowindow_1=Window({
    .inner=DummyWindowContent(),
    .title="Firstwindow",
    .width=80,
    .height=30,
    });

    autowindow_2=Window({
    .inner=DummyWindowContent(),
    .title="Mywindow",
    .left=40,
    .top=20,
    .width=80,
    .height=30,
    });

    autowindow_container=Container::Stacked({
    window_1,
    window_2,
    });

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

    returnEXIT_SUCCESS;
    }