Add wxSize::IsAtLeast() helper

This function is trivial but still useful and it doesn't cost much to
have it.
This commit is contained in:
Vadim Zeitlin 2023-08-25 17:41:28 +02:00
parent cc5f5f90b0
commit 15f19d5d0f
3 changed files with 25 additions and 0 deletions

View file

@ -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)

View file

@ -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

View file

@ -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()) );
}