Set item colors in BListView instead of BStringItem

* Fixes #3970 without introducing the bugs from BeOS
* Makes it easy to override BStringItem just to change the text color.
* Makes it easy to implement custom list items using the correct colors.
This commit is contained in:
Adrien Destugues 2014-12-10 13:31:23 +01:00
parent 524288065b
commit cbb8ebbbbb
2 changed files with 17 additions and 18 deletions

View File

@ -207,8 +207,23 @@ BListView::Draw(BRect updateRect)
BListItem* item = ItemAt(i);
itemFrame.bottom = itemFrame.top + ceilf(item->Height()) - 1;
if (itemFrame.Intersects(updateRect))
rgb_color textColor = ui_color(B_LIST_ITEM_TEXT_COLOR);
rgb_color disabledColor;
if (textColor.red + textColor.green + textColor.blue > 128 * 3)
disabledColor = tint_color(textColor, B_DARKEN_2_TINT);
else
disabledColor = tint_color(textColor, B_LIGHTEN_2_TINT);
if (itemFrame.Intersects(updateRect)) {
if (!item->IsEnabled())
SetHighColor(disabledColor);
else if (item->IsSelected())
SetHighColor(ui_color(B_LIST_SELECTED_ITEM_TEXT_COLOR));
else
SetHighColor(ui_color(B_LIST_ITEM_TEXT_COLOR));
DrawItem(item, itemFrame);
}
itemFrame.top = itemFrame.bottom + 1;
}

View File

@ -75,7 +75,6 @@ BStringItem::DrawItem(BView* owner, BRect frame, bool complete)
if (fText == NULL)
return;
rgb_color highColor = owner->HighColor();
rgb_color lowColor = owner->LowColor();
if (IsSelected() || complete) {
@ -86,30 +85,15 @@ BStringItem::DrawItem(BView* owner, BRect frame, bool complete)
color = owner->ViewColor();
owner->SetLowColor(color);
owner->SetHighColor(color);
owner->FillRect(frame);
owner->FillRect(frame, B_SOLID_LOW);
} else
owner->SetLowColor(owner->ViewColor());
owner->MovePenTo(frame.left + be_control_look->DefaultLabelSpacing(),
frame.top + fBaselineOffset);
if (!IsEnabled()) {
rgb_color textColor = ui_color(B_LIST_ITEM_TEXT_COLOR);
if (textColor.red + textColor.green + textColor.blue > 128 * 3)
owner->SetHighColor(tint_color(textColor, B_DARKEN_2_TINT));
else
owner->SetHighColor(tint_color(textColor, B_LIGHTEN_2_TINT));
} else {
if (IsSelected())
owner->SetHighColor(ui_color(B_LIST_SELECTED_ITEM_TEXT_COLOR));
else
owner->SetHighColor(ui_color(B_LIST_ITEM_TEXT_COLOR));
}
owner->DrawString(fText);
owner->SetHighColor(highColor);
owner->SetLowColor(lowColor);
}