Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing from Sizer to Layout as it is a better name. #33

Merged
merged 2 commits into from
Dec 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions docs/src/docs/ProgrammersGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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... }
Expand All @@ -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 " // ..." }}}
Expand Down
8 changes: 4 additions & 4 deletions examples/HelloWorld/HelloWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
22 changes: 22 additions & 0 deletions include/wxUI/Sizer.h → include/wxUI/Layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,26 @@ struct HStack : public details::Stack<wxHORIZONTAL, W...> {
}
};

struct Generic {
std::optional<wxSizerFlags> 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);
}
};

}
27 changes: 2 additions & 25 deletions include/wxUI/Widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ namespace wxUI::details {

// A widget is anything that supports the createAndAdd function.

// clang-format off
template <typename T>
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 <typename T>
Expand Down Expand Up @@ -140,28 +142,3 @@ struct WidgetDetails {
};

}

namespace wxUI {
struct Generic {
std::optional<wxSizerFlags> 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);
}
};

}
2 changes: 1 addition & 1 deletion include/wxUI/wxUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
#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>
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion tests/wxUI_SizerTests.cpp → tests/wxUI_LayoutTests.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <catch2/catch_test_macros.hpp>
#include <wxUI/Layout.h>
#include <wxUI/Menu.h>
#include <wxUI/Sizer.h>

#include <wx/wx.h>

Expand Down