BMenuField: Check if Frame() is valid, refactor
This commit is contained in:
@@ -916,14 +916,15 @@ BMenuField::DoLayout()
|
|||||||
|
|
||||||
// divider
|
// divider
|
||||||
float divider = 0;
|
float divider = 0;
|
||||||
if (fLayoutData->label_layout_item && fLayoutData->menu_bar_layout_item) {
|
if (fLayoutData->label_layout_item != NULL
|
||||||
// We have layout items. They define the divider location.
|
&& fLayoutData->menu_bar_layout_item != NULL
|
||||||
|
&& fLayoutData->label_layout_item->Frame().IsValid()
|
||||||
|
&& fLayoutData->menu_bar_layout_item->Frame().IsValid()) {
|
||||||
|
// We have valid layout items, they define the divider location.
|
||||||
divider = fLayoutData->menu_bar_layout_item->Frame().left
|
divider = fLayoutData->menu_bar_layout_item->Frame().left
|
||||||
- fLayoutData->label_layout_item->Frame().left;
|
- fLayoutData->label_layout_item->Frame().left;
|
||||||
} else {
|
} else if (fLayoutData->label_width > 0)
|
||||||
if (fLayoutData->label_width > 0)
|
divider = fLayoutData->label_width + 5;
|
||||||
divider = fLayoutData->label_width + 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
// menu bar
|
// menu bar
|
||||||
BRect dirty(fMenuBar->Frame());
|
BRect dirty(fMenuBar->Frame());
|
||||||
@@ -1093,25 +1094,31 @@ BMenuField::_UpdateFrame()
|
|||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
|
|
||||||
if (fLayoutData->label_layout_item && fLayoutData->menu_bar_layout_item) {
|
if (fLayoutData->label_layout_item == NULL
|
||||||
BRect labelFrame = fLayoutData->label_layout_item->Frame();
|
|| fLayoutData->menu_bar_layout_item == NULL) {
|
||||||
BRect menuFrame = fLayoutData->menu_bar_layout_item->Frame();
|
return;
|
||||||
|
|
||||||
// update divider
|
|
||||||
fDivider = menuFrame.left - labelFrame.left;
|
|
||||||
|
|
||||||
// update our frame
|
|
||||||
MoveTo(labelFrame.left, labelFrame.top);
|
|
||||||
BSize oldSize = Bounds().Size();
|
|
||||||
ResizeTo(menuFrame.left + menuFrame.Width() - labelFrame.left,
|
|
||||||
menuFrame.top + menuFrame.Height() - labelFrame.top);
|
|
||||||
BSize newSize = Bounds().Size();
|
|
||||||
|
|
||||||
// If the size changes, ResizeTo() will trigger a relayout, otherwise
|
|
||||||
// we need to do that explicitly.
|
|
||||||
if (newSize != oldSize)
|
|
||||||
Relayout();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BRect labelFrame = fLayoutData->label_layout_item->Frame();
|
||||||
|
BRect menuFrame = fLayoutData->menu_bar_layout_item->Frame();
|
||||||
|
|
||||||
|
if (!labelFrame.IsValid() || !menuFrame.IsValid())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// update divider
|
||||||
|
fDivider = menuFrame.left - labelFrame.left;
|
||||||
|
|
||||||
|
// update our frame
|
||||||
|
MoveTo(labelFrame.left, labelFrame.top);
|
||||||
|
BSize oldSize = Bounds().Size();
|
||||||
|
ResizeTo(menuFrame.left + menuFrame.Width() - labelFrame.left,
|
||||||
|
menuFrame.top + menuFrame.Height() - labelFrame.top);
|
||||||
|
BSize newSize = Bounds().Size();
|
||||||
|
|
||||||
|
// If the size changes, ResizeTo() will trigger a relayout, otherwise
|
||||||
|
// we need to do that explicitly.
|
||||||
|
if (newSize != oldSize)
|
||||||
|
Relayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user