Skip to content

Commit

Permalink
Merge pull request #74 from rmpowell77/dev/make_private
Browse files Browse the repository at this point in the history
Issue #72: consider making WidgetDetails member values private
  • Loading branch information
rmpowell77 authored Feb 1, 2023
2 parents a0ce3f9 + 3381039 commit d412399
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 20 deletions.
1 change: 1 addition & 0 deletions LATEST_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ Other changes:
* [#65](../../issues/65) Custom controller should take a coroutine that generates wxWindows to be added to the sizer
* [#70](../../issues/70) Widget::style() is odd, it should be withStyle()
* [#71](../../issues/71) remove wxUI::details::Custom
* [#72](../../issues/72) consider making WidgetDetails member values private

2 changes: 1 addition & 1 deletion include/wxUI/BitmapButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct BitmapButton : public details::WidgetDetails<BitmapButton, wxBitmapButton

auto create(wxWindow* parent) -> wxWindow* override
{
auto* widget = new underlying_t(parent, identity, bitmap, this->pos, this->size, this->usingStyle);
auto* widget = new underlying_t(parent, getIdentity(), bitmap, getPos(), getSize(), getStyle());
if (isDefault) {
widget->SetDefault();
}
Expand Down
2 changes: 1 addition & 1 deletion include/wxUI/BitmapToggleButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct BitmapToggleButton : public details::WidgetDetails<BitmapToggleButton, wx

auto create(wxWindow* parent) -> wxWindow* override
{
auto* widget = new underlying_t(parent, identity, bitmap, this->pos, this->size, this->usingStyle);
auto* widget = new underlying_t(parent, getIdentity(), bitmap, getPos(), getSize(), getStyle());
if (bitmapPressed) {
widget->SetBitmapPressed(*bitmapPressed);
}
Expand Down
2 changes: 1 addition & 1 deletion include/wxUI/Button.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct Button : public details::WidgetDetails<Button, wxButton> {

auto create(wxWindow* parent) -> wxWindow* override
{
auto* widget = new underlying_t(parent, identity, text, this->pos, this->size, this->usingStyle);
auto* widget = new underlying_t(parent, getIdentity(), text, getPos(), getSize(), getStyle());
if (isDefault) {
widget->SetDefault();
}
Expand Down
2 changes: 1 addition & 1 deletion include/wxUI/CheckBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct CheckBox : public details::WidgetDetails<CheckBox, wxCheckBox> {

auto create(wxWindow* parent) -> wxWindow* override
{
return new underlying_t(parent, this->identity, text, this->pos, this->size, this->usingStyle);
return new underlying_t(parent, getIdentity(), text, getPos(), getSize(), getStyle());
}

template <typename Function>
Expand Down
2 changes: 1 addition & 1 deletion include/wxUI/Choice.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct Choice : public details::WidgetDetails<Choice, wxChoice> {

auto create(wxWindow* parent) -> wxWindow* override
{
auto* widget = new underlying_t(parent, this->identity, this->pos, this->size, static_cast<int>(choices.size()), choices.data(), this->usingStyle);
auto* widget = new underlying_t(parent, getIdentity(), getPos(), getSize(), static_cast<int>(choices.size()), choices.data(), getStyle());
widget->SetSelection(selection);
return widget;
}
Expand Down
2 changes: 1 addition & 1 deletion include/wxUI/Line.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct Line : public details::WidgetDetails<Line, wxStaticLine> {

auto create(wxWindow* parent) -> wxWindow* override
{
return new underlying_t(parent, this->identity, this->pos, this->size, this->usingStyle);
return new underlying_t(parent, getIdentity(), getPos(), getSize(), getStyle());
}

virtual ~Line() = default;
Expand Down
2 changes: 1 addition & 1 deletion include/wxUI/ListBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct ListBox : public details::WidgetDetails<ListBox, wxListBox> {

auto create(wxWindow* parent) -> wxWindow* override
{
auto* widget = new underlying_t(parent, this->identity, this->pos, this->size, static_cast<int>(choices.size()), choices.data(), this->usingStyle);
auto* widget = new underlying_t(parent, getIdentity(), getPos(), getSize(), static_cast<int>(choices.size()), choices.data(), getStyle());
widget->SetSelection(selection);
return widget;
}
Expand Down
8 changes: 3 additions & 5 deletions include/wxUI/RadioBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ struct RadioBox : details::WidgetDetails<RadioBox, wxRadioBox> {
int selection {};

explicit RadioBox(wxWindowID identity, std::string text = "", std::vector<wxString> choices = {})
: super(identity)
: super(identity, details::withStyle {}, wxRA_SPECIFY_COLS)
, text(std::move(text))
, choices(std::move(choices))
{
usingStyle = wxRA_SPECIFY_COLS;
}

RadioBox(wxWindowID identity, std::vector<wxString> choices)
Expand All @@ -60,11 +59,10 @@ struct RadioBox : details::WidgetDetails<RadioBox, wxRadioBox> {
}

RadioBox(wxSizerFlags const& flags, wxWindowID identity, std::string text, std::vector<wxString> choices)
: super(flags, identity)
: super(flags, identity, details::withStyle {}, wxRA_SPECIFY_COLS)
, text(std::move(text))
, choices(std::move(choices))
{
usingStyle = wxRA_SPECIFY_COLS;
}

RadioBox(wxSizerFlags const& flags, wxWindowID identity, std::vector<wxString> choices)
Expand Down Expand Up @@ -96,7 +94,7 @@ struct RadioBox : details::WidgetDetails<RadioBox, wxRadioBox> {

auto create(wxWindow* parent) -> wxWindow* override
{
auto* widget = new underlying_t(parent, this->identity, text, this->pos, this->size, static_cast<int>(choices.size()), choices.data(), majorDim_, this->usingStyle);
auto* widget = new underlying_t(parent, getIdentity(), text, getPos(), getSize(), static_cast<int>(choices.size()), choices.data(), majorDim_, getStyle());
widget->SetSelection(selection);
return widget;
}
Expand Down
2 changes: 1 addition & 1 deletion include/wxUI/Slider.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct Slider : public details::WidgetDetails<Slider, wxSlider> {
auto min = range ? range->first : 0;
auto max = range ? range->second : 100;
auto initvalue = initial ? *initial : min;
auto* widget = new underlying_t(parent, identity, initvalue, min, max, this->pos, this->size, this->usingStyle);
auto* widget = new underlying_t(parent, getIdentity(), initvalue, min, max, getPos(), getSize(), getStyle());
return widget;
}

Expand Down
2 changes: 1 addition & 1 deletion include/wxUI/SpinCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct SpinCtrl : public details::WidgetDetails<SpinCtrl, wxSpinCtrl> {
auto min = range ? range->first : 0;
auto max = range ? range->second : 100;
auto initvalue = initial ? *initial : min;
auto* widget = new underlying_t(parent, identity, wxEmptyString, this->pos, this->size, this->usingStyle, min, max, initvalue);
auto* widget = new underlying_t(parent, getIdentity(), wxEmptyString, getPos(), getSize(), getStyle(), min, max, initvalue);
return widget;
}

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

auto create(wxWindow* parent) -> wxWindow* override
{
return new underlying_t(parent, identity, text, this->pos, this->size, this->usingStyle);
return new underlying_t(parent, getIdentity(), text, getPos(), getSize(), getStyle());
}

virtual ~Text() = default;
Expand Down
2 changes: 1 addition & 1 deletion include/wxUI/TextCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct TextCtrl : public details::WidgetDetails<TextCtrl, wxTextCtrl> {

auto create(wxWindow* parent) -> wxWindow* override
{
return new underlying_t(parent, this->identity, text, this->pos, this->size, this->usingStyle);
return new underlying_t(parent, getIdentity(), text, getPos(), getSize(), getStyle());
}

template <typename Function>
Expand Down
29 changes: 25 additions & 4 deletions include/wxUI/Widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ struct BindWidgetToEvent {
template <Widget W, typename Event, typename Function>
BindWidgetToEvent(W, Event, Function) -> BindWidgetToEvent<W, Event, Function>;

// This is to allow disambiguation of construction with a style
struct withStyle {
};

// The WidgetDetails are the base class of the Controllers. The common details
// across many controllers are stored in the base class.
// The "recipe" for constructing a controller is pretty straight forward:
Expand All @@ -118,6 +122,19 @@ struct WidgetDetails {
{
}

explicit WidgetDetails(wxWindowID identity, withStyle, int64_t style)
: identity(identity)
, style(style)
{
}

WidgetDetails(wxSizerFlags const& flags, wxWindowID identity, withStyle, int64_t style)
: flags(flags)
, identity(identity)
, style(style)
{
}

auto withPosition(wxPoint pos_) -> ConcreteWidget&
{
pos = pos_;
Expand All @@ -130,9 +147,9 @@ struct WidgetDetails {
return static_cast<ConcreteWidget&>(*this);
}

auto withStyle(int64_t style) -> ConcreteWidget&
auto withStyle(int64_t style_) -> ConcreteWidget&
{
usingStyle = style;
style = style_;
return static_cast<ConcreteWidget&>(*this);
}

Expand All @@ -152,18 +169,22 @@ struct WidgetDetails {
return widget;
}

auto getIdentity() const { return identity; }
auto getPos() const { return pos; }
auto getSize() const { return size; }
auto getStyle() const { return style; }

private:
// these should be implemented in the derived classes.
// aka the Template Pattern
virtual auto create(wxWindow* parent) -> wxWindow* = 0;

public:
std::optional<wxSizerFlags> flags;
// these are common across the controls
wxWindowID identity = wxID_ANY;
wxPoint pos = wxDefaultPosition;
wxSize size = wxDefaultSize;
int64_t usingStyle {};
int64_t style {};
Underlying** windowHandle {};
};

Expand Down

0 comments on commit d412399

Please sign in to comment.