From 15f19d5d0ff2b9455bf2045e2c70eb0ea4333f10 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 25 Aug 2023 17:41:28 +0200 Subject: [PATCH] Add wxSize::IsAtLeast() helper This function is trivial but still useful and it doesn't cost much to have it. --- include/wx/gdicmn.h | 4 ++++ interface/wx/gdicmn.h | 8 ++++++++ tests/geometry/size.cpp | 13 +++++++++++++ 3 files changed, 25 insertions(+) diff --git a/include/wx/gdicmn.h b/include/wx/gdicmn.h index 236ba350ee..5f7b881cca 100644 --- a/include/wx/gdicmn.h +++ b/include/wx/gdicmn.h @@ -332,6 +332,10 @@ public: bool IsFullySpecified() const { return x != wxDefaultCoord && y != wxDefaultCoord; } + // Check that this size object is at least as big as the other one in both + // directions. + bool IsAtLeast(const wxSize& sz) const { return x >= sz.x && y >= sz.y; } + // combine this size with the other one replacing the default (i.e. equal // to wxDefaultCoord) components of this object with those of the other void SetDefaults(const wxSize& size) diff --git a/interface/wx/gdicmn.h b/interface/wx/gdicmn.h index 822c338a67..c512a99a3b 100644 --- a/interface/wx/gdicmn.h +++ b/interface/wx/gdicmn.h @@ -1037,6 +1037,14 @@ public: */ void IncTo(const wxSize& size); + /** + Returns @true if this size is at least as big as the other one in both + directions. + + @since 3.3.0 + */ + bool IsAtLeast(const wxSize& size) const; + /** Returns @true if neither of the size object components is equal to -1, which is used as default for the size values in wxWidgets (hence the diff --git a/tests/geometry/size.cpp b/tests/geometry/size.cpp index 15ede6e524..a9c2f7d8a6 100644 --- a/tests/geometry/size.cpp +++ b/tests/geometry/size.cpp @@ -51,3 +51,16 @@ TEST_CASE("wxSize::Operators", "[size]") CHECK( wxSize(6, 9) / 1.5 == wxSize(4, 6) ); } + +TEST_CASE("wxSize::Functions", "[size]") +{ + CHECK( wxSize(10, 10).IsAtLeast(wxDefaultSize) ); + CHECK( wxSize(10, 10).IsAtLeast(wxSize()) ); + CHECK( wxSize(10, 10).IsAtLeast(wxSize(10, 5)) ); + CHECK( wxSize(10, 10).IsAtLeast(wxSize(10, 10)) ); + + CHECK_FALSE( wxSize(10, 10).IsAtLeast(wxSize(11, 10)) ); + CHECK_FALSE( wxSize(10, 10).IsAtLeast(wxSize(10, 11)) ); + CHECK_FALSE( wxSize(10, 10).IsAtLeast(wxSize(11, 11)) ); + CHECK_FALSE( wxDefaultSize.IsAtLeast(wxSize()) ); +}