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:
parent
983dbb974b
commit
d49e0a272c
@ -119,6 +119,22 @@ struct MediaListItem::Renderer {
|
|||||||
onto->SetLowColor(lowColor);
|
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:
|
private:
|
||||||
|
|
||||||
const char* fTitle;
|
const char* fTitle;
|
||||||
@ -147,6 +163,11 @@ MediaListItem::Update(BView* owner, const BFont* font)
|
|||||||
if ((Height() < iconHeight + kITEM_MARGIN * 2)) {
|
if ((Height() < iconHeight + kITEM_MARGIN * 2)) {
|
||||||
SetHeight(iconHeight + kITEM_MARGIN * 2);
|
SetHeight(iconHeight + kITEM_MARGIN * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Renderer renderer;
|
||||||
|
renderer.SetTitle(Label());
|
||||||
|
SetRenderParameters(renderer);
|
||||||
|
SetWidth(renderer.ItemWidth());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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
|
void
|
||||||
MediaWindow::_AddNodeItems(NodeList &list, MediaListItem::media_type type)
|
MediaWindow::_AddNodeItems(NodeList &list, MediaListItem::media_type type)
|
||||||
{
|
{
|
||||||
@ -365,16 +378,12 @@ MediaWindow::_EmptyNodeLists()
|
|||||||
void
|
void
|
||||||
MediaWindow::InitWindow()
|
MediaWindow::InitWindow()
|
||||||
{
|
{
|
||||||
const float scrollWidth = 9 * be_plain_font->Size() + 30;
|
|
||||||
|
|
||||||
fListView = new BListView("media_list_view");
|
fListView = new BListView("media_list_view");
|
||||||
fListView->SetSelectionMessage(new BMessage(ML_SELECTED_NODE));
|
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",
|
BScrollView* scrollView = new BScrollView("listscroller",
|
||||||
fListView, 0, false, false, B_FANCY_BORDER);
|
fListView, 0, false, false, B_FANCY_BORDER);
|
||||||
scrollView->SetExplicitMinSize(BSize(scrollWidth, B_SIZE_UNSET));
|
|
||||||
scrollView->SetExplicitMaxSize(BSize(scrollWidth, B_SIZE_UNSET));
|
|
||||||
|
|
||||||
// Create the Views
|
// Create the Views
|
||||||
fTitleView = new BSeparatorView(B_HORIZONTAL, B_FANCY_BORDER);
|
fTitleView = new BSeparatorView(B_HORIZONTAL, B_FANCY_BORDER);
|
||||||
@ -455,7 +464,7 @@ MediaWindow::InitMedia(bool first)
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (fListView->CountItems() > 0)
|
while (fListView->CountItems() > 0)
|
||||||
delete static_cast<MediaListItem*>(fListView->RemoveItem((int32)0));
|
delete fListView->RemoveItem((int32)0);
|
||||||
_EmptyNodeLists();
|
_EmptyNodeLists();
|
||||||
|
|
||||||
// Grab Media Info
|
// Grab Media Info
|
||||||
@ -486,6 +495,7 @@ MediaWindow::InitMedia(bool first)
|
|||||||
fListView->AddItem(mixer);
|
fListView->AddItem(mixer);
|
||||||
|
|
||||||
fListView->SortItems(&MediaListItem::Compare);
|
fListView->SortItems(&MediaListItem::Compare);
|
||||||
|
_UpdateListViewMinWidth();
|
||||||
|
|
||||||
// Set default nodes for our setting views
|
// Set default nodes for our setting views
|
||||||
media_node default_node;
|
media_node default_node;
|
||||||
|
@ -74,6 +74,7 @@ private:
|
|||||||
void _AddNodeItems(NodeList &from,
|
void _AddNodeItems(NodeList &from,
|
||||||
MediaListItem::media_type type);
|
MediaListItem::media_type type);
|
||||||
void _EmptyNodeLists();
|
void _EmptyNodeLists();
|
||||||
|
void _UpdateListViewMinWidth();
|
||||||
|
|
||||||
NodeListItem* _FindNodeListItem(dormant_node_info* info);
|
NodeListItem* _FindNodeListItem(dormant_node_info* info);
|
||||||
void InitWindow();
|
void InitWindow();
|
||||||
|
Loading…
Reference in New Issue
Block a user