Skip to content

Commit

Permalink
Merge pull request #168 from rmpowell77/dev/splitter_work
Browse files Browse the repository at this point in the history
Issue #167: VSplitter and HSplitter proxy's are hard to use
  • Loading branch information
rmpowell77 authored Dec 26, 2023
2 parents bf3af5d + 01cce6f commit 4f60165
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 44 deletions.
1 change: 1 addition & 0 deletions LATEST_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ Other changes:
* [#157](../../issues/157) Text needs withWrap
* [#161](../../issues/161) Need to have a setEnabled for Widgets
* [#164](../../issues/164) Add ForEach, which would allow a list of Controllers to be added
* [#167](../../issues/167) VSplitter and HSplitter proxy's are hard to use

2 changes: 1 addition & 1 deletion include/wxUI/Bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct Bitmap : public details::WidgetDetails<Bitmap, wxStaticBitmap> {
{
}

struct Proxy : super::WidgetProxy {
struct Proxy : details::WidgetProxy<underlying_t> {
PROXY_BOILERPLATE();
};
RULE_OF_SIX_BOILERPLATE(Bitmap);
Expand Down
2 changes: 1 addition & 1 deletion include/wxUI/BitmapButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct BitmapButton : public details::WidgetDetails<BitmapButton, wxBitmapButton
return super::bind(wxEVT_BUTTON, func);
}

struct Proxy : super::WidgetProxy {
struct Proxy : details::WidgetProxy<underlying_t> {
PROXY_BOILERPLATE();
};
RULE_OF_SIX_BOILERPLATE(BitmapButton);
Expand Down
2 changes: 1 addition & 1 deletion include/wxUI/BitmapComboBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ struct BitmapComboBox : public details::WidgetDetails<BitmapComboBox, wxBitmapCo
return super::bind(wxEVT_COMBOBOX, func);
}

struct Proxy : super::WidgetProxy {
struct Proxy : details::WidgetProxy<underlying_t> {
PROXY_BOILERPLATE();
[[nodiscard]] auto value() const
{
Expand Down
2 changes: 1 addition & 1 deletion include/wxUI/BitmapToggleButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct BitmapToggleButton : public details::WidgetDetails<BitmapToggleButton, wx
return super::bind(wxEVT_TOGGLEBUTTON, func);
}

struct Proxy : super::WidgetProxy {
struct Proxy : details::WidgetProxy<underlying_t> {
PROXY_BOILERPLATE();
[[nodiscard]] auto value() const
{
Expand Down
2 changes: 1 addition & 1 deletion include/wxUI/Button.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct Button : public details::WidgetDetails<Button, wxButton> {
return super::bind(wxEVT_BUTTON, func);
}

struct Proxy : super::WidgetProxy {
struct Proxy : details::WidgetProxy<underlying_t> {
PROXY_BOILERPLATE();
};
RULE_OF_SIX_BOILERPLATE(Button);
Expand Down
2 changes: 1 addition & 1 deletion include/wxUI/CheckBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct CheckBox : public details::WidgetDetails<CheckBox, wxCheckBox> {
return super::bind(wxEVT_CHECKBOX, func);
}

struct Proxy : super::WidgetProxy {
struct Proxy : details::WidgetProxy<underlying_t> {
PROXY_BOILERPLATE();
[[nodiscard]] auto value() const
{
Expand Down
2 changes: 1 addition & 1 deletion include/wxUI/Choice.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct Choice : public details::WidgetDetails<Choice, wxChoice> {
return super::bind(wxEVT_CHOICE, func);
}

struct Proxy : super::WidgetProxy {
struct Proxy : details::WidgetProxy<underlying_t> {
PROXY_BOILERPLATE();
[[nodiscard]] auto selection() const
{
Expand Down
2 changes: 1 addition & 1 deletion include/wxUI/ComboBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ struct ComboBox : public details::WidgetDetails<ComboBox, wxComboBox> {
return super::bind(wxEVT_COMBOBOX, func);
}

struct Proxy : super::WidgetProxy {
struct Proxy : details::WidgetProxy<underlying_t> {
PROXY_BOILERPLATE();
[[nodiscard]] auto value() const
{
Expand Down
2 changes: 1 addition & 1 deletion include/wxUI/Hyperlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct Hyperlink : public details::WidgetDetails<Hyperlink, wxHyperlinkCtrl> {
{
}

struct Proxy : super::WidgetProxy {
struct Proxy : details::WidgetProxy<underlying_t> {
PROXY_BOILERPLATE();
};
RULE_OF_SIX_BOILERPLATE(Hyperlink);
Expand Down
2 changes: 1 addition & 1 deletion include/wxUI/Line.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct Line : public details::WidgetDetails<Line, wxStaticLine> {
return setProxy(new underlying_t(parent, getIdentity(), getPos(), getSize(), getStyle()));
}

struct Proxy : super::WidgetProxy {
struct Proxy : details::WidgetProxy<underlying_t> {
PROXY_BOILERPLATE();
};
RULE_OF_SIX_BOILERPLATE(Line);
Expand Down
2 changes: 1 addition & 1 deletion include/wxUI/ListBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ struct ListBox : public details::WidgetDetails<ListBox, wxListBox> {
return super::bind(wxEVT_LISTBOX, func);
}

struct Proxy : super::WidgetProxy {
struct Proxy : details::WidgetProxy<underlying_t> {
PROXY_BOILERPLATE();
[[nodiscard]] auto selection() const
{
Expand Down
2 changes: 1 addition & 1 deletion include/wxUI/RadioBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ struct RadioBox : details::WidgetDetails<RadioBox, wxRadioBox> {
return super::bind(wxEVT_RADIOBOX, func);
}

struct Proxy : super::WidgetProxy {
struct Proxy : details::WidgetProxy<underlying_t> {
PROXY_BOILERPLATE();
[[nodiscard]] auto selection() const
{
Expand Down
2 changes: 1 addition & 1 deletion include/wxUI/Slider.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct Slider : public details::WidgetDetails<Slider, wxSlider> {
return super::bind(wxEVT_SLIDER, func);
}

struct Proxy : super::WidgetProxy {
struct Proxy : details::WidgetProxy<underlying_t> {
PROXY_BOILERPLATE();
[[nodiscard]] auto value() const
{
Expand Down
2 changes: 1 addition & 1 deletion include/wxUI/SpinCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct SpinCtrl : public details::WidgetDetails<SpinCtrl, wxSpinCtrl> {
return super::bind(wxEVT_SPINCTRL, func);
}

struct Proxy : super::WidgetProxy {
struct Proxy : details::WidgetProxy<underlying_t> {
PROXY_BOILERPLATE();

[[nodiscard]] auto value() const
Expand Down
8 changes: 6 additions & 2 deletions include/wxUI/Splitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ struct HSplitter : public details::WidgetDetails<HSplitter<W1, W2>, wxSplitterWi
{
}

struct Proxy : super::WidgetProxy {
struct Proxy : details::WidgetProxy<underlying_t> {
PROXY_BOILERPLATE();
};
RULE_OF_SIX_BOILERPLATE(HSplitter);
Expand Down Expand Up @@ -148,7 +148,7 @@ struct VSplitter : public details::WidgetDetails<VSplitter<W1, W2>, wxSplitterWi
{
}

struct Proxy : super::WidgetProxy {
struct Proxy : details::WidgetProxy<underlying_t> {
PROXY_BOILERPLATE();
};
RULE_OF_SIX_BOILERPLATE(VSplitter);
Expand All @@ -164,5 +164,9 @@ struct VSplitter : public details::WidgetDetails<VSplitter<W1, W2>, wxSplitterWi
}
};

struct SplitterProxy : details::WidgetProxy<wxSplitterWindow> {
PROXY_BOILERPLATE();
};

}
#include "ZapMacros.h"
2 changes: 1 addition & 1 deletion include/wxUI/Text.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct Text : public details::WidgetDetails<Text, wxStaticText> {
return *this;
}

struct Proxy : super::WidgetProxy {
struct Proxy : details::WidgetProxy<underlying_t> {
PROXY_BOILERPLATE();

[[nodiscard]] auto label() const
Expand Down
2 changes: 1 addition & 1 deletion include/wxUI/TextCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct TextCtrl : public details::WidgetDetails<TextCtrl, wxTextCtrl> {
return super::bind(wxEVT_TEXT, func);
}

struct Proxy : super::WidgetProxy {
struct Proxy : details::WidgetProxy<underlying_t> {
PROXY_BOILERPLATE();

[[nodiscard]] auto label() const
Expand Down
49 changes: 23 additions & 26 deletions include/wxUI/Widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,26 @@ struct overloaded : Ts... {
template <class... Ts>
overloaded(Ts...) -> overloaded<Ts...>;

template <typename Controller, typename Underlying>
struct WidgetProxy;
template <typename Underlying>
struct WidgetProxy {
[[nodiscard]] auto control() const -> Underlying*
{
if (!controller) {
throw std::runtime_error("Proxy class has not been attached");
}
return controller;
}

void setUnderlying(Underlying* control)
{
controller = control;
}

auto operator->() const { return control(); }

private:
Underlying* controller {};
};

// The WidgetDetails are the base class of the Controllers. The common details
// across many controllers are stored in the base class.
Expand All @@ -103,27 +121,6 @@ struct WidgetDetails {
using Controller = ConcreteWidget;
using underlying_t = Underlying;

struct WidgetProxy {
using Controller = ConcreteWidget;
[[nodiscard]] auto control() const -> Underlying*
{
if (!controller) {
throw std::runtime_error("Proxy class has not been attached");
}
return controller;
}

void setUnderlying(Underlying* control)
{
controller = control;
}

auto operator->() const { return control(); }

private:
Underlying* controller {};
};

struct WithStyle {
int64_t mStyle;
};
Expand Down Expand Up @@ -258,7 +255,7 @@ struct WidgetDetails {
auto getSize() const { return size; }
auto getStyle() const { return style; }

void setProxyHandle(WidgetProxy* proxy)
void setProxyHandle(WidgetProxy<Underlying>* proxy)
{
proxyHandle = proxy;
}
Expand All @@ -267,7 +264,7 @@ struct WidgetDetails {
auto setProxy(Underlying* widget) -> Underlying*
{
if (proxyHandle) {
(*proxyHandle)->setUnderlying(widget);
proxyHandle->setUnderlying(widget);
}
return widget;
}
Expand All @@ -285,7 +282,7 @@ struct WidgetDetails {
int64_t style {};
bool enabled = true;
std::optional<wxFontInfo> fontInfo {};
std::optional<WidgetProxy*> proxyHandle {};
details::WidgetProxy<Underlying>* proxyHandle {}; // optional WidgetProxy
std::vector<BindInfo> boundedFunctions;
};

Expand Down
8 changes: 8 additions & 0 deletions tests/wxUI_HSplitterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ TEST_CASE("HSplitter")
CHECK(10000 == window->GetId());
}

SECTION("proxy")
{
wxFrame frame { nullptr, wxID_ANY, "" };
wxUI::SplitterProxy proxy;
auto uut = proxy = TypeUnderTest { wxUI::TextCtrl {}, wxUI::TextCtrl {} };
[[maybe_unused]] auto* window = dynamic_cast<TypeUnderTest::underlying_t*>(uut.create(&frame));
}

COMMON_TESTS(HSplitterTestPolicy)
}
// NOLINTEND(cppcoreguidelines-avoid-magic-numbers, readability-magic-numbers, readability-function-cognitive-complexity, misc-use-anonymous-namespace, cppcoreguidelines-avoid-do-while)
8 changes: 8 additions & 0 deletions tests/wxUI_VSplitterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ TEST_CASE("VSplitter")
CHECK(10000 == window->GetId());
}

SECTION("proxy")
{
wxFrame frame { nullptr, wxID_ANY, "" };
wxUI::SplitterProxy proxy;
auto uut = proxy = TypeUnderTest { wxUI::TextCtrl {}, wxUI::TextCtrl {} };
[[maybe_unused]] auto* window = dynamic_cast<TypeUnderTest::underlying_t*>(uut.create(&frame));
}

COMMON_TESTS(VSplitterTestPolicy)
}
// NOLINTEND(cppcoreguidelines-avoid-magic-numbers, readability-magic-numbers, readability-function-cognitive-complexity, misc-use-anonymous-namespace, cppcoreguidelines-avoid-do-while)

0 comments on commit 4f60165

Please sign in to comment.