Modify signature of Container::Tab(...) (#92)

Take selector at the end to get more pleasing results with clang-format.
This commit is contained in:
Arthur Sonzogni 2021-05-15 02:32:42 +02:00 committed by GitHub
parent 2723616dc8
commit 7daeac25c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 29 deletions

View File

@ -337,13 +337,15 @@ int main(int argc, const char* argv[]) {
L"htop", L"color", L"spinner", L"gauge", L"compiler",
};
auto tab_selection = Toggle(&tab_entries, &tab_index);
auto tab_content = Container::Tab(&tab_index, {
auto tab_content = Container::Tab(
{
htop,
color_tab_renderer,
spinner_tab_renderer,
gauge_component,
compiler_renderer,
});
},
&tab_index);
auto main_container = Container::Vertical({
tab_selection,

View File

@ -66,10 +66,12 @@ int main(int argc, const char* argv[]) {
border;
});
auto main_container = Container::Tab(&depth, {
auto main_container = Container::Tab(
{
depth_0_renderer,
depth_1_renderer,
});
},
&depth);
auto main_renderer = Renderer(main_container, [&] {
Element document = depth_0_renderer->Render();

View File

@ -41,11 +41,12 @@ int main(int argc, const char* argv[]) {
};
int tab_3_selected = 0;
auto tab_container = Container::Tab(
&tab_selected, {
{
Radiobox(&tab_1_entries, &tab_1_selected),
Radiobox(&tab_2_entries, &tab_2_selected),
Radiobox(&tab_3_entries, &tab_3_selected),
});
},
&tab_selected);
auto container = Container::Vertical({
tab_toggle,

View File

@ -41,11 +41,12 @@ int main(int argc, const char* argv[]) {
};
int tab_3_selected = 0;
auto tab_container = Container::Tab(
&tab_selected, {
{
Radiobox(&tab_1_entries, &tab_1_selected),
Radiobox(&tab_2_entries, &tab_2_selected),
Radiobox(&tab_3_entries, &tab_3_selected),
});
},
&tab_selected);
auto container = Container::Horizontal({
tab_menu,

View File

@ -36,7 +36,7 @@ Component Slider(StringRef label, T* value, T min, T max, T increment);
namespace Container {
Component Vertical(Components children);
Component Horizontal(Components children);
Component Tab(int* selector, Components children);
Component Tab(Components children, int* selector);
} // namespace Container
} // namespace ftxui

View File

@ -18,7 +18,7 @@ class ContainerBase : public ComponentBase {
static Component Horizontal(Components children);
static Component Tab(int* selector);
static Component Tab(int* selector, Components children);
static Component Tab(Components children, int* selector);
~ContainerBase() override = default;

View File

@ -62,15 +62,15 @@ Component Horizontal(Components children) {
///
/// ```cpp
/// int tab_drawn = 0;
/// auto container = Container::Tab(&tab_drawn, {
/// auto container = Container::Tab({
/// children_1,
/// children_2,
/// children_3,
/// children_4,
/// });
/// }, &tab_drawn);
/// ```
Component Tab(int* selector, Components children) {
return ContainerBase::Tab(selector, std::move(children));
Component Tab(Components children, int* selector) {
return ContainerBase::Tab(std::move(children), selector);
}
} // namespace Container
@ -107,11 +107,11 @@ Component ContainerBase::Horizontal(Components children) {
// static
Component ContainerBase::Tab(int* selector) {
return Tab(selector, {});
return Tab({}, selector);
}
// static
Component ContainerBase::Tab(int* selector, Components children) {
Component ContainerBase::Tab(Components children, int* selector) {
auto container = std::make_shared<ContainerBase>();
container->selector_ = selector;
container->event_handler_ = &ContainerBase::TabEvent;