From d49e0a272c01332969c00f9cf16960c661baf277 Mon Sep 17 00:00:00 2001 From: Alex Wilson Date: Tue, 11 Jan 2011 19:34:05 +0000 Subject: [PATCH] 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 --- src/preferences/media/MediaListItem.cpp | 21 +++++++++++++++++++++ src/preferences/media/MediaWindow.cpp | 22 ++++++++++++++++------ src/preferences/media/MediaWindow.h | 1 + 3 files changed, 38 insertions(+), 6 deletions(-) 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();