HaikuDepot: Re-invalidate and re-derive labels in ItemCountView sporadically.
Instead of unconditionally calling _DeriveLabel() and Invalidate() every time (both expensive operations), use a bool to track whether we've already invalidated, and derive the label in Draw() if it was set. Significantly decreases the invalidations done on full-list rebuilds.
This commit is contained in:
@@ -801,7 +801,8 @@ public:
|
|||||||
ItemCountView()
|
ItemCountView()
|
||||||
:
|
:
|
||||||
BView("item count view", B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
|
BView("item count view", B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
|
||||||
fItemCount(0)
|
fItemCount(0),
|
||||||
|
fInvalidated(false)
|
||||||
{
|
{
|
||||||
BFont font(be_plain_font);
|
BFont font(be_plain_font);
|
||||||
font.SetSize(font.Size() * 0.75f);
|
font.SetSize(font.Size() * 0.75f);
|
||||||
@@ -834,6 +835,11 @@ public:
|
|||||||
|
|
||||||
virtual void Draw(BRect updateRect)
|
virtual void Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
|
if (fInvalidated) {
|
||||||
|
fLabel = _DeriveLabel(fItemCount);
|
||||||
|
fInvalidated = false;
|
||||||
|
}
|
||||||
|
|
||||||
FillRect(updateRect, B_SOLID_LOW);
|
FillRect(updateRect, B_SOLID_LOW);
|
||||||
|
|
||||||
font_height fontHeight;
|
font_height fontHeight;
|
||||||
@@ -855,19 +861,20 @@ public:
|
|||||||
{
|
{
|
||||||
if (count == fItemCount)
|
if (count == fItemCount)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fItemCount = count;
|
fItemCount = count;
|
||||||
fLabel = _DeriveLabel(fItemCount);
|
if (!fInvalidated) {
|
||||||
Invalidate();
|
Invalidate();
|
||||||
|
fInvalidated = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/*! This method is hit quite often when the list of packages in the
|
||||||
/*! This method is hit quite often when the list of packages in the
|
table-view are updated. Derivation of the plural for some
|
||||||
table-view are updated. Derivation of the plural for some
|
languages such as Russian can be slow so this method should be
|
||||||
languages such as Russian can be slow so this method should be
|
called sparingly.
|
||||||
called sparingly.
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
BString _DeriveLabel(int32 count) const
|
BString _DeriveLabel(int32 count) const
|
||||||
{
|
{
|
||||||
static BStringFormat format(B_TRANSLATE("{0, plural, "
|
static BStringFormat format(B_TRANSLATE("{0, plural, "
|
||||||
@@ -877,9 +884,12 @@ private:
|
|||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
int32 fItemCount;
|
int32 fItemCount;
|
||||||
BString fLabel;
|
BString fLabel;
|
||||||
BSize fMinSize;
|
BSize fMinSize;
|
||||||
|
|
||||||
|
bool fInvalidated;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user