util.cpp
algorithm
functional
memory
utility
ftxui/dom/elements.hpp
ftxui/dom/node.hpp
ftxui/dom/requirement.hpp
ftxui/screen/box.hpp
ftxui/screen/screen.hpp
ftxui/screen/terminal.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/dom/util.cpp
algorithm
cstddef
cstdint
ftxui/dom/take_any_args.hpp
functional
memory
optional
sstream
string
unordered_map
utility
variant
vector
ftxui

    //Copyright2020ArthurSonzogni.Allrightsreserved.
    //UseofthissourcecodeisgovernedbytheMITlicensethatcanbefoundin
    //theLICENSEfile.
    #include<algorithm>//formin
    #include<functional>//forfunction
    #include<memory>//for__shared_ptr_access,make_unique
    #include<utility>//formove

    #include"ftxui/dom/elements.hpp"//forElement,Decorator,Elements,operator|,Fit,emptyElement,nothing,operator|=
    #include"ftxui/dom/node.hpp"//forNode,Node::Status
    #include"ftxui/dom/requirement.hpp"//forRequirement
    #include"ftxui/screen/box.hpp"//forBox
    #include"ftxui/screen/screen.hpp"//forFull
    #include"ftxui/screen/terminal.hpp"//forDimensions

    namespaceftxui{

    namespace{
    Decoratorcompose(Decoratora,Decoratorb){
    return[a=std::move(a),b=std::move(b)](Elementelement){
    returnb(a(std::move(element)));
    };
    }
    }//namespace

    ///@briefAdecorationdoingabsolutelynothing.
    ///@ingroupdom
    Elementnothing(Elementelement){
    returnelement;
    }

    ///@briefComposetwodecoratorintoone.
    ///@ingroupdom
    ///
    ///###Example
    ///
    ///```cpp
    ///autodecorator=bold|blink;
    ///```
    Decoratoroperator|(Decoratora,Decoratorb){
    returncompose(std::move(a),//
    std::move(b));
    }

    ///@briefFromasetofelement,applyadecoratortoeveryelements.
    ///@returnthesetofdecoratedelement.
    ///@ingroupdom
    Elementsoperator|(Elementselements,Decoratordecorator){//NOLINT
    Elementsoutput;
    output.reserve(elements.size());
    for(auto&it:elements){
    output.push_back(std::move(it)|decorator);
    }
    returnoutput;
    }

    ///@briefFromanelement,applyadecorator.
    ///@returnthedecoratedelement.
    ///@ingroupdom
    ///
    ///###Example
    ///
    ///Bothoftheseareequivalent:
    ///```cpp
    ///bold(text("Hello"));
    ///```
    ///```cpp
    ///text("Hello")|bold;
    ///```
    Elementoperator|(Elementelement,Decoratordecorator){//NOLINT
    returndecorator(std::move(element));
    }

    ///@briefApplyadecoratortoanelement.
    ///@returnthedecoratedelement.
    ///@ingroupdom
    ///
    ///###Example
    ///
    ///Bothoftheseareequivalent:
    ///```cpp
    ///autoelement=text("Hello");
    ///element|=bold;
    ///```
    Element&operator|=(Element&e,Decoratord){
    e=e|std::move(d);
    returne;
    }

    ///Theminimaldimensionthatwillfitthegivenelement.
    ///@seeFixed
    ///@seeFull
    DimensionsDimension::Fit(Element&e,boolextend_beyond_screen){
    constDimensionsfullsize=Dimension::Full();
    Boxbox;
    box.x_min=0;
    box.y_min=0;
    box.x_max=fullsize.dimx;
    box.y_max=fullsize.dimy;

    Node::Statusstatus;
    e->Check(&status);
    constintmax_iteration=20;
    while(status.need_iteration&&status.iteration<max_iteration){
    e->ComputeRequirement();

    //Don'tgivetheelementmorespacethanitneeds:
    box.x_max=std::min(box.x_max,e->requirement().min_x);
    box.y_max=e->requirement().min_y;
    if(!extend_beyond_screen){
    box.y_max=std::min(box.y_max,fullsize.dimy);
    }

    e->SetBox(box);
    status.need_iteration=false;
    status.iteration++;
    e->Check(&status);

    if(!status.need_iteration){
    break;
    }
    //Increasethesizeoftheboxuntilitfits...
    box.x_max=std::min(e->requirement().min_x,fullsize.dimx);
    box.y_max=e->requirement().min_y;

    //...butdon'tgobeyondthescreensize:
    if(!extend_beyond_screen){
    box.y_max=std::min(box.y_max,fullsize.dimy);
    }
    }

    return{
    box.x_max,
    box.y_max,
    };
    }

    ///Anelementofsize0x0drawingnothing.
    ///@ingroupdom
    ElementemptyElement(){
    classImpl:publicNode{
    voidComputeRequirement()override{
    requirement_.min_x=0;
    requirement_.min_y=0;
    }
    };
    returnstd::make_unique<Impl>();
    }

    }//namespaceftxui