examples/component/flexbox_gallery.cpp

    //Copyright2020ArthurSonzogni.Allrightsreserved.
    //UseofthissourcecodeisgovernedbytheMITlicensethatcanbefoundin
    //theLICENSEfile.
    #include<stddef.h>//forsize_t
    #include<memory>//forshared_ptr,__shared_ptr_access,allocator
    #include<string>//forstring,basic_string,to_string,operator+,char_traits
    #include<vector>//forvector

    #include"ftxui/component/captured_mouse.hpp"//forftxui
    #include"ftxui/component/component.hpp"//forRadiobox,Vertical,Checkbox,Horizontal,Renderer,ResizableSplitBottom,ResizableSplitRight
    #include"ftxui/component/component_base.hpp"//forComponentBase
    #include"ftxui/component/screen_interactive.hpp"//forScreenInteractive
    #include"ftxui/dom/elements.hpp"//fortext,window,operator|,vbox,hbox,Element,flexbox,bgcolor,filler,flex,size,border,hcenter,color,EQUAL,bold,dim,notflex,xflex_grow,yflex_grow,HEIGHT,WIDTH
    #include"ftxui/dom/flexbox_config.hpp"//forFlexboxConfig,FlexboxConfig::AlignContent,FlexboxConfig::JustifyContent,FlexboxConfig::AlignContent::Center,FlexboxConfig::AlignItems,FlexboxConfig::Direction,FlexboxConfig::JustifyContent::Center,FlexboxConfig::Wrap
    #include"ftxui/screen/color.hpp"//forColor,Color::Black

    usingnamespaceftxui;

    intmain(){
    autoscreen=ScreenInteractive::Fullscreen();

    intdirection_index=0;
    intwrap_index=0;
    intjustify_content_index=0;
    intalign_items_index=0;
    intalign_content_index=0;

    std::vector<std::string>directions={
    "Row",
    "RowInversed",
    "Column",
    "ColumnInversed",
    };

    std::vector<std::string>wraps={
    "NoWrap",
    "Wrap",
    "WrapInversed",
    };

    std::vector<std::string>justify_content={
    "FlexStart","FlexEnd","Center","Stretch",
    "SpaceBetween","SpaceAround","SpaceEvenly",
    };

    std::vector<std::string>align_items={
    "FlexStart",
    "FlexEnd",
    "Center",
    "Stretch",
    };

    std::vector<std::string>align_content={
    "FlexStart","FlexEnd","Center","Stretch",
    "SpaceBetween","SpaceAround","SpaceEvenly",
    };

    autoradiobox_direction=Radiobox(&directions,&direction_index);
    autoradiobox_wrap=Radiobox(&wraps,&wrap_index);
    autoradiobox_justify_content=
    Radiobox(&justify_content,&justify_content_index);
    autoradiobox_align_items=Radiobox(&align_items,&align_items_index);
    autoradiobox_align_content=Radiobox(&align_content,&align_content_index);

    boolelement_xflex_grow=false;
    boolelement_yflex_grow=false;
    boolgroup_xflex_grow=true;
    boolgroup_yflex_grow=true;
    autocheckbox_element_xflex_grow=
    Checkbox("element|=xflex_grow",&element_xflex_grow);
    autocheckbox_element_yflex_grow=
    Checkbox("element|=yflex_grow",&element_yflex_grow);
    autocheckbox_group_xflex_grow=
    Checkbox("group|=xflex_grow",&group_xflex_grow);
    autocheckbox_group_yflex_grow=
    Checkbox("group|=yflex_grow",&group_yflex_grow);

    automake_box=[&](size_tdimx,size_tdimy,size_tindex){
    std::stringtitle=std::to_string(dimx)+"x"+std::to_string(dimy);
    autoelement=window(text(title)|hcenter|bold,
    text(std::to_string(index))|hcenter|dim)|
    size(WIDTH,EQUAL,dimx)|size(HEIGHT,EQUAL,dimy)|
    bgcolor(Color::HSV(index*25,255,255))|
    color(Color::Black);
    if(element_xflex_grow)
    element=element|xflex_grow;
    if(element_yflex_grow)
    element=element|yflex_grow;
    returnelement;
    };

    autocontent_renderer=Renderer([&]{
    FlexboxConfigconfig;
    config.direction=static_cast<FlexboxConfig::Direction>(direction_index);
    config.wrap=static_cast<FlexboxConfig::Wrap>(wrap_index);
    config.justify_content=
    static_cast<FlexboxConfig::JustifyContent>(justify_content_index);
    config.align_items=
    static_cast<FlexboxConfig::AlignItems>(align_items_index);
    config.align_content=
    static_cast<FlexboxConfig::AlignContent>(align_content_index);

    autogroup=flexbox(
    {
    make_box(8,4,0),
    make_box(9,6,1),
    make_box(11,6,2),
    make_box(10,4,3),
    make_box(13,7,4),
    make_box(12,4,5),
    make_box(12,5,6),
    make_box(10,4,7),
    make_box(12,4,8),
    make_box(10,5,9),
    },
    config);

    group=group|bgcolor(Color::Black);

    group=group|notflex;

    if(!group_xflex_grow)
    group=hbox(group,filler());
    if(!group_yflex_grow)
    group=vbox(group,filler());

    group=group|flex;
    returngroup;
    });

    autocenter=FlexboxConfig()
    .Set(FlexboxConfig::JustifyContent::Center)
    .Set(FlexboxConfig::AlignContent::Center);
    intspace_right=10;
    intspace_bottom=1;
    content_renderer=ResizableSplitRight(
    Renderer([&]{returnflexbox({text("resizable")},center);}),
    content_renderer,&space_right);
    content_renderer=ResizableSplitBottom(
    Renderer([&]{returnflexbox({text("resizable")},center);}),
    content_renderer,&space_bottom);

    automain_container=Container::Vertical({
    Container::Horizontal({
    radiobox_direction,
    radiobox_wrap,
    Container::Vertical({
    checkbox_element_xflex_grow,
    checkbox_element_yflex_grow,
    checkbox_group_xflex_grow,
    checkbox_group_yflex_grow,
    }),
    }),
    Container::Horizontal({
    radiobox_justify_content,
    radiobox_align_items,
    radiobox_align_content,
    }),
    content_renderer,
    });

    automain_renderer=Renderer(main_container,[&]{
    returnvbox({
    vbox({hbox({
    window(text("FlexboxConfig::Direction"),
    radiobox_direction->Render()),
    window(text("FlexboxConfig::Wrap"),radiobox_wrap->Render()),
    window(text("Misc:"),
    vbox({
    checkbox_element_xflex_grow->Render(),
    checkbox_element_yflex_grow->Render(),
    checkbox_group_xflex_grow->Render(),
    checkbox_group_yflex_grow->Render(),
    })),
    }),
    hbox({
    window(text("FlexboxConfig::JustifyContent"),
    radiobox_justify_content->Render()),
    window(text("FlexboxConfig::AlignItems"),
    radiobox_align_items->Render()),
    window(text("FlexboxConfig::AlignContent"),
    radiobox_align_content->Render()),
    })}),
    content_renderer->Render()|flex|border,
    });
    });

    screen.Loop(main_renderer);

    return0;
    }