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:
parent
524288065b
commit
cbb8ebbbbb
@ -207,8 +207,23 @@ BListView::Draw(BRect updateRect)
|
|||||||
BListItem* item = ItemAt(i);
|
BListItem* item = ItemAt(i);
|
||||||
itemFrame.bottom = itemFrame.top + ceilf(item->Height()) - 1;
|
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);
|
DrawItem(item, itemFrame);
|
||||||
|
}
|
||||||
|
|
||||||
itemFrame.top = itemFrame.bottom + 1;
|
itemFrame.top = itemFrame.bottom + 1;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,6 @@ BStringItem::DrawItem(BView* owner, BRect frame, bool complete)
|
|||||||
if (fText == NULL)
|
if (fText == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
rgb_color highColor = owner->HighColor();
|
|
||||||
rgb_color lowColor = owner->LowColor();
|
rgb_color lowColor = owner->LowColor();
|
||||||
|
|
||||||
if (IsSelected() || complete) {
|
if (IsSelected() || complete) {
|
||||||
@ -86,30 +85,15 @@ BStringItem::DrawItem(BView* owner, BRect frame, bool complete)
|
|||||||
color = owner->ViewColor();
|
color = owner->ViewColor();
|
||||||
|
|
||||||
owner->SetLowColor(color);
|
owner->SetLowColor(color);
|
||||||
owner->SetHighColor(color);
|
owner->FillRect(frame, B_SOLID_LOW);
|
||||||
owner->FillRect(frame);
|
|
||||||
} else
|
} else
|
||||||
owner->SetLowColor(owner->ViewColor());
|
owner->SetLowColor(owner->ViewColor());
|
||||||
|
|
||||||
owner->MovePenTo(frame.left + be_control_look->DefaultLabelSpacing(),
|
owner->MovePenTo(frame.left + be_control_look->DefaultLabelSpacing(),
|
||||||
frame.top + fBaselineOffset);
|
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->DrawString(fText);
|
||||||
|
|
||||||
owner->SetHighColor(highColor);
|
|
||||||
owner->SetLowColor(lowColor);
|
owner->SetLowColor(lowColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user