Deskbar: Use BControlLook::ComposeIconSize() and other metrics routines.
This gets Deskbar looking somewhat more like its usual self in HiDPI environments. There are still some hardcoded sizes which need to be refactored, however.
This commit is contained in:
@@ -43,6 +43,7 @@ All rights reserved.
|
||||
#include <Autolock.h>
|
||||
#include <Bitmap.h>
|
||||
#include <Catalog.h>
|
||||
#include <ControlLook.h>
|
||||
#include <Debug.h>
|
||||
#include <Directory.h>
|
||||
#include <Dragger.h>
|
||||
@@ -901,7 +902,14 @@ TBarApp::ResizeTeamIcons()
|
||||
int32
|
||||
TBarApp::IconSize()
|
||||
{
|
||||
return fSettings.iconSize;
|
||||
static int32 iconSize = 0, composedIconSize = 0;
|
||||
if (iconSize != fSettings.iconSize) {
|
||||
composedIconSize = be_control_look->ComposeIconSize(fSettings.iconSize)
|
||||
.IntegerWidth() + 1;
|
||||
iconSize = fSettings.iconSize;
|
||||
}
|
||||
|
||||
return composedIconSize;
|
||||
}
|
||||
|
||||
|
||||
@@ -939,8 +947,8 @@ TBarApp::QuitPreferencesWindow()
|
||||
void
|
||||
TBarApp::FetchAppIcon(BarTeamInfo* barInfo)
|
||||
{
|
||||
int32 width = IconSize();
|
||||
int32 index = (width - kMinimumIconSize) / kIconSizeInterval;
|
||||
const int32 width = IconSize();
|
||||
const int32 index = (fSettings.iconSize - kMinimumIconSize) / kIconSizeInterval;
|
||||
|
||||
// first look in the icon cache
|
||||
barInfo->icon = barInfo->iconCache[index];
|
||||
|
||||
@@ -67,6 +67,7 @@ const uint32 kRebootSystem = 302;
|
||||
const uint32 kSuspendSystem = 304;
|
||||
|
||||
// icon size constants
|
||||
const int32 kIconPadding = B_USE_SMALL_SPACING;
|
||||
const int32 kMinimumIconSize = 16;
|
||||
const int32 kMaximumIconSize = 96;
|
||||
const int32 kIconSizeInterval = 8;
|
||||
|
||||
@@ -38,6 +38,7 @@ All rights reserved.
|
||||
|
||||
#include <AppFileInfo.h>
|
||||
#include <Bitmap.h>
|
||||
#include <ControlLook.h>
|
||||
#include <Debug.h>
|
||||
#include <Directory.h>
|
||||
#include <LocaleRoster.h>
|
||||
@@ -65,8 +66,6 @@ const int32 kDefaultRecentAppCount = 10;
|
||||
|
||||
const int32 kMenuTrackMargin = 20;
|
||||
const float kMinTeamItemHeight = 20.0f;
|
||||
const float kVPad = 2.0f;
|
||||
const float kIconPadding = 8.0f;
|
||||
const float kScrollerDimension = 12.0f;
|
||||
|
||||
const uint32 kUpdateOrientation = 'UpOr';
|
||||
@@ -474,7 +473,7 @@ TBarView::PlaceDeskbarMenu()
|
||||
height = std::max(fTabHeight,
|
||||
kGutter + fReplicantTray->MaxReplicantHeight() + kGutter);
|
||||
} else {
|
||||
width = gMinimumWindowWidth / 2 + kIconPadding;
|
||||
width = gMinimumWindowWidth / 2 + be_control_look->ComposeSpacing(kIconPadding);
|
||||
height = std::max(TeamMenuItemHeight(),
|
||||
kGutter + fReplicantTray->MaxReplicantHeight() + kGutter);
|
||||
}
|
||||
@@ -618,7 +617,7 @@ TBarView::PlaceApplicationBar()
|
||||
// top or bottom
|
||||
expandoFrame.top = 0;
|
||||
expandoFrame.bottom = TeamMenuItemHeight();
|
||||
expandoFrame.left = gMinimumWindowWidth / 2 + kIconPadding;
|
||||
expandoFrame.left = gMinimumWindowWidth / 2 + be_control_look->ComposeSpacing(kIconPadding);
|
||||
expandoFrame.right = screenFrame.Width();
|
||||
if (fTrayLocation != 0 && fDragRegion != NULL)
|
||||
expandoFrame.right -= fDragRegion->Frame().Width() + 1;
|
||||
@@ -1265,7 +1264,8 @@ float
|
||||
TBarView::TeamMenuItemHeight() const
|
||||
{
|
||||
const int32 iconSize = fBarApp->IconSize();
|
||||
float iconSizePadded = kVPad + iconSize + kVPad;
|
||||
float iconSizePadded = iconSize +
|
||||
ceilf(be_control_look->ComposeSpacing(B_USE_SMALL_SPACING) / 2);
|
||||
|
||||
font_height fontHeight;
|
||||
if (fExpandoMenuBar != NULL)
|
||||
|
||||
@@ -71,8 +71,7 @@ All rights reserved.
|
||||
#include "WindowMenuItem.h"
|
||||
|
||||
|
||||
const float kIconPadding = 8.0f;
|
||||
const float kDeskbarMenuWidth = gMinimumWindowWidth / 2 + kIconPadding;
|
||||
const float kDeskbarMenuWidth = gMinimumWindowWidth / 2;
|
||||
|
||||
const uint32 kMinimizeTeam = 'mntm';
|
||||
const uint32 kBringTeamToFront = 'bftm';
|
||||
@@ -839,8 +838,9 @@ TExpandoMenuBar::CheckItemSizes(int32 delta, bool reset)
|
||||
float
|
||||
TExpandoMenuBar::MinHorizontalItemWidth()
|
||||
{
|
||||
int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize();
|
||||
float iconOnlyWidth = iconSize + kIconPadding;
|
||||
const int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize();
|
||||
const int32 iconPadding = be_control_look->ComposeSpacing(kIconPadding);
|
||||
float iconOnlyWidth = iconSize + iconPadding;
|
||||
|
||||
return static_cast<TBarApp*>(be_app)->Settings()->hideLabels
|
||||
? iconOnlyWidth
|
||||
@@ -853,11 +853,12 @@ float
|
||||
TExpandoMenuBar::MaxHorizontalItemWidth()
|
||||
{
|
||||
int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize();
|
||||
float iconOnlyWidth = iconSize + kIconPadding;
|
||||
const int32 iconPadding = be_control_look->ComposeSpacing(kIconPadding);
|
||||
float iconOnlyWidth = iconSize + iconPadding;
|
||||
|
||||
// hide labels
|
||||
if (static_cast<TBarApp*>(be_app)->Settings()->hideLabels)
|
||||
return iconOnlyWidth + kIconPadding; // add an extra icon padding
|
||||
return iconOnlyWidth + iconPadding; // add an extra icon padding
|
||||
|
||||
// set max item width to 1.25x min item width
|
||||
return floorf(MinHorizontalItemWidth() * 1.25);
|
||||
@@ -942,7 +943,8 @@ TExpandoMenuBar::CheckForSizeOverrunHorizontal()
|
||||
float
|
||||
TExpandoMenuBar::MaxHorizontalWidth()
|
||||
{
|
||||
return (fBarView->DragRegion()->Frame().left - 1) - kDeskbarMenuWidth;
|
||||
return (fBarView->DragRegion()->Frame().left - 1) -
|
||||
(kDeskbarMenuWidth + be_control_look->ComposeSpacing(kIconPadding));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ TReplicantTray::TReplicantTray(TBarView* barView)
|
||||
{
|
||||
// scale replicants by font size
|
||||
fMaxReplicantHeight = std::max(kMinReplicantHeight,
|
||||
floorf(kMinReplicantHeight * be_plain_font->Size() / 12));
|
||||
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
|
||||
fMaxReplicantHeight = std::min(fMaxReplicantHeight,
|
||||
@@ -193,7 +193,8 @@ TReplicantTray::AttachedToWindow()
|
||||
|
||||
AddChild(fTime);
|
||||
|
||||
fTime->MoveTo(Bounds().right - fTime->Bounds().Width() - kTrayPadding, 2);
|
||||
const int32 trayPadding = ceilf(be_control_look->ComposeSpacing(kTrayPadding) / 2);
|
||||
fTime->MoveTo(Bounds().right - fTime->Bounds().Width() - trayPadding, 2);
|
||||
// will be moved into place later
|
||||
|
||||
if (!((TBarApp*)be_app)->Settings()->showClock)
|
||||
@@ -231,6 +232,7 @@ TReplicantTray::GetPreferredSize(float* preferredWidth, float* preferredHeight)
|
||||
{
|
||||
float width = 0;
|
||||
float height = fMinTrayHeight;
|
||||
const int32 trayPadding = ceilf(be_control_look->ComposeSpacing(kTrayPadding) / 2);
|
||||
|
||||
if (fBarView->Vertical()) {
|
||||
width = static_cast<TBarApp*>(be_app)->Settings()->width
|
||||
@@ -249,11 +251,11 @@ TReplicantTray::GetPreferredSize(float* preferredWidth, float* preferredHeight)
|
||||
} else {
|
||||
// if last replicant overruns clock then resize to accomodate
|
||||
if (ReplicantCount() > 0) {
|
||||
if (!fTime->IsHidden(fTime) && Bounds().right - kTrayPadding - 2
|
||||
if (!fTime->IsHidden(fTime) && Bounds().right - trayPadding - 2
|
||||
- fTime->Frame().Width() - kClockMargin
|
||||
< fRightBottomReplicant.right + kClockMargin) {
|
||||
width = fRightBottomReplicant.right + kClockMargin
|
||||
+ fTime->Frame().Width() + kTrayPadding + 2;
|
||||
+ fTime->Frame().Width() + trayPadding + 2;
|
||||
} else
|
||||
width = fRightBottomReplicant.right + kIconGap + kGutter;
|
||||
}
|
||||
@@ -1173,7 +1175,8 @@ TReplicantTray::AcceptAddon(BRect replicantFrame, BMessage* message)
|
||||
BPoint
|
||||
TReplicantTray::LocationForReplicant(int32 index, float replicantWidth)
|
||||
{
|
||||
BPoint loc(kTrayPadding, 0);
|
||||
const int32 trayPadding = ceilf(be_control_look->ComposeSpacing(kTrayPadding) / 2);
|
||||
BPoint loc(trayPadding, 0);
|
||||
if (fBarView->Vertical() || fBarView->MiniState()) {
|
||||
if (fBarView->Vertical() && !fBarView->Left())
|
||||
loc.x += kDragWidth; // move past dragger on left
|
||||
@@ -1196,7 +1199,7 @@ TReplicantTray::LocationForReplicant(int32 index, float replicantWidth)
|
||||
}
|
||||
|
||||
// move clock vertically centered in first row next to replicants
|
||||
fTime->MoveTo(Bounds().right - fTime->Bounds().Width() - kTrayPadding,
|
||||
fTime->MoveTo(Bounds().right - fTime->Bounds().Width() - trayPadding,
|
||||
loc.y + floorf((fMaxReplicantHeight - fTime->fHeight) / 2));
|
||||
|
||||
if (fBarView->Vertical()) {
|
||||
@@ -1205,7 +1208,7 @@ TReplicantTray::LocationForReplicant(int32 index, float replicantWidth)
|
||||
// determine free space in this row
|
||||
BRect rowRect(loc.x, loc.y,
|
||||
loc.x + static_cast<TBarApp*>(be_app)->Settings()->width
|
||||
- (kTrayPadding + kDragWidth + kGutter) * 2,
|
||||
- (trayPadding + kDragWidth + kGutter) * 2,
|
||||
loc.y + fMaxReplicantHeight);
|
||||
if (row == 0 && !fTime->IsHidden(fTime))
|
||||
rowRect.right -= kClockMargin + fTime->Frame().Width();
|
||||
|
||||
@@ -56,7 +56,7 @@ const int32 kMinimumReplicantCount = 6;
|
||||
const int32 kIconGap = 2;
|
||||
const int32 kGutter = 1;
|
||||
const int32 kDragRegionWidth = 6;
|
||||
const int32 kTrayPadding = 3;
|
||||
const int32 kTrayPadding = B_USE_HALF_ITEM_SPACING;
|
||||
const int32 kClockMargin = 12;
|
||||
|
||||
// 1 pixel for left gutter
|
||||
|
||||
@@ -41,6 +41,7 @@ All rights reserved.
|
||||
|
||||
#include <Application.h>
|
||||
#include <Collator.h>
|
||||
#include <ControlLook.h>
|
||||
#include <Debug.h>
|
||||
#include <Mime.h>
|
||||
#include <Roster.h>
|
||||
@@ -53,9 +54,6 @@ All rights reserved.
|
||||
#include "TeamMenuItem.h"
|
||||
|
||||
|
||||
const float kIconPadding = 8.0f;
|
||||
|
||||
|
||||
// #pragma mark - TTeamMenuItem
|
||||
|
||||
|
||||
@@ -94,7 +92,7 @@ TTeamMenu::AttachedToWindow()
|
||||
bool dragging = fBarView != NULL && fBarView->Dragging();
|
||||
desk_settings* settings = static_cast<TBarApp*>(be_app)->Settings();
|
||||
int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize();
|
||||
float iconOnlyWidth = iconSize + kIconPadding;
|
||||
float iconOnlyWidth = iconSize + be_control_look->ComposeSpacing(kIconPadding);
|
||||
|
||||
// calculate the minimum item width based on font and icon size
|
||||
float minItemWidth = 0;
|
||||
|
||||
@@ -63,10 +63,7 @@ All rights reserved.
|
||||
#include "WindowMenuItem.h"
|
||||
|
||||
|
||||
const float kHPad = 8.0f;
|
||||
const float kVPad = 2.0f;
|
||||
const float kLabelOffset = 8.0f;
|
||||
const float kIconPadding = 8.0f;
|
||||
static float sHPad, sVPad, sLabelOffset = 0.0f;
|
||||
|
||||
|
||||
// #pragma mark - TTeamMenuItem
|
||||
@@ -149,7 +146,7 @@ TTeamMenuItem::GetContentSize(float* width, float* height)
|
||||
else {
|
||||
bool hideLabels = static_cast<TBarApp*>(be_app)->Settings()->hideLabels;
|
||||
float iconSize = static_cast<TBarApp*>(be_app)->IconSize();
|
||||
float iconOnlyWidth = kIconPadding + iconSize + kIconPadding;
|
||||
float iconOnlyWidth = (be_control_look->ComposeSpacing(kIconPadding) * 2) + iconSize;
|
||||
|
||||
if (fBarView->MiniState()) {
|
||||
if (hideLabels)
|
||||
@@ -232,14 +229,14 @@ TTeamMenuItem::DrawContent()
|
||||
: BRect(0, 0, kMinimumIconSize - 1, kMinimumIconSize - 1);
|
||||
BRect updateRect = iconBounds;
|
||||
BPoint contentLocation = ContentLocation();
|
||||
BPoint drawLocation = contentLocation + BPoint(kHPad, kVPad);
|
||||
BPoint drawLocation = contentLocation + BPoint(sHPad, sVPad);
|
||||
|
||||
if (static_cast<TBarApp*>(be_app)->Settings()->hideLabels
|
||||
|| (fBarView->Vertical() && iconBounds.Width() > 32)) {
|
||||
// determine icon location (centered horizontally)
|
||||
float offsetx = contentLocation.x
|
||||
+ floorf((frame.Width() - iconBounds.Width()) / 2);
|
||||
float offsety = contentLocation.y + kVPad + kGutter;
|
||||
float offsety = contentLocation.y + sVPad + kGutter;
|
||||
|
||||
// draw icon
|
||||
updateRect.OffsetTo(BPoint(offsetx, offsety));
|
||||
@@ -247,10 +244,10 @@ TTeamMenuItem::DrawContent()
|
||||
|
||||
// determine label position (below icon)
|
||||
drawLocation.x = floorf((frame.Width() - fLabelWidth) / 2);
|
||||
drawLocation.y = frame.top + kVPad + iconBounds.Height() + kVPad;
|
||||
drawLocation.y = frame.top + sVPad + iconBounds.Height() + sVPad;
|
||||
} else {
|
||||
// determine icon location (centered vertically)
|
||||
float offsetx = contentLocation.x + kHPad;
|
||||
float offsetx = contentLocation.x + sHPad;
|
||||
float offsety = contentLocation.y +
|
||||
floorf((frame.Height() - iconBounds.Height()) / 2);
|
||||
|
||||
@@ -259,7 +256,7 @@ TTeamMenuItem::DrawContent()
|
||||
menu->DrawBitmapAsync(fIcon, updateRect);
|
||||
|
||||
// determine label position (centered vertically)
|
||||
drawLocation.x += iconBounds.Width() + kLabelOffset;
|
||||
drawLocation.x += iconBounds.Width() + sLabelOffset;
|
||||
drawLocation.y = frame.top
|
||||
+ ceilf((frame.Height() - fLabelHeight) / 2);
|
||||
}
|
||||
@@ -310,7 +307,7 @@ void
|
||||
TTeamMenuItem::DrawExpanderArrow()
|
||||
{
|
||||
BRect frame = Frame();
|
||||
BRect rect(0.0f, 0.0f, kSwitchWidth, kHPad + 2.0f);
|
||||
BRect rect(0.0f, 0.0f, kSwitchWidth, sHPad + 2.0f);
|
||||
rect.OffsetTo(BPoint(frame.right - rect.Width(),
|
||||
ContentLocation().y + ((frame.Height() - rect.Height()) / 2)));
|
||||
|
||||
@@ -426,6 +423,13 @@ void
|
||||
TTeamMenuItem::_Init(BList* team, BBitmap* icon, char* name, char* signature,
|
||||
float width, float height)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
fTeam = team;
|
||||
fIcon = icon;
|
||||
fSignature = signature;
|
||||
|
||||
Reference in New Issue
Block a user