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
9b64b5d241
commit
7bcbf187d0
@ -62,6 +62,7 @@ All rights reserved.
|
|||||||
#include <Region.h>
|
#include <Region.h>
|
||||||
#include <ScrollBar.h>
|
#include <ScrollBar.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
#include <SupportDefs.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
#include <ObjectListPrivate.h>
|
#include <ObjectListPrivate.h>
|
||||||
@ -4783,16 +4784,20 @@ float
|
|||||||
OutlineView::GetColumnPreferredWidth(BColumn* column)
|
OutlineView::GetColumnPreferredWidth(BColumn* column)
|
||||||
{
|
{
|
||||||
float preferred = 0.0;
|
float preferred = 0.0;
|
||||||
for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow();
|
for (RecursiveOutlineIterator iterator(&fRows); BRow* row =
|
||||||
iterator.GoToNext()) {
|
iterator.CurrentRow(); iterator.GoToNext()) {
|
||||||
BRow* row = iterator.CurrentRow();
|
|
||||||
BField* field = row->GetField(column->fFieldID);
|
BField* field = row->GetField(column->fFieldID);
|
||||||
if (field) {
|
if (field) {
|
||||||
float width = column->GetPreferredWidth(field, this);
|
float width = column->GetPreferredWidth(field, this)
|
||||||
if (preferred < width)
|
+ iterator.CurrentLevel() * kOutlineLevelIndent;
|
||||||
preferred = width;
|
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
|
// Constrain to preferred width. This makes the method do a little
|
||||||
// more than asked, but it's for convenience.
|
// more than asked, but it's for convenience.
|
||||||
if (preferred < column->MinWidth())
|
if (preferred < column->MinWidth())
|
||||||
|
@ -106,9 +106,7 @@ BTitledColumn::FontHeight() const
|
|||||||
float
|
float
|
||||||
BTitledColumn::GetPreferredWidth(BField *_field, BView* parent) const
|
BTitledColumn::GetPreferredWidth(BField *_field, BView* parent) const
|
||||||
{
|
{
|
||||||
BFont font;
|
return parent->StringWidth(fTitle.String()) + 2 * kTEXT_MARGIN;
|
||||||
parent->GetFont(&font);
|
|
||||||
return font.StringWidth(fTitle.String()) + 2 * kTEXT_MARGIN;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -202,11 +200,7 @@ float
|
|||||||
BStringColumn::GetPreferredWidth(BField *_field, BView* parent) const
|
BStringColumn::GetPreferredWidth(BField *_field, BView* parent) const
|
||||||
{
|
{
|
||||||
BStringField* field = static_cast<BStringField*>(_field);
|
BStringField* field = static_cast<BStringField*>(_field);
|
||||||
BFont font;
|
return parent->StringWidth(field->String()) + 2 * kTEXT_MARGIN;
|
||||||
parent->GetFont(&font);
|
|
||||||
float width = font.StringWidth(field->String()) + 2 * kTEXT_MARGIN;
|
|
||||||
float parentWidth = BTitledColumn::GetPreferredWidth(_field, parent);
|
|
||||||
return max_c(width, parentWidth);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user