Skip to content

Commit

Permalink
Merge pull request #169 from rmpowell77/dev/splitter_gravity
Browse files Browse the repository at this point in the history
Issue #166: Special Functions for Splitter
  • Loading branch information
rmpowell77 authored Dec 26, 2023
2 parents 4f60165 + 826c364 commit e697bd7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions LATEST_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ 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
* [#166](../../issues/166) Special Functions for Splitter
* [#167](../../issues/167) VSplitter and HSplitter proxy's are hard to use

21 changes: 21 additions & 0 deletions include/wxUI/Splitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,29 @@ struct HSplitter : public details::WidgetDetails<HSplitter<W1, W2>, wxSplitterWi
{
}

auto withStashGravity(double gravity) -> HSplitter<W1, W2>&
{
stashGravity = gravity;
return *this;
}

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

RULE_OF_SIX_BOILERPLATE(HSplitter);

private:
std::pair<W1, W2> widgets;
std::optional<double> stashGravity {};

auto createImpl(wxWindow* parent) -> wxWindow* override
{
auto* widget = super::setProxy(new underlying_t(parent, super::getIdentity(), super::getPos(), super::getSize(), super::getStyle()));
widget->SplitHorizontally(std::get<0>(widgets).create(widget), std::get<1>(widgets).create(widget));
if (stashGravity) {
widget->SetSashGravity(*stashGravity);
}
return widget;
}
};
Expand Down Expand Up @@ -148,18 +159,28 @@ struct VSplitter : public details::WidgetDetails<VSplitter<W1, W2>, wxSplitterWi
{
}

auto withStashGravity(double gravity) -> VSplitter<W1, W2>&
{
stashGravity = gravity;
return *this;
}

struct Proxy : details::WidgetProxy<underlying_t> {
PROXY_BOILERPLATE();
};
RULE_OF_SIX_BOILERPLATE(VSplitter);

private:
std::pair<W1, W2> widgets;
std::optional<double> stashGravity {};

auto createImpl(wxWindow* parent) -> wxWindow* override
{
auto* widget = super::setProxy(new underlying_t(parent, super::getIdentity(), super::getPos(), super::getSize(), super::getStyle()));
widget->SplitVertically(std::get<0>(widgets).create(widget), std::get<1>(widgets).create(widget));
if (stashGravity) {
widget->SetSashGravity(*stashGravity);
}
return widget;
}
};
Expand Down
7 changes: 7 additions & 0 deletions tests/wxUI_HSplitterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ TEST_CASE("HSplitter")
[[maybe_unused]] auto* window = dynamic_cast<TypeUnderTest::underlying_t*>(uut.create(&frame));
}

SECTION("withGravity")
{
wxFrame frame { nullptr, wxID_ANY, "" };
auto uut = TypeUnderTest { wxUI::TextCtrl {}, wxUI::TextCtrl {} }.withStashGravity(1.0);
[[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)
7 changes: 7 additions & 0 deletions tests/wxUI_VSplitterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ TEST_CASE("VSplitter")
[[maybe_unused]] auto* window = dynamic_cast<TypeUnderTest::underlying_t*>(uut.create(&frame));
}

SECTION("withGravity")
{
wxFrame frame { nullptr, wxID_ANY, "" };
auto uut = TypeUnderTest { wxUI::TextCtrl {}, wxUI::TextCtrl {} }.withStashGravity(1.0);
[[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 e697bd7

Please sign in to comment.