diff --git a/LATEST_RELEASE_NOTES.md b/LATEST_RELEASE_NOTES.md index d3d870e..795eb79 100644 --- a/LATEST_RELEASE_NOTES.md +++ b/LATEST_RELEASE_NOTES.md @@ -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 diff --git a/include/wxUI/BitmapButton.h b/include/wxUI/BitmapButton.h index 384bb73..5a34a62 100644 --- a/include/wxUI/BitmapButton.h +++ b/include/wxUI/BitmapButton.h @@ -58,7 +58,7 @@ struct BitmapButton : public details::WidgetDetails 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(); } diff --git a/include/wxUI/BitmapToggleButton.h b/include/wxUI/BitmapToggleButton.h index ff24401..f7693ca 100644 --- a/include/wxUI/BitmapToggleButton.h +++ b/include/wxUI/BitmapToggleButton.h @@ -60,7 +60,7 @@ struct BitmapToggleButton : public details::WidgetDetails 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); } diff --git a/include/wxUI/Button.h b/include/wxUI/Button.h index a198a9b..6e031c1 100644 --- a/include/wxUI/Button.h +++ b/include/wxUI/Button.h @@ -58,7 +58,7 @@ struct Button : public details::WidgetDetails { 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(); } diff --git a/include/wxUI/CheckBox.h b/include/wxUI/CheckBox.h index 1f4944a..3ab92dc 100644 --- a/include/wxUI/CheckBox.h +++ b/include/wxUI/CheckBox.h @@ -60,7 +60,7 @@ struct CheckBox : public details::WidgetDetails { 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 diff --git a/include/wxUI/Choice.h b/include/wxUI/Choice.h index 923654b..9a07f67 100644 --- a/include/wxUI/Choice.h +++ b/include/wxUI/Choice.h @@ -64,7 +64,7 @@ struct Choice : public details::WidgetDetails { auto create(wxWindow* parent) -> wxWindow* override { - auto* widget = new underlying_t(parent, this->identity, this->pos, this->size, static_cast(choices.size()), choices.data(), this->usingStyle); + auto* widget = new underlying_t(parent, getIdentity(), getPos(), getSize(), static_cast(choices.size()), choices.data(), getStyle()); widget->SetSelection(selection); return widget; } diff --git a/include/wxUI/Line.h b/include/wxUI/Line.h index d621c57..0c01255 100644 --- a/include/wxUI/Line.h +++ b/include/wxUI/Line.h @@ -43,7 +43,7 @@ struct Line : public details::WidgetDetails { 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; diff --git a/include/wxUI/ListBox.h b/include/wxUI/ListBox.h index 4ab5a0c..209b3de 100644 --- a/include/wxUI/ListBox.h +++ b/include/wxUI/ListBox.h @@ -64,7 +64,7 @@ struct ListBox : public details::WidgetDetails { auto create(wxWindow* parent) -> wxWindow* override { - auto* widget = new underlying_t(parent, this->identity, this->pos, this->size, static_cast(choices.size()), choices.data(), this->usingStyle); + auto* widget = new underlying_t(parent, getIdentity(), getPos(), getSize(), static_cast(choices.size()), choices.data(), getStyle()); widget->SetSelection(selection); return widget; } diff --git a/include/wxUI/RadioBox.h b/include/wxUI/RadioBox.h index 8068529..03c7774 100644 --- a/include/wxUI/RadioBox.h +++ b/include/wxUI/RadioBox.h @@ -37,11 +37,10 @@ struct RadioBox : details::WidgetDetails { int selection {}; explicit RadioBox(wxWindowID identity, std::string text = "", std::vector 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 choices) @@ -60,11 +59,10 @@ struct RadioBox : details::WidgetDetails { } RadioBox(wxSizerFlags const& flags, wxWindowID identity, std::string text, std::vector 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 choices) @@ -96,7 +94,7 @@ struct RadioBox : details::WidgetDetails { auto create(wxWindow* parent) -> wxWindow* override { - auto* widget = new underlying_t(parent, this->identity, text, this->pos, this->size, static_cast(choices.size()), choices.data(), majorDim_, this->usingStyle); + auto* widget = new underlying_t(parent, getIdentity(), text, getPos(), getSize(), static_cast(choices.size()), choices.data(), majorDim_, getStyle()); widget->SetSelection(selection); return widget; } diff --git a/include/wxUI/Slider.h b/include/wxUI/Slider.h index 53b5e52..b103f67 100644 --- a/include/wxUI/Slider.h +++ b/include/wxUI/Slider.h @@ -63,7 +63,7 @@ struct Slider : public details::WidgetDetails { 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; } diff --git a/include/wxUI/SpinCtrl.h b/include/wxUI/SpinCtrl.h index 1a2be41..3ca569b 100644 --- a/include/wxUI/SpinCtrl.h +++ b/include/wxUI/SpinCtrl.h @@ -63,7 +63,7 @@ struct SpinCtrl : public details::WidgetDetails { 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; } diff --git a/include/wxUI/Text.h b/include/wxUI/Text.h index 0ee0780..f9bee84 100644 --- a/include/wxUI/Text.h +++ b/include/wxUI/Text.h @@ -59,7 +59,7 @@ struct Text : public details::WidgetDetails { 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; diff --git a/include/wxUI/TextCtrl.h b/include/wxUI/TextCtrl.h index 340448f..742d0a7 100644 --- a/include/wxUI/TextCtrl.h +++ b/include/wxUI/TextCtrl.h @@ -57,7 +57,7 @@ struct TextCtrl : public details::WidgetDetails { 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 diff --git a/include/wxUI/Widget.h b/include/wxUI/Widget.h index efabdc3..22aed7b 100644 --- a/include/wxUI/Widget.h +++ b/include/wxUI/Widget.h @@ -98,6 +98,10 @@ struct BindWidgetToEvent { template BindWidgetToEvent(W, Event, Function) -> BindWidgetToEvent; +// 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: @@ -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_; @@ -130,9 +147,9 @@ struct WidgetDetails { return static_cast(*this); } - auto withStyle(int64_t style) -> ConcreteWidget& + auto withStyle(int64_t style_) -> ConcreteWidget& { - usingStyle = style; + style = style_; return static_cast(*this); } @@ -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 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 {}; };