Deskbar: Compute more metrics instead of hardcoding them.
This commit is contained in:
parent
da9dee377d
commit
9f4bb0f544
@ -527,10 +527,10 @@ TBarView::PlaceTray(bool vertSwap, bool leftSwap)
|
||||
if (fLeft) {
|
||||
// move replicant tray past dragger width on left
|
||||
// also down 1px so it won't cover the border
|
||||
fReplicantTray->MoveTo(kDragWidth + kGutter, kGutter);
|
||||
fReplicantTray->MoveTo(gDragWidth + kGutter, kGutter);
|
||||
|
||||
// shrink width by same amount
|
||||
fReplicantTray->ResizeBy(-(kDragWidth + kGutter), 0);
|
||||
fReplicantTray->ResizeBy(-(gDragWidth + kGutter), 0);
|
||||
} else {
|
||||
// move replicant tray down 1px so it won't cover the border
|
||||
fReplicantTray->MoveTo(0, kGutter);
|
||||
@ -547,7 +547,7 @@ TBarView::PlaceTray(bool vertSwap, bool leftSwap)
|
||||
|
||||
// move past dragger and top border
|
||||
// and make room for the top and bottom borders
|
||||
fReplicantTray->MoveTo(fLeft ? kDragWidth : 0, kGutter);
|
||||
fReplicantTray->MoveTo(fLeft ? gDragWidth : 0, kGutter);
|
||||
fReplicantTray->ResizeBy(0, -4);
|
||||
} else {
|
||||
// move tray right and down to not cover border, resize by same
|
||||
@ -562,12 +562,12 @@ TBarView::PlaceTray(bool vertSwap, bool leftSwap)
|
||||
fDragRegion->MoveTo(statusLoc);
|
||||
|
||||
// make room for top and bottom border
|
||||
fResizeControl->ResizeTo(kDragWidth, fDragRegion->Bounds().Height() - 2);
|
||||
fResizeControl->ResizeTo(gDragWidth, fDragRegion->Bounds().Height() - 2);
|
||||
|
||||
if (fVertical) {
|
||||
// move resize control into place based on width setting
|
||||
fResizeControl->MoveTo(
|
||||
fLeft ? fBarApp->Settings()->width - kDragWidth : 0, 1);
|
||||
fLeft ? fBarApp->Settings()->width - gDragWidth : 0, 1);
|
||||
if (fResizeControl->IsHidden())
|
||||
fResizeControl->Show();
|
||||
} else {
|
||||
|
@ -79,6 +79,11 @@ All rights reserved.
|
||||
|
||||
static const float kVerticalMiniMultiplier = 2.9f;
|
||||
|
||||
static float sIconGap = 0.0f;
|
||||
float gDragWidth, gDragRegionWidth = 0.0f;
|
||||
float gMinReplicantHeight, gMinReplicantWidth = 0.0f;
|
||||
float gMinimumTrayWidth, gMinimumWindowWidth, gMaximumWindowWidth = 0.0f;
|
||||
|
||||
|
||||
#ifdef DB_ADDONS
|
||||
// Add-on support
|
||||
@ -92,9 +97,6 @@ const char* const kInstantiateEntryCFunctionName = "instantiate_deskbar_entry";
|
||||
const char* const kReplicantSettingsFile = "replicants";
|
||||
const char* const kReplicantPathField = "replicant_path";
|
||||
|
||||
float gMinimumWindowWidth = kGutter + kMinimumTrayWidth + kDragRegionWidth;
|
||||
float gMaximumWindowWidth = gMinimumWindowWidth * 2;
|
||||
|
||||
|
||||
static void
|
||||
DumpItem(DeskbarItemInfo* item)
|
||||
@ -140,8 +142,28 @@ TReplicantTray::TReplicantTray(TBarView* barView)
|
||||
fShelf(new TReplicantShelf(this)),
|
||||
fAlignmentSupport(false)
|
||||
{
|
||||
if (sIconGap == 0.0f) {
|
||||
sIconGap = ceilf(be_control_look->DefaultLabelSpacing() / 3.0f);
|
||||
|
||||
gDragRegionWidth = be_control_look->ComposeSpacing(B_USE_HALF_ITEM_SPACING);
|
||||
gDragWidth = ceilf(gDragRegionWidth * 0.6f);
|
||||
|
||||
gMinReplicantHeight = gMinReplicantWidth =
|
||||
be_control_look->ComposeIconSize(B_MINI_ICON).IntegerWidth() + 1;
|
||||
|
||||
// 1 pixel for left gutter
|
||||
// space for replicant tray (6 items)
|
||||
// 6 pixel drag region
|
||||
gMinimumTrayWidth = sIconGap + gMinReplicantWidth
|
||||
+ (kMinimumReplicantCount * sIconGap)
|
||||
+ (kMinimumReplicantCount * gMinReplicantWidth) + kGutter;
|
||||
|
||||
gMinimumWindowWidth = kGutter + gMinimumTrayWidth + gDragRegionWidth;
|
||||
gMaximumWindowWidth = gMinimumWindowWidth * 2;
|
||||
}
|
||||
|
||||
// scale replicants by font size
|
||||
fMaxReplicantHeight = std::max(kMinReplicantHeight,
|
||||
fMaxReplicantHeight = std::max(gMinReplicantHeight,
|
||||
float(((TBarApp*)be_app)->IconSize()));
|
||||
// but not bigger than TabHeight which depends on be_bold_font
|
||||
// TODO this should only apply to mini-mode but we set it once here for all
|
||||
@ -155,9 +177,9 @@ TReplicantTray::TReplicantTray(TBarView* barView)
|
||||
fMinTrayHeight = kGutter + fMaxReplicantHeight + kGutter;
|
||||
if (fBarView != NULL && fBarView->Vertical()
|
||||
&& (fBarView->ExpandoState() || fBarView->FullState())) {
|
||||
fMinimumTrayWidth = gMinimumWindowWidth - kGutter - kDragRegionWidth;
|
||||
fMinimumTrayWidth = gMinimumWindowWidth - kGutter - gDragRegionWidth;
|
||||
} else
|
||||
fMinimumTrayWidth = kMinimumTrayWidth;
|
||||
fMinimumTrayWidth = gMinimumTrayWidth;
|
||||
|
||||
// Create the time view
|
||||
fTime = new TTimeView(fMinimumTrayWidth, fMaxReplicantHeight - 1.0,
|
||||
@ -236,7 +258,9 @@ TReplicantTray::GetPreferredSize(float* preferredWidth, float* preferredHeight)
|
||||
|
||||
if (fBarView->Vertical()) {
|
||||
width = static_cast<TBarApp*>(be_app)->Settings()->width
|
||||
- kDragWidth - kGutter;
|
||||
- gDragWidth - kGutter;
|
||||
width = std::max(gMinimumTrayWidth, width);
|
||||
|
||||
if (fRightBottomReplicant.IsValid())
|
||||
height = fRightBottomReplicant.bottom;
|
||||
else if (ReplicantCount() > 0) {
|
||||
@ -244,7 +268,7 @@ TReplicantTray::GetPreferredSize(float* preferredWidth, float* preferredHeight)
|
||||
// to show all the replicants and gutters.
|
||||
int32 rowCount = (int32)(height / fMaxReplicantHeight);
|
||||
height = kGutter + (rowCount * fMaxReplicantHeight)
|
||||
+ ((rowCount - 1) * kIconGap) + kGutter;
|
||||
+ ((rowCount - 1) * sIconGap) + kGutter;
|
||||
height = std::max(fMinTrayHeight, height);
|
||||
} else
|
||||
height = fMinTrayHeight;
|
||||
@ -257,11 +281,11 @@ TReplicantTray::GetPreferredSize(float* preferredWidth, float* preferredHeight)
|
||||
width = fRightBottomReplicant.right + kClockMargin
|
||||
+ fTime->Frame().Width() + trayPadding + 2;
|
||||
} else
|
||||
width = fRightBottomReplicant.right + kIconGap + kGutter;
|
||||
width = fRightBottomReplicant.right + sIconGap + kGutter;
|
||||
}
|
||||
|
||||
// this view has a fixed minimum width
|
||||
width = std::max(kMinimumTrayWidth, width);
|
||||
width = std::max(gMinimumTrayWidth, width);
|
||||
|
||||
// if mini-mode set to tab height
|
||||
// else if horizontal mode set to team menu item height
|
||||
@ -1179,7 +1203,7 @@ TReplicantTray::LocationForReplicant(int32 index, float replicantWidth)
|
||||
BPoint loc(trayPadding, 0);
|
||||
if (fBarView->Vertical() || fBarView->MiniState()) {
|
||||
if (fBarView->Vertical() && !fBarView->Left())
|
||||
loc.x += kDragWidth; // move past dragger on left
|
||||
loc.x += gDragWidth; // move past dragger on left
|
||||
|
||||
loc.y = floorf((fBarView->TabHeight() - fMaxReplicantHeight) / 2) - 1;
|
||||
} else {
|
||||
@ -1204,11 +1228,10 @@ TReplicantTray::LocationForReplicant(int32 index, float replicantWidth)
|
||||
|
||||
if (fBarView->Vertical()) {
|
||||
// try to find free space in every row
|
||||
for (int32 row = 0; ; loc.y += fMaxReplicantHeight + kIconGap, row++) {
|
||||
for (int32 row = 0; ; loc.y += fMaxReplicantHeight + sIconGap, row++) {
|
||||
// determine free space in this row
|
||||
BRect rowRect(loc.x, loc.y,
|
||||
loc.x + static_cast<TBarApp*>(be_app)->Settings()->width
|
||||
- (trayPadding + kDragWidth + kGutter) * 2,
|
||||
loc.x + Bounds().Width() - trayPadding,
|
||||
loc.y + fMaxReplicantHeight);
|
||||
if (row == 0 && !fTime->IsHidden(fTime))
|
||||
rowRect.right -= kClockMargin + fTime->Frame().Width();
|
||||
@ -1221,7 +1244,7 @@ TReplicantTray::LocationForReplicant(int32 index, float replicantWidth)
|
||||
continue;
|
||||
|
||||
// push this replicant placement past the last one
|
||||
replicantRect.left = view->Frame().right + kIconGap + 1;
|
||||
replicantRect.left = view->Frame().right + sIconGap + 1;
|
||||
}
|
||||
|
||||
// calculated left position, add replicantWidth to get the
|
||||
@ -1245,7 +1268,7 @@ TReplicantTray::LocationForReplicant(int32 index, float replicantWidth)
|
||||
fShelf->ReplicantAt(index - 1, &view);
|
||||
if (view != NULL) {
|
||||
// push this replicant placement past the last one
|
||||
loc.x = view->Frame().right + kIconGap + 1;
|
||||
loc.x = view->Frame().right + sIconGap + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1389,7 +1412,7 @@ TDragRegion::GetPreferredSize(float* width, float* height)
|
||||
*height = fReplicantTray->Bounds().Height();
|
||||
|
||||
if (fDragLocation != kNoDragRegion)
|
||||
*width += kDragWidth + kGutter;
|
||||
*width += gDragWidth + kGutter;
|
||||
else
|
||||
*width += 6;
|
||||
|
||||
@ -1501,9 +1524,9 @@ TDragRegion::DragRegion() const
|
||||
placeOnLeft = fDragLocation == kDragRegionLeft;
|
||||
|
||||
if (placeOnLeft)
|
||||
dragRegion.right = dragRegion.left + kDragWidth;
|
||||
dragRegion.right = dragRegion.left + gDragWidth;
|
||||
else
|
||||
dragRegion.left = dragRegion.right - kDragWidth;
|
||||
dragRegion.left = dragRegion.right - gDragWidth;
|
||||
|
||||
return dragRegion;
|
||||
}
|
||||
@ -1771,7 +1794,7 @@ TDragRegion::SetDragRegionLocation(int32 location)
|
||||
*/
|
||||
TResizeControl::TResizeControl(TBarView* barView)
|
||||
:
|
||||
BControl(BRect(0, kDragWidth, 0, kMenuBarHeight), "", "", NULL,
|
||||
BControl(BRect(0, gDragWidth, 0, kMenuBarHeight), "", "", NULL,
|
||||
B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS),
|
||||
fBarView(barView)
|
||||
{
|
||||
|
@ -49,25 +49,14 @@ All rights reserved.
|
||||
|
||||
//#define FULL_MODE
|
||||
|
||||
const float kDragWidth = 4.0f;
|
||||
const float kMinReplicantHeight = 16.0f;
|
||||
const float kMinReplicantWidth = 16.0f;
|
||||
const int32 kMinimumReplicantCount = 6;
|
||||
const int32 kIconGap = 2;
|
||||
const int32 kGutter = 1;
|
||||
const int32 kDragRegionWidth = 6;
|
||||
const int32 kTrayPadding = B_USE_HALF_ITEM_SPACING;
|
||||
const int32 kClockMargin = 12;
|
||||
|
||||
// 1 pixel for left gutter
|
||||
// space for replicant tray (6 items)
|
||||
// 6 pixel drag region
|
||||
const float kMinimumTrayWidth = kIconGap + kMinReplicantWidth
|
||||
+ (kMinimumReplicantCount * kIconGap)
|
||||
+ (kMinimumReplicantCount * kMinReplicantWidth) + kGutter;
|
||||
|
||||
extern float gMinimumWindowWidth;
|
||||
extern float gMaximumWindowWidth;
|
||||
extern float gDragWidth, gDragRegionWidth;
|
||||
extern float gMinReplicantHeight, gMinReplicantWidth;
|
||||
extern float gMinimumTrayWidth, gMinimumWindowWidth, gMaximumWindowWidth;
|
||||
|
||||
#ifdef DB_ADDONS
|
||||
struct DeskbarItemInfo {
|
||||
|
@ -152,7 +152,7 @@ TTeamMenuItem::GetContentSize(float* width, float* height)
|
||||
if (hideLabels)
|
||||
*width = iconOnlyWidth;
|
||||
else
|
||||
*width = gMinimumWindowWidth - (kDragRegionWidth + kGutter) * 2;
|
||||
*width = gMinimumWindowWidth - (gDragRegionWidth + kGutter) * 2;
|
||||
} else if (!fBarView->Vertical()) {
|
||||
TExpandoMenuBar* menu = static_cast<TExpandoMenuBar*>(Menu());
|
||||
*width = menu->MaxHorizontalItemWidth();
|
||||
|
@ -199,7 +199,7 @@ TTimeView::GetPreferredSize(float* width, float* height)
|
||||
if (Vertical()) {
|
||||
float appWidth = static_cast<TBarApp*>(be_app)->Settings()->width;
|
||||
*width = fMaxWidth
|
||||
= std::min(appWidth - (kDragRegionWidth + kHMargin) * 2, timeWidth);
|
||||
= std::min(appWidth - (gDragRegionWidth + kHMargin) * 2, timeWidth);
|
||||
} else
|
||||
*width = fMaxWidth = timeWidth;
|
||||
|
||||
|
@ -37,6 +37,7 @@ All rights reserved.
|
||||
#include "WindowMenuItem.h"
|
||||
|
||||
#include <Bitmap.h>
|
||||
#include <ControlLook.h>
|
||||
#include <Debug.h>
|
||||
#include <NaturalCompare.h>
|
||||
|
||||
@ -51,11 +52,7 @@ All rights reserved.
|
||||
#include "icons.h"
|
||||
|
||||
|
||||
const float kHPad = 10.0f;
|
||||
const float kVPad = 2.0f;
|
||||
const float kLabelOffset = 8.0f;
|
||||
|
||||
const BRect kIconRect(1.0f, 1.0f, 13.0f, 14.0f);
|
||||
static float sHPad, sVPad, sLabelOffset = 0.0f;
|
||||
|
||||
|
||||
// #pragma mark - TWindowMenuItem
|
||||
@ -82,11 +79,11 @@ TWindowMenuItem::GetContentSize(float* width, float* height)
|
||||
{
|
||||
if (width != NULL) {
|
||||
if (!fExpanded) {
|
||||
*width = kHPad + fLabelWidth + kHPad;
|
||||
*width = sHPad + fLabelWidth + sHPad;
|
||||
if (fID >= 0)
|
||||
*width += fBitmap->Bounds().Width() + kLabelOffset;
|
||||
*width += fBitmap->Bounds().Width() + sLabelOffset;
|
||||
} else
|
||||
*width = Frame().Width()/* - kHPad*/;
|
||||
*width = Frame().Width()/* - sHPad*/;
|
||||
}
|
||||
|
||||
// Note: when the item is in "expanded mode", ie embedded into
|
||||
@ -98,7 +95,7 @@ TWindowMenuItem::GetContentSize(float* width, float* height)
|
||||
*height = (fID >= 0) ? fBitmap->Bounds().Height() : 0.0f;
|
||||
float labelHeight = fLabelAscent + fLabelDescent;
|
||||
*height = (labelHeight > *height) ? labelHeight : *height;
|
||||
*height += kVPad * 2;
|
||||
*height += sVPad * 2;
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,7 +123,7 @@ TWindowMenuItem::Draw()
|
||||
|
||||
rgb_color shadow = tint_color(menuColor, 1.09);
|
||||
menu->SetHighColor(shadow);
|
||||
frame.right = frame.left + kHPad / 2;
|
||||
frame.right = frame.left + sHPad / 2;
|
||||
menu->FillRect(frame);
|
||||
|
||||
menu->SetHighColor(menuColor);
|
||||
@ -157,12 +154,12 @@ void
|
||||
TWindowMenuItem::DrawContent()
|
||||
{
|
||||
BMenu* menu = Menu();
|
||||
BPoint contentLocation = ContentLocation() + BPoint(kHPad, 0);
|
||||
BPoint contentLocation = ContentLocation() + BPoint(sHPad, 0);
|
||||
|
||||
if (fID >= 0) {
|
||||
menu->SetDrawingMode(B_OP_OVER);
|
||||
|
||||
float width = fBitmap->Bounds().Width();
|
||||
const float width = fBitmap->Bounds().Width();
|
||||
if (width > 16)
|
||||
contentLocation.x -= 8;
|
||||
|
||||
@ -176,9 +173,9 @@ TWindowMenuItem::DrawContent()
|
||||
if (width > 16)
|
||||
contentLocation.x += 8;
|
||||
|
||||
contentLocation.x += kIconRect.Width() + kLabelOffset;
|
||||
contentLocation.x += width + sLabelOffset;
|
||||
}
|
||||
contentLocation.y = ContentLocation().y + kVPad + fLabelAscent;
|
||||
contentLocation.y = ContentLocation().y + sVPad + fLabelAscent;
|
||||
|
||||
menu->SetDrawingMode(B_OP_COPY);
|
||||
menu->MovePenTo(contentLocation);
|
||||
@ -262,6 +259,13 @@ TWindowMenuItem::InsertIndexFor(BMenu* menu, int32 startIndex,
|
||||
void
|
||||
TWindowMenuItem::_Init(const char* name)
|
||||
{
|
||||
if (sHPad == 0.0f) {
|
||||
// Initialize the padding values.
|
||||
sHPad = be_control_look->ComposeSpacing(B_USE_SMALL_SPACING);
|
||||
sVPad = ceilf(be_control_look->ComposeSpacing(B_USE_SMALL_SPACING) / 4.0f);
|
||||
sLabelOffset = ceilf((be_control_look->DefaultLabelSpacing() / 3.0f) * 4.0f);
|
||||
}
|
||||
|
||||
if (fMini) {
|
||||
fBitmap = fCurrentWorkSpace
|
||||
? AppResSet()->FindBitmap(B_MESSAGE_TYPE, R_WindowHiddenIcon)
|
||||
|
Loading…
Reference in New Issue
Block a user