resizable_split.cpp
ftxui/component/component_options.hpp
ftxui/dom/direction.hpp
ftxui/util/ref.hpp
functional
utility
ftxui/component/captured_mouse.hpp
ftxui/component/component.hpp
ftxui/component/component_base.hpp
ftxui/component/event.hpp
ftxui/component/mouse.hpp
ftxui/dom/elements.hpp
ftxui/screen/box.hpp
ftxui/component/animation.hpp
ftxui/component/captured_mouse.hpp
ftxui/component/component.hpp
ftxui/component/component_base.hpp
ftxui/component/component_options.hpp
ftxui/component/event.hpp
ftxui/component/mouse.hpp
ftxui/dom/canvas.hpp
ftxui/dom/deprecated.hpp
ftxui/dom/direction.hpp
ftxui/dom/elements.hpp
ftxui/dom/flexbox_config.hpp
ftxui/dom/linear_gradient.hpp
ftxui/dom/node.hpp
ftxui/dom/requirement.hpp
ftxui/dom/selection.hpp
ftxui/screen/box.hpp
ftxui/screen/color.hpp
ftxui/screen/image.hpp
ftxui/screen/pixel.hpp
ftxui/screen/screen.hpp
ftxui/screen/string.hpp
ftxui/screen/terminal.hpp
ftxui/util/autoreset.hpp
ftxui/util/ref.hpp
src/ftxui/component/resizable_split.cpp
chrono
cstddef
cstdint
ftxui/dom/take_any_args.hpp
functional
memory
optional
sstream
string
unordered_map
utility
variant
vector
ftxui

    //Copyright2021ArthurSonzogni.Allrightsreserved.
    //UseofthissourcecodeisgovernedbytheMITlicensethatcanbefoundin
    //theLICENSEfile.
    #include<ftxui/component/component_options.hpp>//forResizableSplitOption
    #include<ftxui/dom/direction.hpp>//forDirection,Direction::Down,Direction::Left,Direction::Right,Direction::Up
    #include<ftxui/util/ref.hpp>//forRef
    #include<functional>//forfunction
    #include<utility>//formove

    #include"ftxui/component/captured_mouse.hpp"//forCapturedMouse
    #include"ftxui/component/component.hpp"//forHorizontal,Make,ResizableSplit,ResizableSplitBottom,ResizableSplitLeft,ResizableSplitRight,ResizableSplitTop
    #include"ftxui/component/component_base.hpp"//forComponent,ComponentBase
    #include"ftxui/component/event.hpp"//forEvent
    #include"ftxui/component/mouse.hpp"//forMouse,Mouse::Left,Mouse::Pressed,Mouse::Released
    #include"ftxui/dom/elements.hpp"//foroperator|,reflect,Element,size,EQUAL,xflex,yflex,hbox,vbox,HEIGHT,WIDTH,text
    #include"ftxui/screen/box.hpp"//forBox

    namespaceftxui{
    namespace{

    classResizableSplitBase:publicComponentBase{
    public:
    explicitResizableSplitBase(ResizableSplitOptionoptions)
    :options_(std::move(options)){
    switch(options_->direction()){
    caseDirection::Left:
    Add(Container::Horizontal({
    options_->main,
    options_->back,
    }));
    break;
    caseDirection::Right:
    Add(Container::Horizontal({
    options_->back,
    options_->main,
    }));
    break;
    caseDirection::Up:
    Add(Container::Vertical({
    options_->main,
    options_->back,
    }));
    break;
    caseDirection::Down:
    Add(Container::Vertical({
    options_->back,
    options_->main,
    }));
    break;
    }
    }

    boolOnEvent(Eventevent)final{
    if(event.is_mouse()){
    returnOnMouseEvent(std::move(event));
    }
    returnComponentBase::OnEvent(std::move(event));
    }

    boolOnMouseEvent(Eventevent){
    if(captured_mouse_&&event.mouse().motion==Mouse::Released){
    captured_mouse_.reset();
    returntrue;
    }

    if(event.mouse().button==Mouse::Left&&
    event.mouse().motion==Mouse::Pressed&&
    separator_box_.Contain(event.mouse().x,event.mouse().y)&&
    !captured_mouse_){
    captured_mouse_=CaptureMouse(event);
    returntrue;
    }

    if(!captured_mouse_){
    returnComponentBase::OnEvent(event);
    }

    switch(options_->direction()){
    caseDirection::Left:
    options_->main_size()=std::max(0,event.mouse().x-box_.x_min);
    returntrue;
    caseDirection::Right:
    options_->main_size()=std::max(0,box_.x_max-event.mouse().x);
    returntrue;
    caseDirection::Up:
    options_->main_size()=std::max(0,event.mouse().y-box_.y_min);
    returntrue;
    caseDirection::Down:
    options_->main_size()=std::max(0,box_.y_max-event.mouse().y);
    returntrue;
    }

    //NOTREACHED()
    returnfalse;
    }

    ElementOnRender()final{
    switch(options_->direction()){
    caseDirection::Left:
    returnRenderLeft();
    caseDirection::Right:
    returnRenderRight();
    caseDirection::Up:
    returnRenderTop();
    caseDirection::Down:
    returnRenderBottom();
    }
    //NOTREACHED()
    returntext("unreacheable");
    }

    ElementRenderLeft(){
    returnhbox({
    options_->main->Render()|
    size(WIDTH,EQUAL,options_->main_size()),
    options_->separator_func()|reflect(separator_box_),
    options_->back->Render()|xflex,
    })|
    reflect(box_);
    }

    ElementRenderRight(){
    returnhbox({
    options_->back->Render()|xflex,
    options_->separator_func()|reflect(separator_box_),
    options_->main->Render()|
    size(WIDTH,EQUAL,options_->main_size()),
    })|
    reflect(box_);
    }

    ElementRenderTop(){
    returnvbox({
    options_->main->Render()|
    size(HEIGHT,EQUAL,options_->main_size()),
    options_->separator_func()|reflect(separator_box_),
    options_->back->Render()|yflex,
    })|
    reflect(box_);
    }

    ElementRenderBottom(){
    returnvbox({
    options_->back->Render()|yflex,
    options_->separator_func()|reflect(separator_box_),
    options_->main->Render()|
    size(HEIGHT,EQUAL,options_->main_size()),
    })|
    reflect(box_);
    }

    private:
    Ref<ResizableSplitOption>options_;
    CapturedMousecaptured_mouse_;
    Boxseparator_box_;
    Boxbox_;
    };

    }//namespace

    ///@briefAsplitinbetweentwocomponents.
    ///@paramoptionsalltheparameters.
    ///
    ///###Example
    ///
    ///```cpp
    ///autoleft=Renderer([]{returntext("Left")|center;});
    ///autoright=Renderer([]{returntext("right")|center;});
    ///intleft_size=10;
    ///autocomponent=ResizableSplit({
    ///.main=left,
    ///.back=right,
    ///.direction=Direction::Left,
    ///.main_size=&left_size,
    ///.separator_func=[]{returnseparatorDouble();},
    ///});
    ///```
    ///
    ///###Output
    ///
    ///```bash
    ///║
    ///left║right
    ///║
    ///```
    ComponentResizableSplit(ResizableSplitOptionoptions){
    returnMake<ResizableSplitBase>(std::move(options));
    }

    ///@briefAnhorizontalsplitinbetweentwocomponents,configurableusingthe
    ///mouse.
    ///@parammainThemaincomponentofsize|main_size|,ontheleft.
    ///@parambackThebackcomponenttakingtheremainingsize,ontheright.
    ///@parammain_sizeThesizeofthe|main|component.
    ///@ingroupcomponent
    ///
    ///###Example
    ///
    ///```cpp
    ///autoscreen=ScreenInteractive::Fullscreen();
    ///intleft_size=10;
    ///autoleft=Renderer([]{returntext("Left")|center;});
    ///autoright=Renderer([]{returntext("right")|center;});
    ///autosplit=ResizableSplitLeft(left,right,&left_size);
    ///screen.Loop(split);
    ///```
    ///
    ///###Output
    ///
    ///```bash
    ///│
    ///left│right
    ///│
    ///```
    ComponentResizableSplitLeft(Componentmain,Componentback,int*main_size){
    returnResizableSplit({
    std::move(main),
    std::move(back),
    Direction::Left,
    main_size,
    });
    }

    ///@briefAnhorizontalsplitinbetweentwocomponents,configurableusingthe
    ///mouse.
    ///@parammainThemaincomponentofsize|main_size|,ontheright.
    ///@parambackThebackcomponenttakingtheremainingsize,ontheleft.
    ///@parammain_sizeThesizeofthe|main|component.
    ///@ingroupcomponent
    ///
    ///###Example
    ///
    ///```cpp
    ///autoscreen=ScreenInteractive::Fullscreen();
    ///intright_size=10;
    ///autoleft=Renderer([]{returntext("Left")|center;});
    ///autoright=Renderer([]{returntext("right")|center;});
    ///autosplit=ResizableSplitRight(right,left,&right_size)
    ///screen.Loop(split);
    ///```
    ///
    ///###Output
    ///
    ///```bash
    ///│
    ///left│right
    ///│
    ///```
    ComponentResizableSplitRight(Componentmain,Componentback,int*main_size){
    returnResizableSplit({
    std::move(main),
    std::move(back),
    Direction::Right,
    main_size,
    });
    }

    ///@briefAnverticalsplitinbetweentwocomponents,configurableusingthe
    ///mouse.
    ///@parammainThemaincomponentofsize|main_size|,onthetop.
    ///@parambackThebackcomponenttakingtheremainingsize,onthebottom.
    ///@parammain_sizeThesizeofthe|main|component.
    ///@ingroupcomponent
    ///
    ///###Example
    ///
    ///```cpp
    ///autoscreen=ScreenInteractive::Fullscreen();
    ///inttop_size=1;
    ///autotop=Renderer([]{returntext("Top")|center;});
    ///autobottom=Renderer([]{returntext("Bottom")|center;});
    ///autosplit=ResizableSplitTop(top,bottom,&top_size)
    ///screen.Loop(split);
    ///```
    ///
    ///###Output
    ///
    ///```bash
    ///top
    ///────────────
    ///bottom
    ///```
    ComponentResizableSplitTop(Componentmain,Componentback,int*main_size){
    returnResizableSplit({
    std::move(main),
    std::move(back),
    Direction::Up,
    main_size,
    });
    }

    ///@briefAnverticalsplitinbetweentwocomponents,configurableusingthe
    ///mouse.
    ///@parammainThemaincomponentofsize|main_size|,onthebottom.
    ///@parambackThebackcomponenttakingtheremainingsize,onthetop.
    ///@parammain_sizeThesizeofthe|main|component.
    ///@ingroupcomponent
    ///
    ///###Example
    ///
    ///```cpp
    ///autoscreen=ScreenInteractive::Fullscreen();
    ///intbottom_size=1;
    ///autotop=Renderer([]{returntext("Top")|center;});
    ///autobottom=Renderer([]{returntext("Bottom")|center;});
    ///autosplit=ResizableSplit::Bottom(bottom,top,&bottom_size)
    ///screen.Loop(split);
    ///```
    ///
    ///###Output
    ///
    ///```bash
    ///top
    ///────────────
    ///bottom
    ///```
    ComponentResizableSplitBottom(Componentmain,Componentback,int*main_size){
    returnResizableSplit({
    std::move(main),
    std::move(back),
    Direction::Down,
    main_size,
    });
    }

    }//namespaceftxui