diff --git a/include/wxUI/ForEach.h b/include/wxUI/ForEach.h index 44016d8..4d78bf5 100644 --- a/include/wxUI/ForEach.h +++ b/include/wxUI/ForEach.h @@ -89,10 +89,13 @@ struct ForEach { Function createFunction; }; -// initializer_list is like a string_view, we want a copy. So deduce as vector so we have a copy template ForEach(Range&&, Function&&) -> ForEach; +template +ForEach(wxSizerFlags const& flags, Range&&, Function&&) -> ForEach; + +// initializer_list is like a string_view, we want a copy. So deduce as vector so we have a copy template ForEach(std::initializer_list, Function&&) -> ForEach, Function>; diff --git a/tests/wxUI_ForEachTests.cpp b/tests/wxUI_ForEachTests.cpp index 280c167..639844b 100644 --- a/tests/wxUI_ForEachTests.cpp +++ b/tests/wxUI_ForEachTests.cpp @@ -446,6 +446,69 @@ TEST_CASE("ForEach") }); uut3.createAndAdd(&frame, &sizer, wxSizerFlags {}); } + SECTION("ForEach.Flags.lvalue.Vector.T") + { + auto data = std::vector { "A", "B", "C" }; + auto builder = [](auto name) { + return wxUI::Button { name }; + }; + { + wxFrame frame { nullptr, wxID_ANY, "" }; + auto sizer = wxBoxSizer(wxHORIZONTAL); + auto uut = wxUI::ForEach { + wxSizerFlags {}, + data, + [](auto name) { + return wxUI::Button { name }; + } + }; + uut.createAndAdd(&frame, &sizer, wxSizerFlags {}); + auto uut2 = wxUI::VForEach( + wxSizerFlags {}, + data, + [](auto name) { + return wxUI::Button { name }; + }); + uut2.createAndAdd(&frame, &sizer, wxSizerFlags {}); + auto uut3 = wxUI::HForEach( + wxSizerFlags {}, + data, + [](auto name) { + return wxUI::Button { name }; + }); + uut3.createAndAdd(&frame, &sizer, wxSizerFlags {}); + } + { + wxFrame frame { nullptr, wxID_ANY, "" }; + auto sizer = wxBoxSizer(wxHORIZONTAL); + auto uut = wxUI::ForEach { + wxSizerFlags {}, + std::vector { "A", "B", "C" }, + builder + }; + uut.createAndAdd(&frame, &sizer, wxSizerFlags {}); + auto uut2 = wxUI::VForEach( + wxSizerFlags {}, + std::vector { "A", "B", "C" }, + builder); + uut2.createAndAdd(&frame, &sizer, wxSizerFlags {}); + auto uut3 = wxUI::HForEach( + wxSizerFlags {}, + std::vector { "A", "B", "C" }, + builder); + uut3.createAndAdd(&frame, &sizer, wxSizerFlags {}); + } + { + wxFrame frame { nullptr, wxID_ANY, "" }; + auto sizer = wxBoxSizer(wxHORIZONTAL); + auto uut = wxUI::ForEach { wxSizerFlags {}, data, builder }; + uut.createAndAdd(&frame, &sizer, wxSizerFlags {}); + auto uut2 = wxUI::VForEach(wxSizerFlags {}, data, builder); + uut2.createAndAdd(&frame, &sizer, wxSizerFlags {}); + auto uut3 = wxUI::HForEach(wxSizerFlags {}, data, builder); + uut3.createAndAdd(&frame, &sizer, wxSizerFlags {}); + } + } SECTION("ForEach.Flags.Vector.Tuple") { wxFrame frame { nullptr, wxID_ANY, "" }; @@ -527,6 +590,69 @@ TEST_CASE("ForEach") }); uut3.createAndAdd(&frame, &sizer, wxSizerFlags {}); } + SECTION("ForEach.Flags.lvalue.Range.T") + { + auto data = std::vector { "A", "B", "C" } | std::views::filter([](auto str) { return str[0] == 'A'; }); + auto builder = [](auto name) { + return wxUI::Button { name }; + }; + { + wxFrame frame { nullptr, wxID_ANY, "" }; + auto sizer = wxBoxSizer(wxHORIZONTAL); + auto uut = wxUI::ForEach { + wxSizerFlags {}, + data, + [](auto name) { + return wxUI::Button { name }; + } + }; + uut.createAndAdd(&frame, &sizer, wxSizerFlags {}); + auto uut2 = wxUI::VForEach( + wxSizerFlags {}, + data, + [](auto name) { + return wxUI::Button { name }; + }); + uut2.createAndAdd(&frame, &sizer, wxSizerFlags {}); + auto uut3 = wxUI::HForEach( + wxSizerFlags {}, + data, + [](auto name) { + return wxUI::Button { name }; + }); + uut3.createAndAdd(&frame, &sizer, wxSizerFlags {}); + } + { + wxFrame frame { nullptr, wxID_ANY, "" }; + auto sizer = wxBoxSizer(wxHORIZONTAL); + auto uut = wxUI::ForEach { + wxSizerFlags {}, + std::vector { "A", "B", "C" }, + builder + }; + uut.createAndAdd(&frame, &sizer, wxSizerFlags {}); + auto uut2 = wxUI::VForEach( + wxSizerFlags {}, + std::vector { "A", "B", "C" }, + builder); + uut2.createAndAdd(&frame, &sizer, wxSizerFlags {}); + auto uut3 = wxUI::HForEach( + wxSizerFlags {}, + std::vector { "A", "B", "C" }, + builder); + uut3.createAndAdd(&frame, &sizer, wxSizerFlags {}); + } + { + wxFrame frame { nullptr, wxID_ANY, "" }; + auto sizer = wxBoxSizer(wxHORIZONTAL); + auto uut = wxUI::ForEach { wxSizerFlags {}, data, builder }; + uut.createAndAdd(&frame, &sizer, wxSizerFlags {}); + auto uut2 = wxUI::VForEach(wxSizerFlags {}, data, builder); + uut2.createAndAdd(&frame, &sizer, wxSizerFlags {}); + auto uut3 = wxUI::HForEach(wxSizerFlags {}, data, builder); + uut3.createAndAdd(&frame, &sizer, wxSizerFlags {}); + } + } SECTION("ForEach.Flags.Range.Tuple") { wxFrame frame { nullptr, wxID_ANY, "" }; @@ -608,6 +734,69 @@ TEST_CASE("ForEach") }); uut3.createAndAdd(&frame, &sizer, wxSizerFlags {}); } + SECTION("ForEach.Flags.lvalue.InitializerList.T") + { + auto data = { "A", "B", "C" }; + auto builder = [](auto name) { + return wxUI::Button { name }; + }; + { + wxFrame frame { nullptr, wxID_ANY, "" }; + auto sizer = wxBoxSizer(wxHORIZONTAL); + auto uut = wxUI::ForEach { + wxSizerFlags {}, + data, + [](auto name) { + return wxUI::Button { name }; + } + }; + uut.createAndAdd(&frame, &sizer, wxSizerFlags {}); + auto uut2 = wxUI::VForEach( + wxSizerFlags {}, + data, + [](auto name) { + return wxUI::Button { name }; + }); + uut2.createAndAdd(&frame, &sizer, wxSizerFlags {}); + auto uut3 = wxUI::HForEach( + wxSizerFlags {}, + data, + [](auto name) { + return wxUI::Button { name }; + }); + uut3.createAndAdd(&frame, &sizer, wxSizerFlags {}); + } + { + wxFrame frame { nullptr, wxID_ANY, "" }; + auto sizer = wxBoxSizer(wxHORIZONTAL); + auto uut = wxUI::ForEach { + wxSizerFlags {}, + std::vector { "A", "B", "C" }, + builder + }; + uut.createAndAdd(&frame, &sizer, wxSizerFlags {}); + auto uut2 = wxUI::VForEach( + wxSizerFlags {}, + std::vector { "A", "B", "C" }, + builder); + uut2.createAndAdd(&frame, &sizer, wxSizerFlags {}); + auto uut3 = wxUI::HForEach( + wxSizerFlags {}, + std::vector { "A", "B", "C" }, + builder); + uut3.createAndAdd(&frame, &sizer, wxSizerFlags {}); + } + { + wxFrame frame { nullptr, wxID_ANY, "" }; + auto sizer = wxBoxSizer(wxHORIZONTAL); + auto uut = wxUI::ForEach { wxSizerFlags {}, data, builder }; + uut.createAndAdd(&frame, &sizer, wxSizerFlags {}); + auto uut2 = wxUI::VForEach(wxSizerFlags {}, data, builder); + uut2.createAndAdd(&frame, &sizer, wxSizerFlags {}); + auto uut3 = wxUI::HForEach(wxSizerFlags {}, data, builder); + uut3.createAndAdd(&frame, &sizer, wxSizerFlags {}); + } + } SECTION("ForEach.Flags.InitializerList.Tuple") { wxFrame frame { nullptr, wxID_ANY, "" };