It was a bad idea to calculate the text margin when drawing the first column.

Now it is explicitely calculated, which makes getting the preferred size
more reliable.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32852 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2009-08-31 11:38:03 +00:00
parent b439d6e573
commit e5f148ddec
2 changed files with 32 additions and 19 deletions
+25 -16
View File
@@ -42,7 +42,7 @@ BBitmapStringField::SetBitmap(BBitmap* bitmap)
// #pragma mark - PartitionColumn
float PartitionColumn::fTextMargin = 0.0;
float PartitionColumn::sTextMargin = 0.0;
PartitionColumn::PartitionColumn(const char* title, float width, float minWidth,
@@ -57,14 +57,6 @@ PartitionColumn::PartitionColumn(const char* title, float width, float minWidth,
void
PartitionColumn::DrawField(BField* field, BRect rect, BView* parent)
{
if (fTextMargin == 0.0) {
// we are the first column to draw something and need to
// init the text margin
BFont font;
parent->GetFont(&font);
fTextMargin = ceilf(font.Size() * 0.8);
}
BBitmapStringField* bitmapField
= dynamic_cast<BBitmapStringField*>(field);
BStringField* stringField = dynamic_cast<BStringField*>(field);
@@ -82,14 +74,14 @@ PartitionColumn::DrawField(BField* field, BRect rect, BView* parent)
default:
case B_ALIGN_LEFT:
case B_ALIGN_CENTER:
x = rect.left + fTextMargin;
width = rect.right - (x + r.Width()) - (2 * fTextMargin);
x = rect.left + sTextMargin;
width = rect.right - (x + r.Width()) - (2 * sTextMargin);
r.Set(x + r.Width(), rect.top, rect.right - width, rect.bottom);
break;
case B_ALIGN_RIGHT:
x = rect.right - fTextMargin - r.Width();
width = (x - rect.left - (2 * fTextMargin));
x = rect.right - sTextMargin - r.Width();
width = (x - rect.left - (2 * sTextMargin));
r.Set(rect.left, rect.top, rect.left + width, rect.bottom);
break;
}
@@ -113,7 +105,7 @@ PartitionColumn::DrawField(BField* field, BRect rect, BView* parent)
} else if (stringField) {
float width = rect.Width() - (2 * fTextMargin);
float width = rect.Width() - (2 * sTextMargin);
if (width != stringField->Width()) {
BString truncatedString(stringField->String());
@@ -142,7 +134,7 @@ PartitionColumn::GetPreferredWidth(BField *_field, BView* parent) const
const BBitmap* bitmap = bitmapField->Bitmap();
BFont font;
parent->GetFont(&font);
width = font.StringWidth(bitmapField->String()) + 3 * fTextMargin;
width = font.StringWidth(bitmapField->String()) + 3 * sTextMargin;
if (bitmap)
width += bitmap->Bounds().Width();
else
@@ -150,7 +142,7 @@ PartitionColumn::GetPreferredWidth(BField *_field, BView* parent) const
} else if (stringField) {
BFont font;
parent->GetFont(&font);
width = font.StringWidth(stringField->String()) + 2 * fTextMargin;
width = font.StringWidth(stringField->String()) + 2 * sTextMargin;
}
return max_c(width, parentWidth);
}
@@ -163,6 +155,15 @@ PartitionColumn::AcceptsField(const BField* field) const
}
void
PartitionColumn::InitTextMargin(BView* parent)
{
BFont font;
parent->GetFont(&font);
sTextMargin = ceilf(font.Size() * 0.8);
}
// #pragma mark - PartitionListRow
@@ -261,6 +262,14 @@ PartitionListView::PartitionListView(const BRect& frame, uint32 resizeMode)
}
void
PartitionListView::AttachedToWindow()
{
Inherited::AttachedToWindow();
PartitionColumn::InitTextMargin(ScrollView());
}
PartitionListRow*
PartitionListView::FindRow(partition_id id, PartitionListRow* parent)
{
+7 -3
View File
@@ -53,9 +53,11 @@ public:
virtual bool AcceptsField(const BField* field) const;
static void InitTextMargin(BView* parent);
private:
uint32 fTruncateMode;
static float fTextMargin;
static float sTextMargin;
};
@@ -66,7 +68,7 @@ public:
PartitionListRow(BPartition* partition);
PartitionListRow(partition_id parentID,
partition_id id, off_t offset, off_t size);
partition_id ID() const
{ return fPartitionID; }
partition_id ParentID() const
@@ -88,7 +90,9 @@ class PartitionListView : public BColumnListView {
public:
PartitionListView(const BRect& frame,
uint32 resizeMode);
virtual void AttachedToWindow();
PartitionListRow* FindRow(partition_id id,
PartitionListRow* parent = NULL);
PartitionListRow* AddPartition(BPartition* partition);