More or less correctly implemented GetPreferredSize().
The menu bar is now resized to a proper size. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14790 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -465,9 +465,39 @@ void BMenuField::ResizeToPreferred()
|
|||||||
BView::ResizeToPreferred();
|
BView::ResizeToPreferred();
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BMenuField::GetPreferredSize(float *width, float *height)
|
void
|
||||||
|
BMenuField::GetPreferredSize(float *_width, float *_height)
|
||||||
{
|
{
|
||||||
BView::GetPreferredSize(width, height);
|
BView::GetPreferredSize(_width, _height);
|
||||||
|
|
||||||
|
if (!fFixedSizeMB) {
|
||||||
|
BMenu* menu = Menu();
|
||||||
|
float width = 0;
|
||||||
|
|
||||||
|
if (menu != NULL) {
|
||||||
|
if (menu->IsLabelFromMarked()) {
|
||||||
|
// find the width of the largest item
|
||||||
|
for (int32 i = menu->CountItems(); i-- > 0;) {
|
||||||
|
BMenuItem* item = menu->ItemAt(i);
|
||||||
|
|
||||||
|
if (item != NULL && item->Label() != NULL) {
|
||||||
|
float labelWidth = StringWidth(item->Label());
|
||||||
|
if (labelWidth > width)
|
||||||
|
width = labelWidth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (menu->Superitem() != NULL)
|
||||||
|
width = StringWidth(menu->Superitem()->Label());
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: fix these values (they should match the visual appearance)
|
||||||
|
*_width = width + 45 + fDivider;
|
||||||
|
|
||||||
|
if (Label())
|
||||||
|
*_width += StringWidth(Label()) + 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
*_height = fMenuBar->Bounds().Height();
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
status_t BMenuField::Perform(perform_code d, void *arg)
|
status_t BMenuField::Perform(perform_code d, void *arg)
|
||||||
@@ -508,6 +538,15 @@ void BMenuField::InitObject(const char *label)
|
|||||||
void BMenuField::InitObject2()
|
void BMenuField::InitObject2()
|
||||||
{
|
{
|
||||||
// TODO set filter
|
// TODO set filter
|
||||||
|
|
||||||
|
font_height fontHeight;
|
||||||
|
GetFontHeight(&fontHeight);
|
||||||
|
|
||||||
|
// TODO: fix this calculation
|
||||||
|
float height = floorf(fontHeight.ascent + fontHeight.descent
|
||||||
|
+ fontHeight.leading) + 7;
|
||||||
|
|
||||||
|
fMenuBar->ResizeTo(Bounds().Width() - fDivider, height);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BMenuField::DrawLabel(BRect bounds, BRect update)
|
void BMenuField::DrawLabel(BRect bounds, BRect update)
|
||||||
|
|||||||
Reference in New Issue
Block a user