- Calculating the space left for deskbar replicants was broken. The TimeView could overlap on the left. This fixes #1408
- Placement of the time text was broken. With big fonts, the text was way too low. Using text bounding box now, it looks pretty and robust too. - Fixed the height of the time view to the replicant height. The view has a fixed height now and can never overlap deskbar at the bottom (horizontal deskbar mode) or other replicant below. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25970 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -236,9 +236,9 @@ TReplicantTray::DealWithClock(bool showClock)
|
|||||||
if (!fClock) {
|
if (!fClock) {
|
||||||
desk_settings *settings = ((TBarApp *)be_app)->Settings();
|
desk_settings *settings = ((TBarApp *)be_app)->Settings();
|
||||||
|
|
||||||
fClock = new TTimeView(settings->timeShowSeconds,
|
fClock = new TTimeView(kMinimumTrayWidth, kMaxReplicantHeight - 1.0,
|
||||||
settings->timeShowMil, settings->timeFullDate,
|
settings->timeShowSeconds, settings->timeShowMil,
|
||||||
settings->timeShowEuro, false);
|
settings->timeFullDate, settings->timeShowEuro, false);
|
||||||
AddChild(fClock);
|
AddChild(fClock);
|
||||||
|
|
||||||
fClock->MoveTo(Bounds().right - fClock->Bounds().Width() - 1, 2);
|
fClock->MoveTo(Bounds().right - fClock->Bounds().Width() - 1, 2);
|
||||||
@@ -1276,7 +1276,7 @@ TReplicantTray::LocationForReplicant(int32 index, float width)
|
|||||||
// try to find free space in every row
|
// try to find free space in every row
|
||||||
for (int32 row = 0; ; loc.y += kMaxReplicantHeight + kIconGap, row++) {
|
for (int32 row = 0; ; loc.y += kMaxReplicantHeight + kIconGap, row++) {
|
||||||
// determine free space in this row
|
// determine free space in this row
|
||||||
BRect rect(loc.x, loc.y, loc.x + kMinimumTrayWidth + 2, kMaxReplicantHeight);
|
BRect rect(loc.x, loc.y, loc.x + kMinimumTrayWidth - kIconGap - 2.0, loc.y + kMaxReplicantHeight);
|
||||||
if (row == 0 && fBarView->ShowingClock())
|
if (row == 0 && fBarView->ShowingClock())
|
||||||
rect.right -= fClock->Frame().Width() + kIconGap;
|
rect.right -= fClock->Frame().Width() + kIconGap;
|
||||||
|
|
||||||
|
|||||||
@@ -55,20 +55,7 @@ const char *kLongDateFormat = "%a, %B %d, %Y";
|
|||||||
const char *kLongEuroDateFormat = "%a, %d %B, %Y";
|
const char *kLongEuroDateFormat = "%a, %d %B, %Y";
|
||||||
|
|
||||||
static const char * const kMinString = "99:99 AM";
|
static const char * const kMinString = "99:99 AM";
|
||||||
|
static const float kHMargin = 2.0;
|
||||||
|
|
||||||
static float
|
|
||||||
FontHeight(BView *target, bool full)
|
|
||||||
{
|
|
||||||
font_height fontInfo;
|
|
||||||
target->GetFontHeight(&fontInfo);
|
|
||||||
float h = fontInfo.ascent + fontInfo.descent;
|
|
||||||
|
|
||||||
if (full)
|
|
||||||
h += fontInfo.leading;
|
|
||||||
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@@ -78,7 +65,7 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
TTimeView::TTimeView(bool showSeconds, bool milTime, bool fullDate, bool euroDate, bool)
|
TTimeView::TTimeView(float maxWidth, float height, bool showSeconds, bool milTime, bool fullDate, bool euroDate, bool)
|
||||||
: BView(BRect(-100,-100,-90,-90), "_deskbar_tv_",
|
: BView(BRect(-100,-100,-90,-90), "_deskbar_tv_",
|
||||||
B_FOLLOW_RIGHT | B_FOLLOW_TOP,
|
B_FOLLOW_RIGHT | B_FOLLOW_TOP,
|
||||||
B_WILL_DRAW | B_PULSE_NEEDED | B_FRAME_EVENTS),
|
B_WILL_DRAW | B_PULSE_NEEDED | B_FRAME_EVENTS),
|
||||||
@@ -89,7 +76,9 @@ TTimeView::TTimeView(bool showSeconds, bool milTime, bool fullDate, bool euroDat
|
|||||||
fFullDate(fullDate),
|
fFullDate(fullDate),
|
||||||
fCanShowFullDate(false),
|
fCanShowFullDate(false),
|
||||||
fEuroDate(euroDate),
|
fEuroDate(euroDate),
|
||||||
fOrientation(false)
|
fMaxWidth(maxWidth),
|
||||||
|
fHeight(height),
|
||||||
|
fOrientation(true)
|
||||||
{
|
{
|
||||||
fShowingDate = false;
|
fShowingDate = false;
|
||||||
fTime = fLastTime = time(NULL);
|
fTime = fLastTime = time(NULL);
|
||||||
@@ -159,7 +148,6 @@ TTimeView::AttachedToWindow()
|
|||||||
} else
|
} else
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
fFontHeight = FontHeight(this, true);
|
|
||||||
ResizeToPreferred();
|
ResizeToPreferred();
|
||||||
CalculateTextPlacement();
|
CalculateTextPlacement();
|
||||||
}
|
}
|
||||||
@@ -168,17 +156,22 @@ TTimeView::AttachedToWindow()
|
|||||||
void
|
void
|
||||||
TTimeView::GetPreferredSize(float *width, float *height)
|
TTimeView::GetPreferredSize(float *width, float *height)
|
||||||
{
|
{
|
||||||
*height = fFontHeight;
|
*height = fHeight;
|
||||||
|
|
||||||
GetCurrentTime();
|
GetCurrentTime();
|
||||||
GetCurrentDate();
|
GetCurrentDate();
|
||||||
|
|
||||||
|
// TODO: SetOrientation never gets called, fix that
|
||||||
|
// When in vertical mode, we want to limit the width so that it can't
|
||||||
|
// overlap the bevels in the parent view.
|
||||||
if (ShowingDate())
|
if (ShowingDate())
|
||||||
*width = 6 + StringWidth(fDateStr);
|
*width = fOrientation ?
|
||||||
|
min_c(fMaxWidth - kHMargin, kHMargin + StringWidth(fDateStr))
|
||||||
|
: kHMargin + StringWidth(fDateStr);
|
||||||
else {
|
else {
|
||||||
*width = 6 + StringWidth(fTimeStr);
|
*width = fOrientation ?
|
||||||
// Changed this from 10 to 6 so even with interval + seconds, there still
|
min_c(fMaxWidth - kHMargin, kHMargin + StringWidth(fTimeStr))
|
||||||
// is room for two replicants in the default tray.
|
: kHMargin + StringWidth(fTimeStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -495,15 +488,20 @@ TTimeView::CalculateTextPlacement()
|
|||||||
{
|
{
|
||||||
BRect bounds(Bounds());
|
BRect bounds(Bounds());
|
||||||
|
|
||||||
if (fOrientation) { // vertical mode
|
fDateLocation.x = 0.0;
|
||||||
fDateLocation.x = bounds.Width()/2 - StringWidth(fDateStr)/2;
|
fTimeLocation.x = 0.0;
|
||||||
fTimeLocation.x = bounds.Width()/2 - StringWidth(fTimeStr)/2;
|
|
||||||
} else {
|
BFont font;
|
||||||
fTimeLocation.x = bounds.Width() - StringWidth(fTimeStr) - 5;
|
GetFont(&font);
|
||||||
fDateLocation.x = bounds.Width() - StringWidth(fDateStr) - 5;
|
const char* stringArray[1];
|
||||||
}
|
stringArray[0] = fTimeStr;
|
||||||
// center vertically
|
BRect rectArray[1];
|
||||||
fDateLocation.y = fTimeLocation.y = bounds.Height()/2 + fFontHeight/2;
|
escapement_delta delta = { 0.0, 0.0 };
|
||||||
|
font.GetBoundingBoxesForStrings(stringArray, 1, B_SCREEN_METRIC, &delta,
|
||||||
|
rectArray);
|
||||||
|
|
||||||
|
fTimeLocation.y = fDateLocation.y = ceilf((bounds.Height() -
|
||||||
|
rectArray[0].Height() + 1.0) / 2.0 - rectArray[0].top);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class _EXPORT TTimeView;
|
|||||||
|
|
||||||
class TTimeView : public BView {
|
class TTimeView : public BView {
|
||||||
public:
|
public:
|
||||||
TTimeView(bool showSeconds = false, bool milTime = false, bool fullDate = false,
|
TTimeView(float maxWidth, float height, bool showSeconds = false, bool milTime = false, bool fullDate = false,
|
||||||
bool euroDate = false, bool showInterval = false);
|
bool euroDate = false, bool showInterval = false);
|
||||||
TTimeView(BMessage *data);
|
TTimeView(BMessage *data);
|
||||||
~TTimeView();
|
~TTimeView();
|
||||||
@@ -119,7 +119,8 @@ class TTimeView : public BView {
|
|||||||
bool fCanShowFullDate;
|
bool fCanShowFullDate;
|
||||||
bool fEuroDate;
|
bool fEuroDate;
|
||||||
|
|
||||||
float fFontHeight;
|
float fMaxWidth;
|
||||||
|
float fHeight;
|
||||||
bool fOrientation; // vertical = true
|
bool fOrientation; // vertical = true
|
||||||
BPoint fTimeLocation;
|
BPoint fTimeLocation;
|
||||||
BPoint fDateLocation;
|
BPoint fDateLocation;
|
||||||
|
|||||||
Reference in New Issue
Block a user