From f39b684188d1c701aba76aac3169507d52bdf0c4 Mon Sep 17 00:00:00 2001 From: Richard Powell Date: Fri, 30 Dec 2022 10:25:40 -0800 Subject: [PATCH 1/2] Changing from Sizer to Layout as it is a better name. --- CMakeLists.txt | 2 +- docs/src/docs/ProgrammersGuide.md | 10 +++--- examples/HelloWorld/HelloWorld.cpp | 8 ++--- include/wxUI/{Sizer.h => Layout.h} | 22 +++++++++++++ include/wxUI/Widget.h | 32 ++----------------- include/wxUI/wxUI.h | 2 +- tests/CMakeLists.txt | 2 +- ...UI_SizerTests.cpp => wxUI_LayoutTests.cpp} | 2 +- 8 files changed, 38 insertions(+), 42 deletions(-) rename include/wxUI/{Sizer.h => Layout.h} (92%) rename tests/{wxUI_SizerTests.cpp => wxUI_LayoutTests.cpp} (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1715a36..a794cdb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,9 +36,9 @@ add_library( include/wxUI/Button.h include/wxUI/CheckBox.h include/wxUI/Choice.h + include/wxUI/Layout.h include/wxUI/Menu.h include/wxUI/RadioBox.h - include/wxUI/Sizer.h include/wxUI/Text.h include/wxUI/TextCtrl.h include/wxUI/Widget.h diff --git a/docs/src/docs/ProgrammersGuide.md b/docs/src/docs/ProgrammersGuide.md index 92cfb6f..6971f4b 100644 --- a/docs/src/docs/ProgrammersGuide.md +++ b/docs/src/docs/ProgrammersGuide.md @@ -51,17 +51,17 @@ wxUI::Menu also allows nesting of menus. This allows complicated menus to be co The `wxUI::MenuBar` and related objects are generally "lazy" objects. They hold the details of the menu layout, but do not call any wxWidget primatives on construction. When `attachTo` a frame is invoked does the underlying logic construct the menu structure. -### Sizer +### Layout -The basics of `wxUI` layout is the "Sizer". You use a specific type of "Sizer", with the `VStack` and `HStack` being the most common. When a "Sizer" is set as the top level, it uses the layout as a sort of "blueprint" for stamping out the UI by constructing the ownership hierarchy and layout. +The basics of `wxUI` layout is the "Layout". You use a specific type of "Layout", with the `VStack` and `HStack` being the most common. When a "Layout" is set as the top level, it uses the layout as a sort of "blueprint" for stamping out the UI by constructing the ownership hierarchy and layout. ```cpp -{{{ examples/HelloWorld/HelloWorld.cpp wxUISizerBasic " // ..." }}} +{{{ examples/HelloWorld/HelloWorld.cpp wxUILayoutBasic " // ..." }}} ``` In the above example we have constructed a vertical layout stack that will use a `wxSizer` with the `wxSizerFlags` set to expand with a default border. Then the first item in the stack is a second layer stack with another vertical layout. The `wxSizerFlags` are propogated to each layer so the vertical layout in this example would also be set to expand with a default border. The second stack would be created as a "named" box vertical stack. -A "Sizer" takes a collection of Items, which can be either additional "Sizers" (to create a tree of "Sizers") or "Controllers". Here is the general form of constructions for Stacks: +A "Layout" takes a collection of Items, which can be either additional "Layout" (to create a tree of "Layouts") or "Controllers". Here is the general form of constructions for Stacks: ``` Stack { Items... } @@ -87,7 +87,7 @@ wxUI::VStack { "Current Frame" }.attachTo(this); #### Generic -One special type of "Sizer" is `Generic`. There are cases where you may have an existing `wxSizer` (such as a common dialog) that you wish to use with `wxUI`. This is a case to use `Generic`: +One special type of "Layout" is `Generic`. There are cases where you may have an existing layout as a `wxSizer` (such as a common dialog) that you wish to use with `wxUI`. This is a case to use `Generic`: ```cpp {{{ examples/HelloWorld/HelloWorld.cpp wxUIGeneric " // ..." }}} diff --git a/examples/HelloWorld/HelloWorld.cpp b/examples/HelloWorld/HelloWorld.cpp index 2d27ef7..57fd62e 100644 --- a/examples/HelloWorld/HelloWorld.cpp +++ b/examples/HelloWorld/HelloWorld.cpp @@ -223,14 +223,14 @@ ExampleDialog::ExampleDialog(wxWindow* parent) wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) { using namespace wxUI; - // snippet wxUISizerBasic + // snippet wxUILayoutBasic // snippet wxUIGeneric VStack { wxSizerFlags().Expand().Border(), // endsnippet wxUIGeneric VStack { "Text examples", - // endsnippet wxUISizerBasic + // endsnippet wxUILayoutBasic Text { "Example of Text in wxUI" }, TextCtrl { "Single line of text" } .style(wxALIGN_LEFT), @@ -272,11 +272,11 @@ ExampleDialog::ExampleDialog(wxWindow* parent) // snippet wxUIGeneric Generic { CreateStdDialogButtonSizer(wxOK) }, // snippet withwxUI - // snippet wxUISizerBasic + // snippet wxUILayoutBasic } .attachTo(this); // endsnippet wxUIGeneric - // endsnippet wxUISizerBasic + // endsnippet wxUILayoutBasic } // endsnippet withwxUI // endsnippet Example diff --git a/include/wxUI/Sizer.h b/include/wxUI/Layout.h similarity index 92% rename from include/wxUI/Sizer.h rename to include/wxUI/Layout.h index 29927ca..766b11f 100644 --- a/include/wxUI/Sizer.h +++ b/include/wxUI/Layout.h @@ -236,4 +236,26 @@ struct HStack : public details::Stack { } }; +struct Generic { + std::optional flags; + wxSizer* sizer; + + Generic(wxSizerFlags const& flags, wxSizer* sizer) + : flags(flags) + , sizer(sizer) + { + } + + Generic(wxSizer* sizer) + : sizer(sizer) + { + } + + void createAndAdd([[maybe_unused]] wxWindow* parent, wxSizer* parentSizer, wxSizerFlags const& parentFlags) const + { + // the item has already been created, we're mearly holding on to it. + parentSizer->Add(sizer, flags ? *flags : parentFlags); + } +}; + } diff --git a/include/wxUI/Widget.h b/include/wxUI/Widget.h index c3ea1ae..94e15c2 100644 --- a/include/wxUI/Widget.h +++ b/include/wxUI/Widget.h @@ -30,10 +30,9 @@ namespace wxUI::details { // A widget is anything that supports the createAndAdd function. template -concept Widget = requires(T widget, wxWindow* w, wxSizer* s) -{ - widget.createAndAdd(w, s, wxSizerFlags {}); -}; +concept Widget = requires(T widget, wxWindow* w, wxSizer* s) { + widget.createAndAdd(w, s, wxSizerFlags {}); + }; // https://stackoverflow.com/questions/27866909/get-function-arity-from-template-parameter template @@ -140,28 +139,3 @@ struct WidgetDetails { }; } - -namespace wxUI { -struct Generic { - std::optional flags; - wxSizer* sizer; - - Generic(wxSizerFlags const& flags, wxSizer* sizer) - : flags(flags) - , sizer(sizer) - { - } - - Generic(wxSizer* sizer) - : sizer(sizer) - { - } - - void createAndAdd([[maybe_unused]] wxWindow* parent, wxSizer* parentSizer, wxSizerFlags const& parentFlags) const - { - // the item has already been created, we're mearly holding on to it. - parentSizer->Add(sizer, flags ? *flags : parentFlags); - } -}; - -} diff --git a/include/wxUI/wxUI.h b/include/wxUI/wxUI.h index 8321570..98efaf2 100644 --- a/include/wxUI/wxUI.h +++ b/include/wxUI/wxUI.h @@ -30,9 +30,9 @@ #include #include #include +#include #include #include -#include #include #include #include diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c1f79aa..6b68816 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,9 +5,9 @@ add_executable(wxUI_Tests ${CMAKE_CURRENT_SOURCE_DIR}/wxUI_ButtonTests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wxUI_CheckBoxTests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wxUI_ChoiceTests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/wxUI_LayoutTests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wxUI_MenuTests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wxUI_RadioBoxTests.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/wxUI_SizerTests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wxUI_Text.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wxUI_TextCtrl.cpp ) diff --git a/tests/wxUI_SizerTests.cpp b/tests/wxUI_LayoutTests.cpp similarity index 99% rename from tests/wxUI_SizerTests.cpp rename to tests/wxUI_LayoutTests.cpp index d12f787..55e07b6 100644 --- a/tests/wxUI_SizerTests.cpp +++ b/tests/wxUI_LayoutTests.cpp @@ -1,6 +1,6 @@ #include +#include #include -#include #include From 5ab6d8cf86711b717403da371988c55fd15f5319 Mon Sep 17 00:00:00 2001 From: Richard Powell Date: Sat, 31 Dec 2022 09:06:51 -0800 Subject: [PATCH 2/2] WHy is clang-format acting funny...? --- include/wxUI/Widget.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/wxUI/Widget.h b/include/wxUI/Widget.h index 94e15c2..e641127 100644 --- a/include/wxUI/Widget.h +++ b/include/wxUI/Widget.h @@ -29,10 +29,13 @@ namespace wxUI::details { // A widget is anything that supports the createAndAdd function. +// clang-format off template -concept Widget = requires(T widget, wxWindow* w, wxSizer* s) { - widget.createAndAdd(w, s, wxSizerFlags {}); - }; +concept Widget = requires(T widget, wxWindow* w, wxSizer* s) +{ + widget.createAndAdd(w, s, wxSizerFlags {}); +}; +// clang-format on // https://stackoverflow.com/questions/27866909/get-function-arity-from-template-parameter template