* Fixed GetPreferredSize()
* Text height was computed with roundf() instead of ceilf() (which makes more sense). * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16706 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -7,35 +7,36 @@
|
|||||||
* Stephan Aßmus <[email protected]>
|
* Stephan Aßmus <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** BRadioButton represents a single on/off button.
|
/*!
|
||||||
* All sibling BRadioButton objects comprise a single
|
BRadioButton represents a single on/off button.
|
||||||
* "multiple choice" control.
|
All sibling BRadioButton objects comprise a single
|
||||||
*/
|
"multiple choice" control.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <Box.h>
|
#include <Box.h>
|
||||||
#include <Errors.h>
|
#include <RadioButton.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
#include <RadioButton.h>
|
|
||||||
|
|
||||||
|
|
||||||
BRadioButton::BRadioButton(BRect frame, const char *name, const char *label,
|
BRadioButton::BRadioButton(BRect frame, const char *name, const char *label,
|
||||||
BMessage *message, uint32 resizMask, uint32 flags)
|
BMessage *message, uint32 resizMask, uint32 flags)
|
||||||
: BControl(frame, name, label, message, resizMask, flags),
|
: BControl(frame, name, label, message, resizMask, flags),
|
||||||
fOutlined(false)
|
fOutlined(false)
|
||||||
{
|
{
|
||||||
// Resize to minimum height if needed
|
// Resize to minimum height if needed
|
||||||
font_height fh;
|
font_height fontHeight;
|
||||||
GetFontHeight(&fh);
|
GetFontHeight(&fontHeight);
|
||||||
float minHeight = (float)ceil(6.0f + fh.ascent + fh.descent);
|
float minHeight = ceilf(6.0f + fontHeight.ascent + fontHeight.descent);
|
||||||
if (Bounds().Height() < minHeight)
|
if (Bounds().Height() < minHeight)
|
||||||
ResizeTo(Bounds().Width(), minHeight);
|
ResizeTo(Bounds().Width(), minHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BRadioButton::BRadioButton(BMessage *archive)
|
BRadioButton::BRadioButton(BMessage *archive)
|
||||||
: BControl(archive),
|
: BControl(archive),
|
||||||
fOutlined(false)
|
fOutlined(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,8 +51,8 @@ BRadioButton::Instantiate(BMessage *archive)
|
|||||||
{
|
{
|
||||||
if (validate_instantiation(archive, "BRadioButton"))
|
if (validate_instantiation(archive, "BRadioButton"))
|
||||||
return new BRadioButton(archive);
|
return new BRadioButton(archive);
|
||||||
else
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -69,12 +70,12 @@ BRadioButton::Draw(BRect updateRect)
|
|||||||
BRect rect = _KnobFrame();
|
BRect rect = _KnobFrame();
|
||||||
|
|
||||||
// its size depends on the text height
|
// its size depends on the text height
|
||||||
font_height fh;
|
font_height fontHeight;
|
||||||
GetFontHeight(&fh);
|
GetFontHeight(&fontHeight);
|
||||||
float textHeight = floorf(fh.ascent + fh.descent + 0.5);
|
float textHeight = ceilf(fontHeight.ascent + fontHeight.descent);
|
||||||
|
|
||||||
BPoint labelPos(rect.right + floorf(textHeight / 2.0),
|
BPoint labelPos(rect.right + floorf(textHeight / 2.0),
|
||||||
floorf((rect.top + rect.bottom + textHeight) / 2.0 - fh.descent + 0.5) + 1.0);
|
floorf((rect.top + rect.bottom + textHeight) / 2.0 - fontHeight.descent + 0.5) + 1.0);
|
||||||
|
|
||||||
// if the focus is changing, just redraw the focus indicator
|
// if the focus is changing, just redraw the focus indicator
|
||||||
if (IsFocusChanging()) {
|
if (IsFocusChanging()) {
|
||||||
@@ -84,7 +85,7 @@ BRadioButton::Draw(BRect updateRect)
|
|||||||
SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
BPoint underLine = labelPos;
|
BPoint underLine = labelPos;
|
||||||
underLine.y += fh.descent;
|
underLine.y += fontHeight.descent;
|
||||||
StrokeLine(underLine, underLine + BPoint(StringWidth(Label()), 0.0));
|
StrokeLine(underLine, underLine + BPoint(StringWidth(Label()), 0.0));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -182,7 +183,7 @@ BRadioButton::Draw(BRect updateRect)
|
|||||||
if (IsFocus()) {
|
if (IsFocus()) {
|
||||||
SetHighColor(naviColor);
|
SetHighColor(naviColor);
|
||||||
BPoint underLine = labelPos;
|
BPoint underLine = labelPos;
|
||||||
underLine.y += fh.descent;
|
underLine.y += fontHeight.descent;
|
||||||
StrokeLine(underLine, underLine + BPoint(StringWidth(Label()), 0.0));
|
StrokeLine(underLine, underLine + BPoint(StringWidth(Label()), 0.0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -320,21 +321,22 @@ BRadioButton::SetValue(int32 value)
|
|||||||
void
|
void
|
||||||
BRadioButton::GetPreferredSize(float* _width, float* _height)
|
BRadioButton::GetPreferredSize(float* _width, float* _height)
|
||||||
{
|
{
|
||||||
|
font_height fontHeight;
|
||||||
|
GetFontHeight(&fontHeight);
|
||||||
|
|
||||||
if (_width) {
|
if (_width) {
|
||||||
float width = 22.0f; // TODO: check if ascent is included
|
BRect rect = _KnobFrame();
|
||||||
|
float width = rect.right + floorf(ceilf(fontHeight.ascent
|
||||||
|
+ fontHeight.descent) / 2.0);
|
||||||
|
|
||||||
if (Label())
|
if (Label())
|
||||||
width += StringWidth(Label());
|
width += StringWidth(Label());
|
||||||
|
|
||||||
*_width = (float)ceil(width);
|
*_width = ceilf(width);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_height) {
|
if (_height)
|
||||||
font_height fontHeight;
|
*_height = ceilf(fontHeight.ascent + fontHeight.descent) + 6.0f;
|
||||||
GetFontHeight(&fontHeight);
|
|
||||||
|
|
||||||
*_height = (float)ceil(fontHeight.ascent + fontHeight.descent) + 6.0f;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -479,14 +481,14 @@ BRadioButton::operator=(const BRadioButton &)
|
|||||||
BRect
|
BRect
|
||||||
BRadioButton::_KnobFrame() const
|
BRadioButton::_KnobFrame() const
|
||||||
{
|
{
|
||||||
font_height fh;
|
font_height fontHeight;
|
||||||
GetFontHeight(&fh);
|
GetFontHeight(&fontHeight);
|
||||||
|
|
||||||
// layout the rect for the dot
|
// layout the rect for the dot
|
||||||
BRect rect(Bounds());
|
BRect rect(Bounds());
|
||||||
|
|
||||||
// its size depends on the text height
|
// its size depends on the text height
|
||||||
float textHeight = floorf(fh.ascent + fh.descent + 0.5);
|
float textHeight = ceilf(fontHeight.ascent + fontHeight.descent);
|
||||||
float inset = -floorf(textHeight / 2 - 2);
|
float inset = -floorf(textHeight / 2 - 2);
|
||||||
|
|
||||||
rect.left -= (inset - 1);
|
rect.left -= (inset - 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user