In Media preflet: add an ItemWidth() method to MediaListItem::Renderer, which tells us how much space is needed onscreen for a MediaListItem. Use the new ItemWidth() method in MediaListItem::Update() to set our width. Add a MediaWindow::_UpdateListItemMinSize() method that uses the items' width to calculate the new explicit min width of our list view. This fixes a problem I saw with localized strings in the listview not being fully displayed.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40207 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Alex Wilson 2011-01-11 19:34:05 +00:00
parent 983dbb974b
commit d49e0a272c
3 changed files with 38 additions and 6 deletions

View File

@ -119,6 +119,22 @@ struct MediaListItem::Renderer {
onto->SetLowColor(lowColor);
}
float ItemWidth()
{
float width = 4.0f;
// left margin
float iconSpace = MediaIcons::sBounds.Width() + 1.0f;
if (fDoubleInsets)
iconSpace *= 2.0f;
width += iconSpace;
width += 8.0f;
// space between icons and text
width += be_plain_font->StringWidth(fTitle) + 3.0f;
return width;
}
private:
const char* fTitle;
@ -147,6 +163,11 @@ MediaListItem::Update(BView* owner, const BFont* font)
if ((Height() < iconHeight + kITEM_MARGIN * 2)) {
SetHeight(iconHeight + kITEM_MARGIN * 2);
}
Renderer renderer;
renderer.SetTitle(Label());
SetRenderParameters(renderer);
SetWidth(renderer.ItemWidth());
}

View File

@ -340,6 +340,19 @@ MediaWindow::_FindNodeListItem(dormant_node_info* info)
}
void
MediaWindow::_UpdateListViewMinWidth()
{
float width = 0;
for (int32 i = 0; i < fListView->CountItems(); i++) {
BListItem* item = fListView->ItemAt(i);
width = max_c(width, item->Width());
}
fListView->SetExplicitMinSize(BSize(width, B_SIZE_UNSET));
fListView->InvalidateLayout();
}
void
MediaWindow::_AddNodeItems(NodeList &list, MediaListItem::media_type type)
{
@ -365,16 +378,12 @@ MediaWindow::_EmptyNodeLists()
void
MediaWindow::InitWindow()
{
const float scrollWidth = 9 * be_plain_font->Size() + 30;
fListView = new BListView("media_list_view");
fListView->SetSelectionMessage(new BMessage(ML_SELECTED_NODE));
// Add ScrollView to Media Menu
// Add ScrollView to Media Menu for pretty border
BScrollView* scrollView = new BScrollView("listscroller",
fListView, 0, false, false, B_FANCY_BORDER);
scrollView->SetExplicitMinSize(BSize(scrollWidth, B_SIZE_UNSET));
scrollView->SetExplicitMaxSize(BSize(scrollWidth, B_SIZE_UNSET));
// Create the Views
fTitleView = new BSeparatorView(B_HORIZONTAL, B_FANCY_BORDER);
@ -455,7 +464,7 @@ MediaWindow::InitMedia(bool first)
}
while (fListView->CountItems() > 0)
delete static_cast<MediaListItem*>(fListView->RemoveItem((int32)0));
delete fListView->RemoveItem((int32)0);
_EmptyNodeLists();
// Grab Media Info
@ -486,6 +495,7 @@ MediaWindow::InitMedia(bool first)
fListView->AddItem(mixer);
fListView->SortItems(&MediaListItem::Compare);
_UpdateListViewMinWidth();
// Set default nodes for our setting views
media_node default_node;

View File

@ -74,6 +74,7 @@ private:
void _AddNodeItems(NodeList &from,
MediaListItem::media_type type);
void _EmptyNodeLists();
void _UpdateListViewMinWidth();
NodeListItem* _FindNodeListItem(dormant_node_info* info);
void InitWindow();