diff --git a/src/preferences/media/MediaListItem.cpp b/src/preferences/media/MediaListItem.cpp index 02cb7b2740..cfd6f51b09 100644 --- a/src/preferences/media/MediaListItem.cpp +++ b/src/preferences/media/MediaListItem.cpp @@ -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()); } diff --git a/src/preferences/media/MediaWindow.cpp b/src/preferences/media/MediaWindow.cpp index 6351456d4a..970816250e 100644 --- a/src/preferences/media/MediaWindow.cpp +++ b/src/preferences/media/MediaWindow.cpp @@ -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(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; diff --git a/src/preferences/media/MediaWindow.h b/src/preferences/media/MediaWindow.h index abbd737b07..ec3967da37 100644 --- a/src/preferences/media/MediaWindow.h +++ b/src/preferences/media/MediaWindow.h @@ -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();