BBox: Always offset the top border by the same amount
...so that the top border of BBox's with no labels, BBox's with text labels, and BBox's with BControl labels will all line up.
This commit is contained in:
@@ -63,6 +63,7 @@ class BBox : public BView {
|
|||||||
virtual void ResizeToPreferred();
|
virtual void ResizeToPreferred();
|
||||||
virtual void GetPreferredSize(float* _width, float* _height);
|
virtual void GetPreferredSize(float* _width, float* _height);
|
||||||
virtual void MakeFocus(bool focused = true);
|
virtual void MakeFocus(bool focused = true);
|
||||||
|
virtual void SetFont(const BFont* font, uint32 mask = B_FONT_ALL);
|
||||||
virtual status_t GetSupportedSuites(BMessage* message);
|
virtual status_t GetSupportedSuites(BMessage* message);
|
||||||
|
|
||||||
virtual status_t Perform(perform_code d, void* arg);
|
virtual status_t Perform(perform_code d, void* arg);
|
||||||
@@ -96,6 +97,7 @@ class BBox : public BView {
|
|||||||
border_style fStyle;
|
border_style fStyle;
|
||||||
BView* fLabelView;
|
BView* fLabelView;
|
||||||
LayoutData* fLayoutData;
|
LayoutData* fLayoutData;
|
||||||
|
float fLabelHeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _BOX_H
|
#endif // _BOX_H
|
||||||
|
|||||||
+28
-17
@@ -158,12 +158,7 @@ BBox::Border() const
|
|||||||
float
|
float
|
||||||
BBox::TopBorderOffset()
|
BBox::TopBorderOffset()
|
||||||
{
|
{
|
||||||
_ValidateLayoutData();
|
return fLabelHeight / 2;
|
||||||
|
|
||||||
if (fLabel != NULL || fLabelView != NULL)
|
|
||||||
return fLayoutData->label_box.Height() / 2;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -446,6 +441,18 @@ BBox::MakeFocus(bool focused)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BBox::SetFont(const BFont* font, uint32 mask)
|
||||||
|
{
|
||||||
|
BView::SetFont(font, mask);
|
||||||
|
|
||||||
|
// recalculate the label height based on the new font
|
||||||
|
font_height fontHeight;
|
||||||
|
GetFontHeight(&fontHeight);
|
||||||
|
fLabelHeight = ceilf(fontHeight.ascent + fontHeight.descent) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BBox::GetSupportedSuites(BMessage* message)
|
BBox::GetSupportedSuites(BMessage* message)
|
||||||
{
|
{
|
||||||
@@ -635,6 +642,11 @@ BBox::_InitObject(BMessage* archive)
|
|||||||
|
|
||||||
if (flags != 0)
|
if (flags != 0)
|
||||||
SetFont(&font, flags);
|
SetFont(&font, flags);
|
||||||
|
else {
|
||||||
|
font_height fontHeight;
|
||||||
|
GetFontHeight(&fontHeight);
|
||||||
|
fLabelHeight = ceilf(fontHeight.ascent + fontHeight.descent) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (archive != NULL) {
|
if (archive != NULL) {
|
||||||
const char* string;
|
const char* string;
|
||||||
@@ -801,8 +813,9 @@ BBox::_ValidateLayoutData()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// compute the label box, width and height
|
// compute the label box, width and height
|
||||||
bool label = true;
|
bool hasLabel = true;
|
||||||
float labelHeight = 0; // height of the label (pixel count)
|
float labelHeight = 0;
|
||||||
|
// height of the label (pixel count)
|
||||||
if (fLabel) {
|
if (fLabel) {
|
||||||
// leave 6 pixels of the frame, and have a gap of 4 pixels between
|
// leave 6 pixels of the frame, and have a gap of 4 pixels between
|
||||||
// the frame and the text on either side
|
// the frame and the text on either side
|
||||||
@@ -810,14 +823,15 @@ BBox::_ValidateLayoutData()
|
|||||||
GetFontHeight(&fontHeight);
|
GetFontHeight(&fontHeight);
|
||||||
fLayoutData->label_box.Set(6.0f, 0, 14.0f + StringWidth(fLabel),
|
fLayoutData->label_box.Set(6.0f, 0, 14.0f + StringWidth(fLabel),
|
||||||
ceilf(fontHeight.ascent));
|
ceilf(fontHeight.ascent));
|
||||||
labelHeight = ceilf(fontHeight.ascent + fontHeight.descent) + 1;
|
labelHeight = fLabelHeight;
|
||||||
} else if (fLabelView) {
|
} else if (fLabelView) {
|
||||||
// the label view is placed at (0, 10) at its preferred size
|
// the label view is placed at (0, 10) at its preferred size
|
||||||
BSize size = fLabelView->PreferredSize();
|
BSize size = fLabelView->PreferredSize();
|
||||||
fLayoutData->label_box.Set(10, 0, 10 + size.width, size.height);
|
fLayoutData->label_box.Set(10, 0, 10 + size.width, size.height);
|
||||||
labelHeight = size.height + 1;
|
labelHeight = size.height + 1;
|
||||||
} else {
|
} else {
|
||||||
label = false;
|
labelHeight = fLabelHeight;
|
||||||
|
hasLabel = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// border
|
// border
|
||||||
@@ -834,8 +848,8 @@ BBox::_ValidateLayoutData()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if there's a label, the top inset will be dictated by the label
|
// Grow the top inset by the label height
|
||||||
if (label && labelHeight > fLayoutData->insets.top)
|
if (labelHeight > fLayoutData->insets.top)
|
||||||
fLayoutData->insets.top = labelHeight;
|
fLayoutData->insets.top = labelHeight;
|
||||||
|
|
||||||
// total number of pixel the border adds
|
// total number of pixel the border adds
|
||||||
@@ -843,11 +857,8 @@ BBox::_ValidateLayoutData()
|
|||||||
float addHeight = fLayoutData->insets.top + fLayoutData->insets.bottom;
|
float addHeight = fLayoutData->insets.top + fLayoutData->insets.bottom;
|
||||||
|
|
||||||
// compute the minimal width induced by the label
|
// compute the minimal width induced by the label
|
||||||
float minWidth;
|
float minWidth = !hasLabel ? addWidth - 1
|
||||||
if (label)
|
: fLayoutData->label_box.right + fLayoutData->insets.right;
|
||||||
minWidth = fLayoutData->label_box.right + fLayoutData->insets.right;
|
|
||||||
else
|
|
||||||
minWidth = addWidth - 1;
|
|
||||||
|
|
||||||
// finally consider the child constraints, if we shall support layout
|
// finally consider the child constraints, if we shall support layout
|
||||||
BView* child = _Child();
|
BView* child = _Child();
|
||||||
|
|||||||
Reference in New Issue
Block a user