Add wxBitmapBundle::GetConsensusSizeFor(double) and test it
Add an overload of the existing function which can be easily tested in the unit tests and add a trivial new test for it.
This commit is contained in:
@@ -152,7 +152,11 @@ public:
|
||||
// Implementation only from now on.
|
||||
|
||||
// Get the bitmap size preferred by the majority of the elements of the
|
||||
// bundles at the scale appropriate for the given scale.
|
||||
// bundles at the given scale or the scale appropriate for the given window.
|
||||
static wxSize
|
||||
GetConsensusSizeFor(double scale,
|
||||
const wxVector<wxBitmapBundle>& bundles,
|
||||
const wxSize& sizeDefault);
|
||||
static wxSize
|
||||
GetConsensusSizeFor(wxWindow* win,
|
||||
const wxVector<wxBitmapBundle>& bundles,
|
||||
|
||||
@@ -596,7 +596,15 @@ wxBitmapBundle::GetConsensusSizeFor(wxWindow* win,
|
||||
const wxVector<wxBitmapBundle>& bundles,
|
||||
const wxSize& sizeDefault)
|
||||
{
|
||||
const double scale = win->GetDPIScaleFactor();
|
||||
return GetConsensusSizeFor(win->GetDPIScaleFactor(), bundles, sizeDefault);
|
||||
}
|
||||
|
||||
/* static */
|
||||
wxSize
|
||||
wxBitmapBundle::GetConsensusSizeFor(double scale,
|
||||
const wxVector<wxBitmapBundle>& bundles,
|
||||
const wxSize& sizeDefault)
|
||||
{
|
||||
const wxSize sizeIdeal = sizeDefault*scale;
|
||||
|
||||
// We want to use preferred bitmap size, but the preferred sizes can be
|
||||
|
||||
@@ -460,3 +460,34 @@ TEST_CASE("BitmapBundle::Scale", "[bmpbundle][scale]")
|
||||
}
|
||||
|
||||
#endif // ports with scaled bitmaps support
|
||||
|
||||
TEST_CASE("BitmapBundle::GetConsensusSize", "[bmpbundle]")
|
||||
{
|
||||
// Just a trivial helper to make writing the tests below simpler.
|
||||
struct Bundles
|
||||
{
|
||||
wxVector<wxBitmapBundle> vec;
|
||||
|
||||
void Add(int size)
|
||||
{
|
||||
vec.push_back(wxBitmapBundle::FromBitmap(wxSize(size, size)));
|
||||
}
|
||||
|
||||
int GetConsensusSize(double scale) const
|
||||
{
|
||||
return wxBitmapBundle::GetConsensusSizeFor(scale, vec, wxSize()).y;
|
||||
}
|
||||
} bundles;
|
||||
|
||||
// When there is a tie, a larger size is chosen by default.
|
||||
bundles.Add(16);
|
||||
bundles.Add(24);
|
||||
CHECK( bundles.GetConsensusSize(2) == 48 );
|
||||
|
||||
// Breaking the tie results in the smaller size winning now.
|
||||
bundles.Add(16);
|
||||
CHECK( bundles.GetConsensusSize(2) == 32 );
|
||||
|
||||
// Integer scaling factors should be preferred.
|
||||
CHECK( bundles.GetConsensusSize(1.5) == 16 );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user