Fix update issues in BStringColumn.
In some cases, BStringColumn wouldn't properly detect that an update was needed, and would consequently fail to truncate a string as needed with a column resize.
This commit is contained in:
parent
9187efd1a9
commit
69d85497fd
@ -60,6 +60,7 @@ class BStringField : public BField
|
||||
void SetString (const char* string);
|
||||
const char* String () const;
|
||||
void SetClippedString (const char* string);
|
||||
bool HasClippedString () const;
|
||||
const char* ClippedString ();
|
||||
void SetWidth (float);
|
||||
float Width ();
|
||||
|
@ -159,6 +159,13 @@ BStringField::SetClippedString(const char* val)
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BStringField::HasClippedString() const
|
||||
{
|
||||
return !fClippedString.IsEmpty();
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
BStringField::ClippedString()
|
||||
{
|
||||
@ -182,17 +189,22 @@ BStringColumn::DrawField(BField* _field, BRect rect, BView* parent)
|
||||
{
|
||||
float width = rect.Width() - (2 * kTEXT_MARGIN);
|
||||
BStringField* field = static_cast<BStringField*>(_field);
|
||||
bool clipNeeded = width < field->Width();
|
||||
float fieldWidth = field->Width();
|
||||
bool updateNeeded = width != fieldWidth;
|
||||
|
||||
if (clipNeeded) {
|
||||
if (updateNeeded) {
|
||||
BString out_string(field->String());
|
||||
|
||||
float preferredWidth = parent->StringWidth(out_string.String());
|
||||
if (width < preferredWidth) {
|
||||
parent->TruncateString(&out_string, fTruncate, width + 2);
|
||||
field->SetClippedString(out_string.String());
|
||||
} else
|
||||
field->SetClippedString("");
|
||||
field->SetWidth(width);
|
||||
}
|
||||
|
||||
DrawString(clipNeeded ? field->ClippedString() : field->String(), parent, rect);
|
||||
DrawString(field->HasClippedString() ? field->ClippedString()
|
||||
: field->String(), parent, rect);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user