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

Issue #171: Need a wxGauge #172

Merged
merged 1 commit into from
Dec 27, 2023
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ add_library(
include/wxUI/ComboBox.h
include/wxUI/Custom.h
include/wxUI/ForEach.h
include/wxUI/Gauge.h
include/wxUI/Generic.h
include/wxUI/GetterSetter.h
include/wxUI/HelperMacros.h
Expand Down
1 change: 1 addition & 0 deletions LATEST_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ Other changes:
* [#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
* [#171](../../issues/171) Need a wxGauge

37 changes: 19 additions & 18 deletions docs/ProgrammersGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,24 +330,25 @@ ExtendedExample::Reset() {

The "Controllers" currently supported by `wxUI`:

| wxUI | wxWidget | Default Event | Proxy | Proxy accessors value |
| :------------------- | :--------------------- | :----------------- | :------------------------ | :-------------- |
| `Bitmap` | `wxStaticBitmap` | n/a | `BitmapProxy` | n/a |
| `BitmapButton` | `wxBitmapButton` | `EVT_BUTTON` | `BitmapButtonProxy` | n/a |
| `BitmapComboBox` | `wxBitmapComboBox` | `EVT_COMBOBOX` | `BitmapComboBoxProxy` | `selection` -> `int`<BR>`value` -> `std::string`<BR>*default*: `value` |
| `BitmapToggleButton` | `wxBitmapToggleButton` | `EVT_TOGGLEBUTTON` | `BitmapToggleButtonProxy` | `value` -> `bool`<BR>*default*: `value` |
| `Button` | `wxButton` | `EVT_BUTTON` | `ButtonProxy` | n/a |
| `CheckBox` | `wxCheckBox` | `EVT_CHECKBOX` | `CheckBoxProxy` | `value` -> `bool`<BR>*default*: `value` |
| `Choice` | `wxChoice` | `EVT_CHOICE` | `ChoiceProxy` | `selection` -> `int`<BR>*default*: `selection` |
| `ComboBox` | `wxComboBox` | `EVT_COMBOBOX` | `ComboBoxProxy` | `selection` -> `int`<BR>`value` -> `std::string`<BR>*default*: `value` |
| `Hypertext` | `wxHypertextCtrl` | n/a | `HypertextProxy` | n/a |
| `Line` | `wxStaticLine` | n/a | `LineProxy` | n/a |
| `ListBox` | `wxListBox` | `EVT_LISTBOX` | `ListBoxProxy` | `selection` -> `int`<BR>*default*: `selection` |
| `RadioBox` | `wxRadioBox` | `EVT_RADIOBOX` | `RadioBoxProxy` | `selection` -> `int`<BR>*default*: `selection` |
| `Slider` | `wxSlider` | `EVT_SLIDER` | `SliderProxy` | `value` -> `int`<BR>*default*: `value` |
| `SpinCtrl` | `wxSpinCtrl` | `EVT_SPINCTRL` | `SpinCtrlProxy` | `value` -> `int`<BR>*default*: `value` |
| `Text` | `wxStaticText` | n/a | `TextProxy` | `label` -> `std::string`<BR>*default*: `label` |
| `TextCtrl` | `wxTextCtrl` | `EVT_TEXT` | `TextCtrlProxy` | `label` -> `std::string`<BR>*default*: `label` |
| wxUI | wxWidget | Default Event | Proxy accessors value |
| :------------------- | :--------------------- | :----------------- | :-------------------- |
| `Bitmap` | `wxStaticBitmap` | n/a | n/a |
| `BitmapButton` | `wxBitmapButton` | `EVT_BUTTON` | n/a |
| `BitmapComboBox` | `wxBitmapComboBox` | `EVT_COMBOBOX` | `selection` -> `int`<BR>`value` -> `std::string`<BR>*default*: `value` |
| `BitmapToggleButton` | `wxBitmapToggleButton` | `EVT_TOGGLEBUTTON` | `value` -> `bool`<BR>*default*: `value` |
| `Button` | `wxButton` | `EVT_BUTTON` | n/a |
| `CheckBox` | `wxCheckBox` | `EVT_CHECKBOX` | `value` -> `bool`<BR>*default*: `value` |
| `Choice` | `wxChoice` | `EVT_CHOICE` | `selection` -> `int`<BR>*default*: `selection` |
| `ComboBox` | `wxComboBox` | `EVT_COMBOBOX` | `selection` -> `int`<BR>`value` -> `std::string`<BR>*default*: `value` |
| `Gauge` | `wxGauge` | n/a | `range` -> `int`<BR>`value` -> `int`<BR>*default*: `value` |
| `Hypertext` | `wxHypertextCtrl` | n/a | n/a |
| `Line` | `wxStaticLine` | n/a | n/a |
| `ListBox` | `wxListBox` | `EVT_LISTBOX` | `selection` -> `int`<BR>*default*: `selection` |
| `RadioBox` | `wxRadioBox` | `EVT_RADIOBOX` | `selection` -> `int`<BR>*default*: `selection` |
| `Slider` | `wxSlider` | `EVT_SLIDER` | `value` -> `int`<BR>*default*: `value` |
| `SpinCtrl` | `wxSpinCtrl` | `EVT_SPINCTRL` | `value` -> `int`<BR>*default*: `value` |
| `Text` | `wxStaticText` | n/a | `label` -> `std::string`<BR>*default*: `label` |
| `TextCtrl` | `wxTextCtrl` | `EVT_TEXT` | `label` -> `std::string`<BR>*default*: `label` |

Additional "Contollers" should be easy to add in future updates.

Expand Down
37 changes: 19 additions & 18 deletions docs/src/docs/ProgrammersGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,24 +195,25 @@ ExtendedExample::Reset() {

The "Controllers" currently supported by `wxUI`:

| wxUI | wxWidget | Default Event | Proxy | Proxy accessors value |
| :------------------- | :--------------------- | :----------------- | :------------------------ | :-------------- |
| `Bitmap` | `wxStaticBitmap` | n/a | `BitmapProxy` | n/a |
| `BitmapButton` | `wxBitmapButton` | `EVT_BUTTON` | `BitmapButtonProxy` | n/a |
| `BitmapComboBox` | `wxBitmapComboBox` | `EVT_COMBOBOX` | `BitmapComboBoxProxy` | `selection` -> `int`<BR>`value` -> `std::string`<BR>*default*: `value` |
| `BitmapToggleButton` | `wxBitmapToggleButton` | `EVT_TOGGLEBUTTON` | `BitmapToggleButtonProxy` | `value` -> `bool`<BR>*default*: `value` |
| `Button` | `wxButton` | `EVT_BUTTON` | `ButtonProxy` | n/a |
| `CheckBox` | `wxCheckBox` | `EVT_CHECKBOX` | `CheckBoxProxy` | `value` -> `bool`<BR>*default*: `value` |
| `Choice` | `wxChoice` | `EVT_CHOICE` | `ChoiceProxy` | `selection` -> `int`<BR>*default*: `selection` |
| `ComboBox` | `wxComboBox` | `EVT_COMBOBOX` | `ComboBoxProxy` | `selection` -> `int`<BR>`value` -> `std::string`<BR>*default*: `value` |
| `Hypertext` | `wxHypertextCtrl` | n/a | `HypertextProxy` | n/a |
| `Line` | `wxStaticLine` | n/a | `LineProxy` | n/a |
| `ListBox` | `wxListBox` | `EVT_LISTBOX` | `ListBoxProxy` | `selection` -> `int`<BR>*default*: `selection` |
| `RadioBox` | `wxRadioBox` | `EVT_RADIOBOX` | `RadioBoxProxy` | `selection` -> `int`<BR>*default*: `selection` |
| `Slider` | `wxSlider` | `EVT_SLIDER` | `SliderProxy` | `value` -> `int`<BR>*default*: `value` |
| `SpinCtrl` | `wxSpinCtrl` | `EVT_SPINCTRL` | `SpinCtrlProxy` | `value` -> `int`<BR>*default*: `value` |
| `Text` | `wxStaticText` | n/a | `TextProxy` | `label` -> `std::string`<BR>*default*: `label` |
| `TextCtrl` | `wxTextCtrl` | `EVT_TEXT` | `TextCtrlProxy` | `label` -> `std::string`<BR>*default*: `label` |
| wxUI | wxWidget | Default Event | Proxy accessors value |
| :------------------- | :--------------------- | :----------------- | :-------------------- |
| `Bitmap` | `wxStaticBitmap` | n/a | n/a |
| `BitmapButton` | `wxBitmapButton` | `EVT_BUTTON` | n/a |
| `BitmapComboBox` | `wxBitmapComboBox` | `EVT_COMBOBOX` | `selection` -> `int`<BR>`value` -> `std::string`<BR>*default*: `value` |
| `BitmapToggleButton` | `wxBitmapToggleButton` | `EVT_TOGGLEBUTTON` | `value` -> `bool`<BR>*default*: `value` |
| `Button` | `wxButton` | `EVT_BUTTON` | n/a |
| `CheckBox` | `wxCheckBox` | `EVT_CHECKBOX` | `value` -> `bool`<BR>*default*: `value` |
| `Choice` | `wxChoice` | `EVT_CHOICE` | `selection` -> `int`<BR>*default*: `selection` |
| `ComboBox` | `wxComboBox` | `EVT_COMBOBOX` | `selection` -> `int`<BR>`value` -> `std::string`<BR>*default*: `value` |
| `Gauge` | `wxGauge` | n/a | `range` -> `int`<BR>`value` -> `int`<BR>*default*: `value` |
| `Hypertext` | `wxHypertextCtrl` | n/a | n/a |
| `Line` | `wxStaticLine` | n/a | n/a |
| `ListBox` | `wxListBox` | `EVT_LISTBOX` | `selection` -> `int`<BR>*default*: `selection` |
| `RadioBox` | `wxRadioBox` | `EVT_RADIOBOX` | `selection` -> `int`<BR>*default*: `selection` |
| `Slider` | `wxSlider` | `EVT_SLIDER` | `value` -> `int`<BR>*default*: `value` |
| `SpinCtrl` | `wxSpinCtrl` | `EVT_SPINCTRL` | `value` -> `int`<BR>*default*: `value` |
| `Text` | `wxStaticText` | n/a | `label` -> `std::string`<BR>*default*: `label` |
| `TextCtrl` | `wxTextCtrl` | `EVT_TEXT` | `label` -> `std::string`<BR>*default*: `label` |

Additional "Contollers" should be easy to add in future updates.

Expand Down
112 changes: 112 additions & 0 deletions include/wxUI/Gauge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
MIT License

Copyright (c) 2022 Richard Powell

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once

#include "GetterSetter.h"
#include "Widget.h"
#include <wx/gauge.h>

#include "HelperMacros.h"

namespace wxUI {

// https://docs.wxwidgets.org/latest/classwx_gauge.html
struct Gauge : public details::WidgetDetails<Gauge, wxGauge> {
using super = details::WidgetDetails<Gauge, wxGauge>;

// clang-format off
struct withRange { };
struct withIdentity { };
// clang-format on

explicit Gauge()
: Gauge(withIdentity {}, wxID_ANY, 100)
{
}

explicit Gauge([[maybe_unused]] withRange unused, int range)
: Gauge(withIdentity {}, wxID_ANY, range)
{
}

explicit Gauge([[maybe_unused]] withIdentity unused, wxWindowID identity, int range = 100)
: super(identity, super::WithStyle { wxGA_HORIZONTAL })
, range(range)
{
}

explicit Gauge(wxSizerFlags const& flags)
: Gauge(flags, withIdentity {}, wxID_ANY, 100)
{
}

explicit Gauge(wxSizerFlags const& flags, [[maybe_unused]] withRange unused, int range)
: Gauge(flags, withIdentity {}, wxID_ANY, range)
{
}

Gauge(wxSizerFlags const& flags, [[maybe_unused]] withIdentity unused, wxWindowID identity, int range = 100)
: super(flags, identity, super::WithStyle { wxGA_HORIZONTAL })
, range(range)
{
}

struct Proxy : details::WidgetProxy<underlying_t> {
PROXY_BOILERPLATE();
[[nodiscard]] auto value() const
{
auto* controller = control();
return details::GetterSetter {
[controller] { return static_cast<int>(controller->GetValue()); },
[controller](int value) { controller->SetValue(value); }
};
}
[[nodiscard]] auto range() const
{
auto* controller = control();
return details::GetterSetter {
[controller] { return static_cast<int>(controller->GetRange()); },
[controller](int range) { controller->SetRange(range); }
};
}

auto operator*() const { return value(); }
};

RULE_OF_SIX_BOILERPLATE(Gauge);

private:
int range;

auto createImpl(wxWindow* parent) -> wxWindow* override
{
auto* widget = new underlying_t(parent, getIdentity(), range, getPos(), getSize(), getStyle());
return setProxy(widget);
}
};

WIDGET_STATIC_ASSERT_BOILERPLATE(Gauge);
}

#include "ZapMacros.h"
1 change: 1 addition & 0 deletions tests/BuildTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ target_sources(wxUI_Tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/ComboBox.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Custom.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ForEach.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Gauge.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Generic.cpp
${CMAKE_CURRENT_SOURCE_DIR}/GetterSetter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/HelperMacros.cpp
Expand Down
38 changes: 38 additions & 0 deletions tests/BuildTests/Gauge.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
MIT License

Copyright (c) 2022 Richard Powell

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// Generated with bash command
// for i in *.cpp; do echo \#include \<wxUI\/Layout.h\> > Layout.cpp; for j in RULE_OF_SIX_BOILERPLATE PROXY_BOILERPLATE WIDGET_STATIC_ASSERT_BOILERPLATE; do echo \#if defined\(WIDGET_STATIC_ASSERT_BOILERPLATE\) >> Layout.cpp; echo \#error Missed zapping WIDGET_STATIC_ASSERT_BOILERPLATE >> Layout.cpp; echo \#endif >> Layout.cpp; done; done
#include <wxUI/Gauge.h>

#if defined(RULE_OF_SIX_BOILERPLATE)
#error Missed zapping RULE_OF_SIX_BOILERPLATE
#endif

#if defined(PROXY_BOILERPLATE)
#error Missed zapping PROXY_BOILERPLATE
#endif

#if defined(WIDGET_STATIC_ASSERT_BOILERPLATE)
#error Missed zapping WIDGET_STATIC_ASSERT_BOILERPLATE
#endif
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_executable(wxUI_Tests
${CMAKE_CURRENT_SOURCE_DIR}/wxUI_ChoiceTests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wxUI_ComboBoxTests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wxUI_ForEachTests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wxUI_GaugeTests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wxUI_GenericTests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wxUI_GetterSetterTests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wxUI_HSplitterTests.cpp
Expand Down
Loading