examples/component/modal_dialog.cpp

    //Copyright2022ArthurSonzogni.Allrightsreserved.
    //UseofthissourcecodeisgovernedbytheMITlicensethatcanbefoundin
    //theLICENSEfile.
    #include<ftxui/component/component_options.hpp>//forButtonOption
    #include<ftxui/component/mouse.hpp>//forftxui
    #include<functional>//forfunction
    #include<memory>//forallocator,shared_ptr

    #include"ftxui/component/component.hpp"//forButton,operator|=,Renderer,Vertical,Modal
    #include"ftxui/component/screen_interactive.hpp"//forScreenInteractive,Component
    #include"ftxui/dom/elements.hpp"//foroperator|,separator,text,size,Element,vbox,border,GREATER_THAN,WIDTH,center,HEIGHT

    usingnamespaceftxui;

    autobutton_style=ButtonOption::Animated();

    //Definitionofthemaincomponent.Thedetailsarenotimportant.
    ComponentMainComponent(std::function<void()>show_modal,
    std::function<void()>exit){
    autocomponent=Container::Vertical({
    Button("Showmodal",show_modal,button_style),
    Button("Quit",exit,button_style),
    });
    //Polishhowthetwobuttonsarerendered:
    component|=Renderer([&](Elementinner){
    returnvbox({
    text("Maincomponent"),
    separator(),
    inner,
    })//
    |size(WIDTH,GREATER_THAN,15)//
    |size(HEIGHT,GREATER_THAN,15)//
    |border//
    |center;//
    });
    returncomponent;
    }

    //Definitionofthemodalcomponent.Thedetailsarenotimportant.
    ComponentModalComponent(std::function<void()>do_nothing,
    std::function<void()>hide_modal){
    autocomponent=Container::Vertical({
    Button("Donothing",do_nothing,button_style),
    Button("Quitmodal",hide_modal,button_style),
    });
    //Polishhowthetwobuttonsarerendered:
    component|=Renderer([&](Elementinner){
    returnvbox({
    text("Modalcomponent"),
    separator(),
    inner,
    })//
    |size(WIDTH,GREATER_THAN,30)//
    |border;//
    });
    returncomponent;
    }

    intmain(intargc,constchar*argv[]){
    autoscreen=ScreenInteractive::TerminalOutput();

    //Stateoftheapplication:
    boolmodal_shown=false;

    //Someactionsmodifyingthestate:
    autoshow_modal=[&]{modal_shown=true;};
    autohide_modal=[&]{modal_shown=false;};
    autoexit=screen.ExitLoopClosure();
    autodo_nothing=[&]{};

    //Instanciatethemainandmodalcomponents:
    automain_component=MainComponent(show_modal,exit);
    automodal_component=ModalComponent(do_nothing,hide_modal);

    //Usethe`Modal`functiontousetogetherthemaincomponentanditsmodal
    //window.The|modal_shown|booleancontrolswhetherthemodalisshownor
    //not.
    main_component|=Modal(modal_component,&modal_shown);

    screen.Loop(main_component);
    return0;
    }