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:
@@ -42,7 +42,7 @@ BBitmapStringField::SetBitmap(BBitmap* bitmap)
|
|||||||
// #pragma mark - PartitionColumn
|
// #pragma mark - PartitionColumn
|
||||||
|
|
||||||
|
|
||||||
float PartitionColumn::fTextMargin = 0.0;
|
float PartitionColumn::sTextMargin = 0.0;
|
||||||
|
|
||||||
|
|
||||||
PartitionColumn::PartitionColumn(const char* title, float width, float minWidth,
|
PartitionColumn::PartitionColumn(const char* title, float width, float minWidth,
|
||||||
@@ -57,14 +57,6 @@ PartitionColumn::PartitionColumn(const char* title, float width, float minWidth,
|
|||||||
void
|
void
|
||||||
PartitionColumn::DrawField(BField* field, BRect rect, BView* parent)
|
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
|
BBitmapStringField* bitmapField
|
||||||
= dynamic_cast<BBitmapStringField*>(field);
|
= dynamic_cast<BBitmapStringField*>(field);
|
||||||
BStringField* stringField = dynamic_cast<BStringField*>(field);
|
BStringField* stringField = dynamic_cast<BStringField*>(field);
|
||||||
@@ -82,14 +74,14 @@ PartitionColumn::DrawField(BField* field, BRect rect, BView* parent)
|
|||||||
default:
|
default:
|
||||||
case B_ALIGN_LEFT:
|
case B_ALIGN_LEFT:
|
||||||
case B_ALIGN_CENTER:
|
case B_ALIGN_CENTER:
|
||||||
x = rect.left + fTextMargin;
|
x = rect.left + sTextMargin;
|
||||||
width = rect.right - (x + r.Width()) - (2 * fTextMargin);
|
width = rect.right - (x + r.Width()) - (2 * sTextMargin);
|
||||||
r.Set(x + r.Width(), rect.top, rect.right - width, rect.bottom);
|
r.Set(x + r.Width(), rect.top, rect.right - width, rect.bottom);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_ALIGN_RIGHT:
|
case B_ALIGN_RIGHT:
|
||||||
x = rect.right - fTextMargin - r.Width();
|
x = rect.right - sTextMargin - r.Width();
|
||||||
width = (x - rect.left - (2 * fTextMargin));
|
width = (x - rect.left - (2 * sTextMargin));
|
||||||
r.Set(rect.left, rect.top, rect.left + width, rect.bottom);
|
r.Set(rect.left, rect.top, rect.left + width, rect.bottom);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -113,7 +105,7 @@ PartitionColumn::DrawField(BField* field, BRect rect, BView* parent)
|
|||||||
|
|
||||||
} else if (stringField) {
|
} else if (stringField) {
|
||||||
|
|
||||||
float width = rect.Width() - (2 * fTextMargin);
|
float width = rect.Width() - (2 * sTextMargin);
|
||||||
|
|
||||||
if (width != stringField->Width()) {
|
if (width != stringField->Width()) {
|
||||||
BString truncatedString(stringField->String());
|
BString truncatedString(stringField->String());
|
||||||
@@ -142,7 +134,7 @@ PartitionColumn::GetPreferredWidth(BField *_field, BView* parent) const
|
|||||||
const BBitmap* bitmap = bitmapField->Bitmap();
|
const BBitmap* bitmap = bitmapField->Bitmap();
|
||||||
BFont font;
|
BFont font;
|
||||||
parent->GetFont(&font);
|
parent->GetFont(&font);
|
||||||
width = font.StringWidth(bitmapField->String()) + 3 * fTextMargin;
|
width = font.StringWidth(bitmapField->String()) + 3 * sTextMargin;
|
||||||
if (bitmap)
|
if (bitmap)
|
||||||
width += bitmap->Bounds().Width();
|
width += bitmap->Bounds().Width();
|
||||||
else
|
else
|
||||||
@@ -150,7 +142,7 @@ PartitionColumn::GetPreferredWidth(BField *_field, BView* parent) const
|
|||||||
} else if (stringField) {
|
} else if (stringField) {
|
||||||
BFont font;
|
BFont font;
|
||||||
parent->GetFont(&font);
|
parent->GetFont(&font);
|
||||||
width = font.StringWidth(stringField->String()) + 2 * fTextMargin;
|
width = font.StringWidth(stringField->String()) + 2 * sTextMargin;
|
||||||
}
|
}
|
||||||
return max_c(width, parentWidth);
|
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
|
// #pragma mark - PartitionListRow
|
||||||
|
|
||||||
|
|
||||||
@@ -261,6 +262,14 @@ PartitionListView::PartitionListView(const BRect& frame, uint32 resizeMode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PartitionListView::AttachedToWindow()
|
||||||
|
{
|
||||||
|
Inherited::AttachedToWindow();
|
||||||
|
PartitionColumn::InitTextMargin(ScrollView());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PartitionListRow*
|
PartitionListRow*
|
||||||
PartitionListView::FindRow(partition_id id, PartitionListRow* parent)
|
PartitionListView::FindRow(partition_id id, PartitionListRow* parent)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -53,9 +53,11 @@ public:
|
|||||||
|
|
||||||
virtual bool AcceptsField(const BField* field) const;
|
virtual bool AcceptsField(const BField* field) const;
|
||||||
|
|
||||||
|
static void InitTextMargin(BView* parent);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32 fTruncateMode;
|
uint32 fTruncateMode;
|
||||||
static float fTextMargin;
|
static float sTextMargin;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -89,6 +91,8 @@ public:
|
|||||||
PartitionListView(const BRect& frame,
|
PartitionListView(const BRect& frame,
|
||||||
uint32 resizeMode);
|
uint32 resizeMode);
|
||||||
|
|
||||||
|
virtual void AttachedToWindow();
|
||||||
|
|
||||||
PartitionListRow* FindRow(partition_id id,
|
PartitionListRow* FindRow(partition_id id,
|
||||||
PartitionListRow* parent = NULL);
|
PartitionListRow* parent = NULL);
|
||||||
PartitionListRow* AddPartition(BPartition* partition);
|
PartitionListRow* AddPartition(BPartition* partition);
|
||||||
|
|||||||
Reference in New Issue
Block a user