* Added default value for message in two arguments constructor.
* Removed resizing to minimum height in layout-friendly constructors. * Cache preferred size. * Implemented all of Min/Max/PreferredSize(). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21364 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -57,7 +57,7 @@ public:
|
|||||||
BMessage *message,
|
BMessage *message,
|
||||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE
|
uint32 flags = B_WILL_DRAW | B_NAVIGABLE
|
||||||
| B_FULL_UPDATE_ON_RESIZE);
|
| B_FULL_UPDATE_ON_RESIZE);
|
||||||
BButton(const char* label, BMessage *message);
|
BButton(const char* label, BMessage *message = NULL);
|
||||||
|
|
||||||
virtual ~BButton();
|
virtual ~BButton();
|
||||||
|
|
||||||
@@ -98,10 +98,15 @@ virtual BHandler *ResolveSpecifier(BMessage *message,
|
|||||||
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);
|
||||||
|
|
||||||
|
virtual void InvalidateLayout(bool descendants = false);
|
||||||
|
|
||||||
|
virtual BSize MinSize();
|
||||||
virtual BSize MaxSize();
|
virtual BSize MaxSize();
|
||||||
|
virtual BSize PreferredSize();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
BSize _ValidatePreferredSize();
|
||||||
|
|
||||||
virtual void _ReservedButton1();
|
virtual void _ReservedButton1();
|
||||||
virtual void _ReservedButton2();
|
virtual void _ReservedButton2();
|
||||||
@@ -115,9 +120,9 @@ virtual void _ReservedButton3();
|
|||||||
|
|
||||||
status_t Execute ();
|
status_t Execute ();
|
||||||
|
|
||||||
float fCachedWidth;
|
BSize fPreferredSize;
|
||||||
bool fDrawAsDefault;
|
bool fDrawAsDefault;
|
||||||
uint32 _reserved[3];
|
uint32 _reserved[2];
|
||||||
};
|
};
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ BButton::BButton(BRect frame, const char *name, const char *label, BMessage *mes
|
|||||||
uint32 resizingMode, uint32 flags)
|
uint32 resizingMode, uint32 flags)
|
||||||
: BControl(frame, name, label, message, resizingMode,
|
: BControl(frame, name, label, message, resizingMode,
|
||||||
flags | B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
|
flags | B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
|
||||||
|
fPreferredSize(-1, -1),
|
||||||
fDrawAsDefault(false)
|
fDrawAsDefault(false)
|
||||||
{
|
{
|
||||||
// Resize to minimum height if needed
|
// Resize to minimum height if needed
|
||||||
@@ -36,31 +37,20 @@ BButton::BButton(BRect frame, const char *name, const char *label, BMessage *mes
|
|||||||
|
|
||||||
BButton::BButton(const char* name, const char* label, BMessage *message,
|
BButton::BButton(const char* name, const char* label, BMessage *message,
|
||||||
uint32 flags)
|
uint32 flags)
|
||||||
: BControl(BRect(0, 0, -1, -1), name, label, message, B_FOLLOW_NONE,
|
: BControl(name, label, message,
|
||||||
flags | B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_SUPPORTS_LAYOUT),
|
flags | B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
|
||||||
|
fPreferredSize(-1, -1),
|
||||||
fDrawAsDefault(false)
|
fDrawAsDefault(false)
|
||||||
{
|
{
|
||||||
// Resize to minimum height if needed
|
|
||||||
font_height fh;
|
|
||||||
GetFontHeight(&fh);
|
|
||||||
float minHeight = 12.0f + (float)ceil(fh.ascent + fh.descent);
|
|
||||||
if (Bounds().Height() < minHeight)
|
|
||||||
ResizeTo(Bounds().Width(), minHeight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BButton::BButton(const char* label, BMessage *message)
|
BButton::BButton(const char* label, BMessage *message)
|
||||||
: BControl(BRect(0, 0, -1, -1), NULL, label, message, B_FOLLOW_NONE,
|
: BControl(NULL, label, message,
|
||||||
B_WILL_DRAW | B_NAVIGABLE | B_FULL_UPDATE_ON_RESIZE
|
B_WILL_DRAW | B_NAVIGABLE | B_FULL_UPDATE_ON_RESIZE),
|
||||||
| B_SUPPORTS_LAYOUT),
|
fPreferredSize(-1, -1),
|
||||||
fDrawAsDefault(false)
|
fDrawAsDefault(false)
|
||||||
{
|
{
|
||||||
// Resize to minimum height if needed
|
|
||||||
font_height fh;
|
|
||||||
GetFontHeight(&fh);
|
|
||||||
float minHeight = 12.0f + (float)ceil(fh.ascent + fh.descent);
|
|
||||||
if (Bounds().Height() < minHeight)
|
|
||||||
ResizeTo(Bounds().Width(), minHeight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -622,25 +612,13 @@ BButton::SetValue(int32 value)
|
|||||||
void
|
void
|
||||||
BButton::GetPreferredSize(float *_width, float *_height)
|
BButton::GetPreferredSize(float *_width, float *_height)
|
||||||
{
|
{
|
||||||
if (_height) {
|
_ValidatePreferredSize();
|
||||||
font_height fontHeight;
|
|
||||||
GetFontHeight(&fontHeight);
|
|
||||||
|
|
||||||
// *_height = 12.0f + ceilf(fontHeight.ascent + fontHeight.descent)
|
if (_width)
|
||||||
*_height = ceilf((fontHeight.ascent + fontHeight.descent) * 1.8)
|
*_width = fPreferredSize.width;
|
||||||
+ (fDrawAsDefault ? 6.0f : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_width) {
|
if (_height)
|
||||||
float width = 20.0f + (float)ceil(StringWidth(Label()));
|
*_height = fPreferredSize.height;
|
||||||
if (width < 75.0f)
|
|
||||||
width = 75.0f;
|
|
||||||
|
|
||||||
if (fDrawAsDefault)
|
|
||||||
width += 6.0f;
|
|
||||||
|
|
||||||
*_width = width;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -723,13 +701,37 @@ BButton::Perform(perform_code d, void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BButton::InvalidateLayout(bool descendants)
|
||||||
|
{
|
||||||
|
// invalidate cached preferred size
|
||||||
|
fPreferredSize.Set(-1, -1);
|
||||||
|
|
||||||
|
BControl::InvalidateLayout(descendants);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSize
|
||||||
|
BButton::MinSize()
|
||||||
|
{
|
||||||
|
return BLayoutUtils::ComposeSize(ExplicitMinSize(),
|
||||||
|
_ValidatePreferredSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BSize
|
BSize
|
||||||
BButton::MaxSize()
|
BButton::MaxSize()
|
||||||
{
|
{
|
||||||
float width, height;
|
return BLayoutUtils::ComposeSize(ExplicitMaxSize(),
|
||||||
GetPreferredSize(&width, &height);
|
_ValidatePreferredSize());
|
||||||
|
}
|
||||||
|
|
||||||
return BLayoutUtils::ComposeSize(ExplicitMaxSize(), BSize(width, height));
|
|
||||||
|
BSize
|
||||||
|
BButton::PreferredSize()
|
||||||
|
{
|
||||||
|
return BLayoutUtils::ComposeSize(ExplicitPreferredSize(),
|
||||||
|
_ValidatePreferredSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -844,3 +846,31 @@ BButton::DrawFocusLine(float x, float y, float width, bool visible)
|
|||||||
// White Line
|
// White Line
|
||||||
StrokeLine(BPoint(x, y + 1.0f), BPoint(x + width, y + 1.0f));
|
StrokeLine(BPoint(x, y + 1.0f), BPoint(x + width, y + 1.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSize
|
||||||
|
BButton::_ValidatePreferredSize()
|
||||||
|
{
|
||||||
|
if (fPreferredSize.width < 0) {
|
||||||
|
// width
|
||||||
|
float width = 20.0f + (float)ceil(StringWidth(Label()));
|
||||||
|
if (width < 75.0f)
|
||||||
|
width = 75.0f;
|
||||||
|
|
||||||
|
if (fDrawAsDefault)
|
||||||
|
width += 6.0f;
|
||||||
|
|
||||||
|
fPreferredSize.width = width;
|
||||||
|
|
||||||
|
// height
|
||||||
|
font_height fontHeight;
|
||||||
|
GetFontHeight(&fontHeight);
|
||||||
|
|
||||||
|
fPreferredSize.height
|
||||||
|
= ceilf((fontHeight.ascent + fontHeight.descent) * 1.8)
|
||||||
|
+ (fDrawAsDefault ? 6.0f : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fPreferredSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user