component.cpp
algorithm
cassert
cstddef
iterator
memory
utility
vector
ftxui/component/captured_mouse.hpp
ftxui/component/component.hpp
ftxui/component/component_base.hpp
ftxui/component/event.hpp
ftxui/component/screen_interactive.hpp
ftxui/dom/elements.hpp
ftxui/dom/node.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/component/receiver.hpp
ftxui/component/screen_interactive.hpp
ftxui/component/task.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/component.cpp
algorithm
atomic
cassert
chrono
condition_variable
cstddef
cstdint
ftxui/dom/take_any_args.hpp
functional
iterator
memory
mutex
optional
queue
sstream
string
thread
unordered_map
utility
variant
vector
ftxui
ftxui::animation

    //Copyright2020ArthurSonzogni.Allrightsreserved.
    //UseofthissourcecodeisgovernedbytheMITlicensethatcanbefoundin
    //theLICENSEfile.
    #include<algorithm>//forfind_if
    #include<cassert>//forassert
    #include<cstddef>//forsize_t
    #include<iterator>//forbegin,end
    #include<memory>//forunique_ptr,make_unique
    #include<utility>//formove
    #include<vector>//forvector,__alloc_traits<>::value_type

    #include"ftxui/component/captured_mouse.hpp"//forCapturedMouse,CapturedMouseInterface
    #include"ftxui/component/component.hpp"
    #include"ftxui/component/component_base.hpp"//forComponentBase,Components
    #include"ftxui/component/event.hpp"//forEvent
    #include"ftxui/component/screen_interactive.hpp"//forComponent,ScreenInteractive
    #include"ftxui/dom/elements.hpp"//fortext,Element
    #include"ftxui/dom/node.hpp"//forNode,Elements
    #include"ftxui/screen/box.hpp"//forBox

    namespaceftxui::animation{
    classParams;
    }//namespaceftxui::animation

    namespaceftxui{

    namespace{
    classCaptureMouseImpl:publicCapturedMouseInterface{};
    }//namespace

    ComponentBase::~ComponentBase(){
    DetachAllChildren();
    }

    ///@briefReturntheparentComponentBase,ornulifany.
    ///@seeDetach
    ///@seeParent
    ///@ingroupcomponent
    ComponentBase*ComponentBase::Parent()const{
    returnparent_;
    }

    ///@briefAccessthechildatindex`i`.
    ///@ingroupcomponent
    Component&ComponentBase::ChildAt(size_ti){
    assert(i<ChildCount());//NOLINT
    returnchildren_[i];
    }

    ///@briefReturnsthenumberofchildren.
    ///@ingroupcomponent
    size_tComponentBase::ChildCount()const{
    returnchildren_.size();
    }

    ///@briefReturnindexofthecomponentinitsparent.-1ifnoparent.
    ///@ingroupcomponent
    intComponentBase::Index()const{
    if(parent_==nullptr){
    return-1;
    }
    intindex=0;
    for(constComponent&child:parent_->children_){
    if(child.get()==this){
    returnindex;
    }
    index++;
    }
    return-1;//Notreached.
    }

    ///@briefAddachild.
    ///@@paramchildThechildtobeattached.
    ///@ingroupcomponent
    voidComponentBase::Add(Componentchild){
    child->Detach();
    child->parent_=this;
    children_.push_back(std::move(child));
    }

    ///@briefDetachthischildfromitsparent.
    ///@seeDetach
    ///@seeParent
    ///@ingroupcomponent
    voidComponentBase::Detach(){
    if(parent_==nullptr){
    return;
    }
    autoit=std::find_if(std::begin(parent_->children_),//
    std::end(parent_->children_),//
    [this](constComponent&that){//
    returnthis==that.get();
    });
    ComponentBase*parent=parent_;
    parent_=nullptr;
    parent->children_.erase(it);//Mightdelete|this|.
    }

    ///@briefRemoveallchildren.
    ///@ingroupcomponent
    voidComponentBase::DetachAllChildren(){
    while(!children_.empty()){
    children_[0]->Detach();
    }
    }

    ///@briefDrawthecomponent.
    ///Buildaftxui::Elementtobedrawnontheftxui::Screenrepresentingthis
    ///ftxui::ComponentBase.PleaseoverrideOnRender()tomodifytherendering.
    ///@ingroupcomponent
    ElementComponentBase::Render(){
    //Someusersmightcall`ComponentBase::Render()`from
    //`T::OnRender()`.Toavoidinfiniterecursion,weuseaflag.
    if(in_render){
    returnComponentBase::OnRender();
    }

    in_render=true;
    Elementelement=OnRender();
    in_render=false;

    classWrapper:publicNode{
    public:
    boolactive_=false;

    Wrapper(Elementchild,boolactive)
    :Node({std::move(child)}),active_(active){}

    voidSetBox(Boxbox)override{
    Node::SetBox(box);
    children_[0]->SetBox(box);
    }

    voidComputeRequirement()override{
    Node::ComputeRequirement();
    requirement_.focused.component_active=active_;
    }
    };

    returnstd::make_shared<Wrapper>(std::move(element),Active());
    }

    ///@briefDrawthecomponent.
    ///Buildaftxui::Elementtobedrawnontheftxi::Screenrepresentingthis
    ///ftxui::ComponentBase.Thisfunctionismeanstobeoverridden.
    ///@ingroupcomponent
    ElementComponentBase::OnRender(){
    if(children_.size()==1){
    returnchildren_.front()->Render();
    }

    returntext("Notimplementedcomponent");
    }

    ///@briefCalledinresponsetoanevent.
    ///@parameventTheevent.
    ///@returnTruewhentheeventhasbeenhandled.
    ///ThedefaultimplementationcalledOnEventoneverychilduntilonereturn
    ///true.Ifnonereturnstrue,returnfalse.
    ///@ingroupcomponent
    boolComponentBase::OnEvent(Eventevent){//NOLINT
    for(Component&child:children_){//NOLINT
    if(child->OnEvent(event)){
    returntrue;
    }
    }
    returnfalse;
    }

    ///@briefCalledinresponsetoananimationevent.
    ///@paramparamstheparametersoftheanimation
    ///Thedefaultimplementationdispatchtheeventtoeverychild.
    ///@ingroupcomponent
    voidComponentBase::OnAnimation(animation::Params&params){
    for(constComponent&child:children_){
    child->OnAnimation(params);
    }
    }

    ///@briefReturnthecurrentlyActivechild.
    ///@returnthecurrentlyActivechild.
    ///@ingroupcomponent
    ComponentComponentBase::ActiveChild(){
    for(auto&child:children_){
    if(child->Focusable()){
    returnchild;
    }
    }
    returnnullptr;
    }

    ///@briefReturntruewhenthecomponentcontainsfocusableelements.
    ///ThenonfocusableComponentswillbeskippedwhennavigatingusingthe
    ///keyboard.
    ///@ingroupcomponent
    boolComponentBase::Focusable()const{
    for(constComponent&child:children_){//NOLINT
    if(child->Focusable()){
    returntrue;
    }
    }
    returnfalse;
    }

    ///@briefReturnsiftheelementifthecurrentlyactivechildofitsparent.
    ///@ingroupcomponent
    boolComponentBase::Active()const{
    returnparent_==nullptr||parent_->ActiveChild().get()==this;
    }

    ///@briefReturnsiftheelementsiffocusedbytheuser.
    ///TruewhentheComponentBaseisfocusedbytheuser.AnelementisFocused
    ///whenitiswithallitsancestorstheActiveChild()oftheirparents,andit
    ///Focusable().
    ///@ingroupcomponent
    boolComponentBase::Focused()const{
    constauto*current=this;
    while(current&&current->Active()){
    current=current->parent_;
    }
    return!current&&Focusable();
    }

    ///@briefMakethe|child|tobethe"active"one.
    ///@paramchildthechildtobecomeactive.
    ///@ingroupcomponent
    voidComponentBase::SetActiveChild([[maybe_unused]]ComponentBase*child){}

    ///@briefMakethe|child|tobethe"active"one.
    ///@paramchildthechildtobecomeactive.
    ///@ingroupcomponent
    voidComponentBase::SetActiveChild(Componentchild){//NOLINT
    SetActiveChild(child.get());
    }

    ///@briefConfigurealltheancestorstogivefocustothiscomponent.
    ///@ingroupcomponent
    voidComponentBase::TakeFocus(){
    ComponentBase*child=this;
    while(ComponentBase*parent=child->parent_){
    parent->SetActiveChild(child);
    child=parent;
    }
    }

    ///@briefTaketheCapturedMouseifavailable.Thereisonlyonecomponentof
    ///them.Itrepresentsacomponenttakingpriorityoverothers.
    ///@parameventTheevent
    ///@ingroupcomponent
    CapturedMouseComponentBase::CaptureMouse(constEvent&event){//NOLINT
    if(event.screen_){
    returnevent.screen_->CaptureMouse();
    }
    returnstd::make_unique<CaptureMouseImpl>();
    }

    }//namespaceftxui