dropdown.cpp
ftxui/component/event.hpp
functional
string
utility
ftxui/component/component.hpp
ftxui/component/component_base.hpp
ftxui/component/component_options.hpp
ftxui/dom/elements.hpp
ftxui/screen/util.hpp
ftxui/util/ref.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/dropdown.cpp
ftxui/screen/util.hpp
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/event.hpp>
    #include<functional>//forfunction
    #include<string>//forstring

    #include<utility>
    #include"ftxui/component/component.hpp"//forMaybe,Checkbox,Make,Radiobox,Vertical,Dropdown
    #include"ftxui/component/component_base.hpp"//forComponent,ComponentBase
    #include"ftxui/component/component_options.hpp"//forCheckboxOption,EntryState
    #include"ftxui/dom/elements.hpp"//foroperator|,Element,border,filler,operator|=,separator,size,text,vbox,frame,vscroll_indicator,hbox,HEIGHT,LESS_THAN,bold,inverted
    #include"ftxui/screen/util.hpp"//forclamp
    #include"ftxui/util/ref.hpp"//forConstStringListRef

    namespaceftxui{

    ///@briefAdropdownmenu.
    ///@ingroupcomponent
    ///@paramentriesThelistofentriestodisplay.
    ///@paramselectedTheindexoftheselectedentry.
    ComponentDropdown(ConstStringListRefentries,int*selected){
    DropdownOptionoption;
    option.radiobox.entries=std::move(entries);
    option.radiobox.selected=selected;
    returnDropdown(option);
    }

    ///@briefAdropdownmenu.
    ///@ingroupcomponent
    ///@paramoptionTheoptionsforthedropdown.
    //NOLINTNEXTLINE
    ComponentDropdown(DropdownOptionoption){
    classImpl:publicComponentBase,publicDropdownOption{
    public:
    explicitImpl(DropdownOptionoption):DropdownOption(std::move(option)){
    FillDefault();
    checkbox_=Checkbox(checkbox);
    radiobox_=Radiobox(radiobox);

    Add(Container::Vertical({
    checkbox_,
    Maybe(radiobox_,checkbox.checked),
    }));
    }

    ElementOnRender()override{
    selected_=
    util::clamp(radiobox.selected(),0,int(radiobox.entries.size())-1);
    selected_=util::clamp(selected_(),0,int(radiobox.entries.size())-1);

    if(selected_()>=0&&selected_()<int(radiobox.entries.size())){
    title_=radiobox.entries[selected_()];
    }

    returntransform(*open_,checkbox_->Render(),radiobox_->Render());
    }

    //Switchfocusinbetweenthecheckboxandtheradioboxwhenselectingit.
    boolOnEvent(ftxui::Eventevent)override{
    constboolopen_old=open_();
    constintselected_old=selected_();
    boolhandled=ComponentBase::OnEvent(event);

    //Transferfocustotheradioboxwhenthedropdownisopened.
    if(!open_old&&open_()){
    radiobox_->TakeFocus();
    }

    //Auto-closethedropdownwhentheuserselectsanitem,eveniftheitem
    //itthesameasthepreviousone.
    if(open_old&&open_()){
    constboolshould_close=
    (selected_()!=selected_old)||//
    (event==Event::Return)||//
    (event==Event::Character(''))||//
    (event==Event::Escape)||//
    (event.is_mouse()&&event.mouse().button==Mouse::Left&&
    event.mouse().motion==Mouse::Pressed);

    if(should_close){
    checkbox_->TakeFocus();
    open_=false;
    handled=true;
    }
    }

    returnhandled;
    }

    voidFillDefault(){
    open_=checkbox.checked;
    selected_=radiobox.selected;
    checkbox.checked=&*open_;
    radiobox.selected=&*selected_;
    checkbox.label=&title_;

    if(!checkbox.transform){
    checkbox.transform=[](constEntryState&s){
    autoprefix=text(s.state?"↓":"→");//NOLINT
    autot=text(s.label);
    if(s.active){
    t|=bold;
    }
    if(s.focused){
    t|=inverted;
    }
    returnhbox({prefix,t});
    };
    }

    if(!transform){
    transform=[](boolis_open,Elementcheckbox_element,
    Elementradiobox_element){
    if(is_open){
    constintmax_height=12;
    returnvbox({
    std::move(checkbox_element),
    separator(),
    std::move(radiobox_element)|vscroll_indicator|frame|
    size(HEIGHT,LESS_THAN,max_height),
    })|
    border;
    }
    returnvbox({std::move(checkbox_element),filler()})|border;
    };
    }
    }

    private:
    Ref<bool>open_;
    Ref<int>selected_;
    Componentcheckbox_;
    Componentradiobox_;
    std::stringtitle_;
    };

    returnMake<Impl>(option);
    }

    }//namespaceftxui