Optimize column preferred width calculation a bit.
Move calculating the width of the column title itself out to OutlineView::GetColumnPreferredWidth(). Previously, each pass would compute the width of both the field itself and the column title, leading to considerable redundant work. Also, take outline level indent into account in the resulting width. Should improve performance a bit.
This commit is contained in:
parent
aab6f715c9
commit
f4677735ca
@ -62,6 +62,7 @@ All rights reserved.
|
||||
#include <Region.h>
|
||||
#include <ScrollBar.h>
|
||||
#include <String.h>
|
||||
#include <SupportDefs.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include <ObjectListPrivate.h>
|
||||
@ -4783,16 +4784,20 @@ float
|
||||
OutlineView::GetColumnPreferredWidth(BColumn* column)
|
||||
{
|
||||
float preferred = 0.0;
|
||||
for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow();
|
||||
iterator.GoToNext()) {
|
||||
BRow* row = iterator.CurrentRow();
|
||||
for (RecursiveOutlineIterator iterator(&fRows); BRow* row =
|
||||
iterator.CurrentRow(); iterator.GoToNext()) {
|
||||
BField* field = row->GetField(column->fFieldID);
|
||||
if (field) {
|
||||
float width = column->GetPreferredWidth(field, this);
|
||||
if (preferred < width)
|
||||
preferred = width;
|
||||
float width = column->GetPreferredWidth(field, this)
|
||||
+ iterator.CurrentLevel() * kOutlineLevelIndent;
|
||||
preferred = max_c(preferred, width);
|
||||
}
|
||||
}
|
||||
|
||||
BString name;
|
||||
column->GetColumnName(&name);
|
||||
preferred = max_c(preferred, StringWidth(name));
|
||||
|
||||
// Constrain to preferred width. This makes the method do a little
|
||||
// more than asked, but it's for convenience.
|
||||
if (preferred < column->MinWidth())
|
||||
|
@ -106,9 +106,7 @@ BTitledColumn::FontHeight() const
|
||||
float
|
||||
BTitledColumn::GetPreferredWidth(BField *_field, BView* parent) const
|
||||
{
|
||||
BFont font;
|
||||
parent->GetFont(&font);
|
||||
return font.StringWidth(fTitle.String()) + 2 * kTEXT_MARGIN;
|
||||
return parent->StringWidth(fTitle.String()) + 2 * kTEXT_MARGIN;
|
||||
}
|
||||
|
||||
|
||||
@ -202,11 +200,7 @@ float
|
||||
BStringColumn::GetPreferredWidth(BField *_field, BView* parent) const
|
||||
{
|
||||
BStringField* field = static_cast<BStringField*>(_field);
|
||||
BFont font;
|
||||
parent->GetFont(&font);
|
||||
float width = font.StringWidth(field->String()) + 2 * kTEXT_MARGIN;
|
||||
float parentWidth = BTitledColumn::GetPreferredWidth(_field, parent);
|
||||
return max_c(width, parentWidth);
|
||||
return parent->StringWidth(field->String()) + 2 * kTEXT_MARGIN;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user