Deskbar: Adjust team menu items with font size.
The Deskbar team menu should look the same at 12pt but much better at larger (and smaller) font sizes. Determine team menu item height in TBarView instead of TTeamMenuItem::GetContentSize() because it is needed earlier in the process, and also call method in GetContentSize(). The clock is centered horizontally in the first replicant row and the width can grow to push the replicant icons better at larger font sizes. The replicant tray and clock go to the bottom in horizontal bottom mode and go to the top in horizontal top mode for Fitt's Law convinience and go in the center of the first row in vertical mode. Grow horizontal team item widths with font size, and shrink them down to 1/2 of full width to fit more, or 1/2 padding for icon-only. In horizontal mode the menu item size increases so that you can fit approximate the same amount of label text based on icon and font size. hit the width limit the items shrink and the label gets truncated (like before.) Scale team menu with font size. Reduce to half width for hide labels. Change-Id: I93ecc8acded274b994728e7247768455862e31c5 Reviewed-on: https://review.haiku-os.org/c/haiku/+/345 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
1c765f5b62
commit
15eb397e32
@@ -64,9 +64,10 @@ const int32 kDefaultRecentDocCount = 10;
|
||||
const int32 kDefaultRecentAppCount = 10;
|
||||
|
||||
const int32 kMenuTrackMargin = 20;
|
||||
const float kMinTeamItemHeight = 20.0f;
|
||||
const float kVPad = 2.0f;
|
||||
|
||||
const uint32 kUpdateOrientation = 'UpOr';
|
||||
const float kSepItemWidth = 5.0f;
|
||||
|
||||
|
||||
class BarViewMessageFilter : public BMessageFilter
|
||||
@@ -149,6 +150,7 @@ TBarView::TBarView(BRect frame, bool vertical, bool left, bool top,
|
||||
fMouseFilter(NULL)
|
||||
{
|
||||
// determine the initial Be menu size
|
||||
// (will be updated later)
|
||||
BRect menuFrame(frame);
|
||||
if (fVertical)
|
||||
menuFrame.bottom = menuFrame.top + kMenuBarHeight;
|
||||
@@ -212,6 +214,9 @@ TBarView::AttachedToWindow()
|
||||
fTrackingHookData.fTrackingHook = MenuTrackingHook;
|
||||
fTrackingHookData.fTarget = BMessenger(this);
|
||||
fTrackingHookData.fDragMessage = new BMessage(B_REFS_RECEIVED);
|
||||
|
||||
if (!fVertical)
|
||||
UpdatePlacement(); // update MenuBarHeight
|
||||
}
|
||||
|
||||
|
||||
@@ -434,7 +439,8 @@ TBarView::PlaceDeskbarMenu()
|
||||
menuFrame.bottom = menuFrame.top + height;
|
||||
} else {
|
||||
width = gMinimumWindowWidth;
|
||||
height = fBarApp->IconSize() + 4;
|
||||
height = std::max(TeamMenuItemHeight(),
|
||||
kGutter + fReplicantTray->MaxReplicantHeight() + kGutter);
|
||||
menuFrame.bottom = menuFrame.top + height;
|
||||
}
|
||||
|
||||
@@ -574,7 +580,7 @@ TBarView::PlaceApplicationBar()
|
||||
} else {
|
||||
// top or bottom
|
||||
expandoFrame.top = 0;
|
||||
expandoFrame.bottom = fBarApp->IconSize() + 4;
|
||||
expandoFrame.bottom = TeamMenuItemHeight();
|
||||
|
||||
if (fBarMenuBar != NULL)
|
||||
expandoFrame.left = fBarMenuBar->Frame().Width() + 1;
|
||||
@@ -594,11 +600,6 @@ TBarView::PlaceApplicationBar()
|
||||
fExpandoMenuBar->MoveTo(0, 0);
|
||||
fExpandoMenuBar->ResizeTo(expandoFrame.Width(), expandoFrame.Height());
|
||||
|
||||
if (!fVertical) {
|
||||
// Set the max item width based on icon size
|
||||
fExpandoMenuBar->SetMaxItemWidth();
|
||||
}
|
||||
|
||||
if (fState == kExpandoState)
|
||||
fExpandoMenuBar->BuildItems();
|
||||
|
||||
@@ -645,7 +646,8 @@ TBarView::GetPreferredWindowSize(BRect screenFrame, float* width, float* height)
|
||||
} else {
|
||||
// top or bottom, full
|
||||
fExpandoMenuBar->CheckItemSizes(0);
|
||||
windowHeight = fBarApp->IconSize() + 4;
|
||||
windowHeight = std::max(TeamMenuItemHeight(),
|
||||
kGutter + fReplicantTray->MaxReplicantHeight() + kGutter);
|
||||
windowWidth = screenFrame.Width();
|
||||
}
|
||||
} else {
|
||||
@@ -1230,3 +1232,37 @@ TBarView::IconFrame(const char* name) const
|
||||
{
|
||||
return OffsetIconFrame(fReplicantTray->IconFrame(name));
|
||||
}
|
||||
|
||||
|
||||
float
|
||||
TBarView::TeamMenuItemHeight() const
|
||||
{
|
||||
const int32 iconSize = fBarApp->IconSize();
|
||||
float iconSizePadded = kVPad + iconSize + kVPad;
|
||||
|
||||
font_height fontHeight;
|
||||
if (fExpandoMenuBar != NULL)
|
||||
fExpandoMenuBar->GetFontHeight(&fontHeight);
|
||||
else
|
||||
GetFontHeight(&fontHeight);
|
||||
|
||||
float labelHeight = fontHeight.ascent + fontHeight.descent;
|
||||
labelHeight = labelHeight < kMinTeamItemHeight ? kMinTeamItemHeight
|
||||
: ceilf(labelHeight * 1.1f);
|
||||
|
||||
bool hideLabels = static_cast<TBarApp*>(be_app)->Settings()->hideLabels;
|
||||
if (hideLabels && iconSize > B_MINI_ICON) {
|
||||
// height is determined based solely on icon size
|
||||
return iconSizePadded;
|
||||
} else if (!fVertical || fVertical && iconSize <= B_LARGE_ICON) {
|
||||
// horizontal or vertical with label on same row as icon:
|
||||
// height based on icon size or font size, whichever is bigger
|
||||
return std::max(iconSizePadded, labelHeight);
|
||||
} else if (fVertical && iconSize > B_LARGE_ICON) {
|
||||
// vertical with label below icon: height based on icon and label
|
||||
return ceilf(iconSizePadded + labelHeight);
|
||||
} else {
|
||||
// height is determined based solely on label height
|
||||
return labelHeight;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,6 +169,8 @@ public:
|
||||
TDragRegion* DragRegion() const { return fDragRegion; }
|
||||
TReplicantTray* ReplicantTray() const { return fReplicantTray; }
|
||||
|
||||
float TeamMenuItemHeight() const;
|
||||
|
||||
private:
|
||||
friend class TBarApp;
|
||||
friend class TDeskbarMenu;
|
||||
|
||||
@@ -71,7 +71,6 @@ All rights reserved.
|
||||
|
||||
|
||||
const float kMinMenuItemWidth = 50.0f;
|
||||
const float kSepItemWidth = 5.0f;
|
||||
const float kIconPadding = 8.0f;
|
||||
|
||||
const uint32 kMinimizeTeam = 'mntm';
|
||||
@@ -95,14 +94,13 @@ TExpandoMenuBar::TExpandoMenuBar(TBarView* barView, bool vertical)
|
||||
fVertical(vertical),
|
||||
fOverflow(false),
|
||||
fFirstBuild(true),
|
||||
fDeskbarMenuWidth(kMinMenuItemWidth),
|
||||
fDeskbarMenuWidth(gMinimumWindowWidth),
|
||||
fPreviousDragTargetItem(NULL),
|
||||
fLastMousedOverItem(NULL),
|
||||
fLastClickedItem(NULL)
|
||||
{
|
||||
SetItemMargins(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
SetFont(be_plain_font);
|
||||
SetMaxItemWidth();
|
||||
|
||||
// top or bottom mode, add deskbar menu and sep for menubar tracking
|
||||
// consistency
|
||||
@@ -468,21 +466,12 @@ TExpandoMenuBar::BuildItems()
|
||||
BMessenger self(this);
|
||||
TBarApp::Subscribe(self, &fTeamList);
|
||||
|
||||
int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize();
|
||||
desk_settings* settings = static_cast<TBarApp*>(be_app)->Settings();
|
||||
|
||||
float itemWidth = -1.0f;
|
||||
if (fVertical) {
|
||||
itemWidth = Frame().Width();
|
||||
SetMaxContentWidth(itemWidth);
|
||||
} else {
|
||||
itemWidth = iconSize;
|
||||
if (!settings->hideLabels)
|
||||
itemWidth += gMinimumWindowWidth - kMinimumIconSize;
|
||||
else
|
||||
itemWidth += kIconPadding * 2;
|
||||
}
|
||||
float itemHeight = -1.0f;
|
||||
} else
|
||||
CheckItemSizes(0, true); // force reset
|
||||
|
||||
TeamMenuItemMap items;
|
||||
int32 itemCount = CountItems();
|
||||
@@ -495,6 +484,7 @@ TExpandoMenuBar::BuildItems()
|
||||
items[BString(item->Signature()).ToLower()] = item;
|
||||
}
|
||||
|
||||
desk_settings* settings = static_cast<TBarApp*>(be_app)->Settings();
|
||||
if (settings->sortRunningApps)
|
||||
fTeamList.SortItems(TTeamMenu::CompareByName);
|
||||
|
||||
@@ -506,8 +496,7 @@ TExpandoMenuBar::BuildItems()
|
||||
if (iter == items.end()) {
|
||||
// new team
|
||||
TTeamMenuItem* item = new TTeamMenuItem(barInfo->teams,
|
||||
barInfo->icon, barInfo->name, barInfo->sig, itemWidth,
|
||||
itemHeight);
|
||||
barInfo->icon, barInfo->name, barInfo->sig, itemWidth);
|
||||
|
||||
if (settings->trackerAlwaysFirst
|
||||
&& strcasecmp(barInfo->sig, kTrackerSignature) == 0) {
|
||||
@@ -522,7 +511,6 @@ TExpandoMenuBar::BuildItems()
|
||||
TTeamMenuItem* item = iter->second;
|
||||
item->SetIcon(barInfo->icon);
|
||||
item->SetOverrideWidth(itemWidth);
|
||||
item->SetOverrideHeight(itemHeight);
|
||||
|
||||
if (settings->trackerAlwaysFirst
|
||||
&& strcasecmp(barInfo->sig, kTrackerSignature) == 0) {
|
||||
@@ -560,7 +548,7 @@ TExpandoMenuBar::BuildItems()
|
||||
if (CountItems() == 0) {
|
||||
// If we're empty, BMenuBar::AttachedToWindow() resizes us to some
|
||||
// weird value - we just override it again
|
||||
ResizeTo(itemWidth, 0);
|
||||
ResizeTo(gMinimumWindowWidth, 0);
|
||||
}
|
||||
|
||||
fFirstBuild = false;
|
||||
@@ -624,24 +612,9 @@ void
|
||||
TExpandoMenuBar::AddTeam(BList* team, BBitmap* icon, char* name,
|
||||
char* signature)
|
||||
{
|
||||
int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize();
|
||||
TTeamMenuItem* item = new TTeamMenuItem(team, icon, name, signature);
|
||||
|
||||
desk_settings* settings = static_cast<TBarApp*>(be_app)->Settings();
|
||||
|
||||
float itemWidth = -1.0f;
|
||||
if (fVertical)
|
||||
itemWidth = fBarView->Bounds().Width();
|
||||
else {
|
||||
itemWidth = iconSize;
|
||||
if (!settings->hideLabels)
|
||||
itemWidth += gMinimumWindowWidth - kMinimumIconSize;
|
||||
else
|
||||
itemWidth += kIconPadding * 2;
|
||||
}
|
||||
float itemHeight = -1.0f;
|
||||
|
||||
TTeamMenuItem* item = new TTeamMenuItem(team, icon, name, signature,
|
||||
itemWidth, itemHeight);
|
||||
|
||||
if (settings->trackerAlwaysFirst
|
||||
&& strcasecmp(signature, kTrackerSignature) == 0) {
|
||||
AddItem(item, 0);
|
||||
@@ -746,34 +719,44 @@ TExpandoMenuBar::RemoveTeam(team_id team, bool partial)
|
||||
|
||||
|
||||
void
|
||||
TExpandoMenuBar::CheckItemSizes(int32 delta)
|
||||
TExpandoMenuBar::CheckItemSizes(int32 delta, bool reset)
|
||||
{
|
||||
if (fBarView->Vertical())
|
||||
if (fVertical)
|
||||
return;
|
||||
|
||||
bool drawLabels = !static_cast<TBarApp*>(be_app)->Settings()->hideLabels;
|
||||
int32 itemCount = CountItems();
|
||||
TTeamMenuItem* item = static_cast<TTeamMenuItem*>(ItemAt(0));
|
||||
if (itemCount < 1 || item == NULL)
|
||||
return;
|
||||
|
||||
float maxWidth = fBarView->DragRegion()->Frame().left
|
||||
- fDeskbarMenuWidth - kSepItemWidth;
|
||||
int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize();
|
||||
float iconOnlyWidth = kIconPadding + iconSize + kIconPadding;
|
||||
float minItemWidth = drawLabels
|
||||
? iconOnlyWidth + kMinMenuItemWidth
|
||||
: iconOnlyWidth - kIconPadding;
|
||||
float maxItemWidth = drawLabels
|
||||
? gMinimumWindowWidth + iconSize - kMinimumIconSize
|
||||
: iconOnlyWidth;
|
||||
float menuWidth = maxItemWidth * CountItems() + fDeskbarMenuWidth
|
||||
+ kSepItemWidth;
|
||||
|
||||
bool reset = false;
|
||||
float maxItemWidth;
|
||||
float minItemWidth;
|
||||
if (static_cast<TBarApp*>(be_app)->Settings()->hideLabels) {
|
||||
maxItemWidth = iconOnlyWidth;
|
||||
minItemWidth = iconOnlyWidth - kIconPadding * 3 / 4;
|
||||
} else {
|
||||
float labelWidth = gMinimumWindowWidth;
|
||||
labelWidth += (be_plain_font->Size() - 12) * 4 + iconSize
|
||||
- kMinimumIconSize;
|
||||
maxItemWidth = iconOnlyWidth + labelWidth;
|
||||
minItemWidth = iconOnlyWidth + floorf(labelWidth / 4);
|
||||
}
|
||||
|
||||
float menuWidth = fDeskbarMenuWidth + kSepItemWidth
|
||||
+ maxItemWidth * itemCount;
|
||||
float maxWidth = fBarView->DragRegion()->Frame().left - 1
|
||||
- fDeskbarMenuWidth - kSepItemWidth;
|
||||
|
||||
float newWidth = -1.0f;
|
||||
|
||||
if (delta >= 0 && menuWidth > maxWidth) {
|
||||
fOverflow = true;
|
||||
reset = true;
|
||||
newWidth = floorf(maxWidth / CountItems());
|
||||
} else if (delta < 0 && fOverflow) {
|
||||
} else if (reset || (delta < 0 && fOverflow)) {
|
||||
reset = true;
|
||||
if (menuWidth > maxWidth)
|
||||
newWidth = floorf(maxWidth / CountItems());
|
||||
@@ -820,8 +803,7 @@ TExpandoMenuBar::SetMenuLayout(menu_layout layout)
|
||||
{
|
||||
fVertical = layout == B_ITEMS_IN_COLUMN;
|
||||
BPrivate::MenuPrivate(this).SetLayout(layout);
|
||||
SetMaxItemWidth();
|
||||
// when the menu layout changes, make sure to set the max width
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
|
||||
@@ -884,38 +866,22 @@ TExpandoMenuBar::CheckForSizeOverrun()
|
||||
}
|
||||
|
||||
// horizontal
|
||||
int32 count = CountItems() - 1;
|
||||
if (count < 0)
|
||||
int32 itemCount = CountItems();
|
||||
TTeamMenuItem* item = static_cast<TTeamMenuItem*>(ItemAt(0));
|
||||
if (itemCount < 1 || item == NULL)
|
||||
return false;
|
||||
|
||||
int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize();
|
||||
float iconOnlyWidth = kIconPadding + iconSize + kIconPadding;
|
||||
float minItemWidth = !static_cast<TBarApp*>(be_app)->Settings()->hideLabels
|
||||
? iconOnlyWidth + kMinMenuItemWidth
|
||||
: iconOnlyWidth - kIconPadding;
|
||||
float menuWidth = minItemWidth * CountItems() + fDeskbarMenuWidth
|
||||
+ kSepItemWidth;
|
||||
float maxWidth = fBarView->DragRegion()->Frame().left
|
||||
- fDeskbarMenuWidth - kSepItemWidth;
|
||||
float itemWidth = item->Frame().Width();
|
||||
if (itemWidth <= 0)
|
||||
return false;
|
||||
|
||||
float menuWidth = fDeskbarMenuWidth + kSepItemWidth + itemWidth * itemCount;
|
||||
float maxWidth = fBarView->DragRegion()->Frame().left - 1;
|
||||
|
||||
return menuWidth > maxWidth;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TExpandoMenuBar::SetMaxItemWidth()
|
||||
{
|
||||
if (fVertical)
|
||||
SetMaxContentWidth(static_cast<TBarApp*>(be_app)->Settings()->width);
|
||||
else {
|
||||
// Make more room for the icon in horizontal mode
|
||||
int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize();
|
||||
SetMaxContentWidth(gMinimumWindowWidth + iconSize
|
||||
- kMinimumIconSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TExpandoMenuBar::SizeWindow(int32 delta)
|
||||
{
|
||||
@@ -1029,9 +995,10 @@ TExpandoMenuBar::monitor_team_windows(void* arg)
|
||||
((1 << current_workspace())
|
||||
& wInfo->workspaces) != 0);
|
||||
|
||||
if (strcasecmp(item->Label(), windowName) > 0)
|
||||
if (strcasecmp(item->Label(), windowName)
|
||||
> 0) {
|
||||
item->SetLabel(windowName);
|
||||
|
||||
}
|
||||
if (item->Modified())
|
||||
itemModified = true;
|
||||
} else if (teamItem->IsExpanded()) {
|
||||
|
||||
@@ -45,6 +45,9 @@ All rights reserved.
|
||||
#include <Locker.h>
|
||||
|
||||
|
||||
const float kSepItemWidth = 5.0f;
|
||||
|
||||
|
||||
enum drag_and_drop_selection {
|
||||
kNoSelection,
|
||||
kDeskbarMenuSelection,
|
||||
@@ -83,13 +86,11 @@ public:
|
||||
BMenuItem** _item = NULL);
|
||||
bool InDeskbarMenu(BPoint) const;
|
||||
|
||||
void CheckItemSizes(int32 delta);
|
||||
void CheckItemSizes(int32 delta, bool reset = false);
|
||||
|
||||
menu_layout MenuLayout() const;
|
||||
void SetMenuLayout(menu_layout layout);
|
||||
|
||||
void SetMaxItemWidth();
|
||||
|
||||
void SizeWindow(int32 delta);
|
||||
bool CheckForSizeOverrun();
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ All rights reserved.
|
||||
|
||||
#include "BarApp.h"
|
||||
#include "DeskbarUtils.h"
|
||||
#include "ExpandoMenuBar.h"
|
||||
#include "ResourceSet.h"
|
||||
#include "StatusViewShelf.h"
|
||||
#include "TimeView.h"
|
||||
@@ -1191,7 +1192,8 @@ TReplicantTray::LocationForReplicant(int32 index, float replicantWidth)
|
||||
replicantRect.left = view->Frame().right + kIconGap + 1;
|
||||
}
|
||||
|
||||
// calculated left position, add replicantWidth to get right position
|
||||
// calculated left position, add replicantWidth to get the
|
||||
// right position
|
||||
replicantRect.right = replicantRect.left + replicantWidth;
|
||||
|
||||
// check if replicant fits in this row
|
||||
@@ -1203,15 +1205,36 @@ TReplicantTray::LocationForReplicant(int32 index, float replicantWidth)
|
||||
|
||||
// check next row
|
||||
}
|
||||
} else if (index > 0) {
|
||||
// get the last replicant added for placement reference
|
||||
BView* view = NULL;
|
||||
fShelf->ReplicantAt(index - 1, &view);
|
||||
if (view != NULL) {
|
||||
// push this replicant placement past the last one
|
||||
loc.x = view->Frame().right + kIconGap + 1;
|
||||
loc.y = view->Frame().top;
|
||||
|
||||
fTime->MoveTo(Bounds().right - fTime->Bounds().Width()
|
||||
- kTrayPadding, 2);
|
||||
} else {
|
||||
if (index > 0) {
|
||||
// get the last replicant added for placement reference
|
||||
BView* view = NULL;
|
||||
fShelf->ReplicantAt(index - 1, &view);
|
||||
if (view != NULL) {
|
||||
// push this replicant placement past the last one
|
||||
loc.x = view->Frame().right + kIconGap + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (fBarView->Vertical()) {
|
||||
// center vertically
|
||||
loc.y = floorf((kMenuBarHeight - fMaxReplicantHeight) / 2) - 1;
|
||||
} else {
|
||||
if (fBarView->Top()) {
|
||||
// align top
|
||||
loc.y = 3;
|
||||
} else {
|
||||
// align bottom
|
||||
loc.y = fBarView->TeamMenuItemHeight() - fMaxReplicantHeight - 2;
|
||||
}
|
||||
}
|
||||
|
||||
// move time in place next to replicants
|
||||
fTime->MoveTo(Bounds().right - fTime->Bounds().Width() - kTrayPadding,
|
||||
loc.y + (fMaxReplicantHeight - fTime->Bounds().Height()) / 2);
|
||||
}
|
||||
|
||||
if (loc.y > fRightBottomReplicant.top
|
||||
|
||||
@@ -40,10 +40,13 @@ All rights reserved.
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <Bitmap.h>
|
||||
#include <ControlLook.h>
|
||||
#include <Debug.h>
|
||||
#include <Font.h>
|
||||
#include <Mime.h>
|
||||
#include <Region.h>
|
||||
#include <Roster.h>
|
||||
#include <Resources.h>
|
||||
@@ -54,6 +57,7 @@ All rights reserved.
|
||||
#include "ExpandoMenuBar.h"
|
||||
#include "ResourceSet.h"
|
||||
#include "ShowHideMenuItem.h"
|
||||
#include "StatusView.h"
|
||||
#include "TeamMenu.h"
|
||||
#include "WindowMenu.h"
|
||||
#include "WindowMenuItem.h"
|
||||
@@ -62,7 +66,7 @@ All rights reserved.
|
||||
const float kHPad = 8.0f;
|
||||
const float kVPad = 2.0f;
|
||||
const float kLabelOffset = 8.0f;
|
||||
const float kSwitchWidth = 12.0f;
|
||||
const float kIconPadding = 8.0f;
|
||||
|
||||
|
||||
// #pragma mark - TTeamMenuItem
|
||||
@@ -138,39 +142,39 @@ TTeamMenuItem::SetIcon(BBitmap* icon) {
|
||||
void
|
||||
TTeamMenuItem::GetContentSize(float* width, float* height)
|
||||
{
|
||||
BRect iconBounds;
|
||||
|
||||
if (fIcon != NULL)
|
||||
iconBounds = fIcon->Bounds();
|
||||
else
|
||||
iconBounds = BRect(0, 0, kMinimumIconSize - 1, kMinimumIconSize - 1);
|
||||
|
||||
BMenuItem::GetContentSize(width, height);
|
||||
|
||||
if (fOverrideWidth != -1.0f)
|
||||
*width = fOverrideWidth;
|
||||
else {
|
||||
*width = kHPad + iconBounds.Width() + kHPad;
|
||||
if (iconBounds.Width() <= 32
|
||||
&& !static_cast<TBarApp*>(be_app)->Settings()->hideLabels) {
|
||||
*width += LabelWidth() + kHPad;
|
||||
}
|
||||
bool hideLabels = static_cast<TBarApp*>(be_app)->Settings()->hideLabels;
|
||||
float iconSize = static_cast<TBarApp*>(be_app)->IconSize();
|
||||
float iconOnlyWidth = kIconPadding + iconSize + kIconPadding;
|
||||
|
||||
if (fBarView->MiniState()) {
|
||||
if (hideLabels)
|
||||
*width = iconOnlyWidth;
|
||||
else
|
||||
*width = gMinimumWindowWidth - (kDragRegionWidth + kGutter) * 2;
|
||||
} else if (!fBarView->Vertical()) {
|
||||
if (hideLabels)
|
||||
*width = iconOnlyWidth;
|
||||
else {
|
||||
float labelWidth = gMinimumWindowWidth;
|
||||
BFont font;
|
||||
Menu()->GetFont(&font);
|
||||
labelWidth += (font.Size() - 12) * 4 + iconSize - 16;
|
||||
// do font and icon scaling
|
||||
*width = iconOnlyWidth + labelWidth;
|
||||
}
|
||||
} else
|
||||
*width = static_cast<TBarApp*>(be_app)->Settings()->width;
|
||||
}
|
||||
|
||||
if (fOverrideHeight != -1.0f)
|
||||
*height = fOverrideHeight;
|
||||
else {
|
||||
if (fBarView->Vertical()) {
|
||||
*height = iconBounds.Height() + kVPad * 2;
|
||||
if (!static_cast<TBarApp*>(be_app)->Settings()->hideLabels
|
||||
&& iconBounds.Width() > 32) {
|
||||
*height += fLabelAscent + fLabelDescent;
|
||||
}
|
||||
} else {
|
||||
*height = iconBounds.Height() + kVPad * 2;
|
||||
}
|
||||
}
|
||||
*height += 2;
|
||||
else
|
||||
*height = fBarView->TeamMenuItemHeight();
|
||||
}
|
||||
|
||||
|
||||
@@ -223,6 +227,8 @@ void
|
||||
TTeamMenuItem::DrawContent()
|
||||
{
|
||||
BMenu* menu = Menu();
|
||||
BRect frame = Frame();
|
||||
|
||||
if (fIcon != NULL) {
|
||||
if (fIcon->ColorSpace() == B_RGBA32) {
|
||||
menu->SetDrawingMode(B_OP_ALPHA);
|
||||
@@ -230,48 +236,50 @@ TTeamMenuItem::DrawContent()
|
||||
} else
|
||||
menu->SetDrawingMode(B_OP_OVER);
|
||||
|
||||
BRect frame = Frame();
|
||||
BRect iconBounds = fIcon->Bounds();
|
||||
BRect iconBounds = fIcon != NULL ? fIcon->Bounds()
|
||||
: BRect(0, 0, kMinimumIconSize - 1, kMinimumIconSize - 1);
|
||||
BRect updateRect = iconBounds;
|
||||
float extra = fBarView->Vertical() ? 0.0f : -1.0f;
|
||||
BPoint contentLocation = ContentLocation();
|
||||
BPoint drawLocation = contentLocation + BPoint(kHPad, kVPad);
|
||||
|
||||
if (static_cast<TBarApp*>(be_app)->Settings()->hideLabels
|
||||
|| (fBarView->Vertical() && iconBounds.Width() > 32)) {
|
||||
// determine icon location (centered horizontally)
|
||||
float offsetx = contentLocation.x
|
||||
+ ((frame.Width() - iconBounds.Width()) / 2) + extra;
|
||||
float offsety = contentLocation.y + 3.0f + extra;
|
||||
+ floorf((frame.Width() - iconBounds.Width()) / 2);
|
||||
float offsety = contentLocation.y + kVPad + kGutter;
|
||||
|
||||
// draw icon
|
||||
updateRect.OffsetTo(BPoint(offsetx, offsety));
|
||||
menu->DrawBitmapAsync(fIcon, updateRect);
|
||||
|
||||
drawLocation.x = ((frame.Width() - LabelWidth()) / 2);
|
||||
drawLocation.y = frame.top + iconBounds.Height() + kVPad * 2;
|
||||
// determine label position (below icon)
|
||||
drawLocation.x = floorf((frame.Width() - fLabelWidth) / 2);
|
||||
drawLocation.y = frame.top + kVPad + iconBounds.Height() + kVPad;
|
||||
} else {
|
||||
// determine icon location (centered vertically)
|
||||
float offsetx = contentLocation.x + kHPad;
|
||||
float offsety = contentLocation.y +
|
||||
((frame.Height() - iconBounds.Height()) / 2) + extra;
|
||||
floorf((frame.Height() - iconBounds.Height()) / 2);
|
||||
|
||||
// draw icon
|
||||
updateRect.OffsetTo(BPoint(offsetx, offsety));
|
||||
menu->DrawBitmapAsync(fIcon, updateRect);
|
||||
|
||||
float labelHeight = fLabelAscent + fLabelDescent;
|
||||
// determine label position (centered vertically)
|
||||
drawLocation.x += iconBounds.Width() + kLabelOffset;
|
||||
drawLocation.y = frame.top + ((frame.Height() - labelHeight) / 2)
|
||||
+ extra;
|
||||
drawLocation.y = frame.top
|
||||
+ ceilf((frame.Height() - fLabelHeight) / 2);
|
||||
}
|
||||
|
||||
menu->MovePenTo(drawLocation);
|
||||
}
|
||||
|
||||
menu->SetDrawingMode(B_OP_OVER);
|
||||
menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR));
|
||||
|
||||
// override the drawing of the content when the item is disabled
|
||||
// the wrong lowcolor is used when the item is disabled since the
|
||||
// text color does not change
|
||||
menu->MovePenBy(0, fLabelAscent);
|
||||
menu->SetDrawingMode(B_OP_OVER);
|
||||
menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR));
|
||||
|
||||
bool canHandle = !fBarView->Dragging()
|
||||
|| fBarView->AppCanHandleTypes(Signature());
|
||||
@@ -286,13 +294,18 @@ TTeamMenuItem::DrawContent()
|
||||
else
|
||||
menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR));
|
||||
|
||||
menu->MovePenBy(0, fLabelAscent);
|
||||
|
||||
// draw label
|
||||
if (!static_cast<TBarApp*>(be_app)->Settings()->hideLabels) {
|
||||
float labelWidth = menu->StringWidth(Label());
|
||||
BPoint penLocation = menu->PenLocation();
|
||||
float offset = penLocation.x - Frame().left;
|
||||
// truncate to max width
|
||||
float offset = penLocation.x - frame.left;
|
||||
menu->DrawString(Label(labelWidth + offset));
|
||||
}
|
||||
|
||||
// draw expander arrow
|
||||
if (fBarView->Vertical()
|
||||
&& static_cast<TBarApp*>(be_app)->Settings()->superExpando
|
||||
&& fBarView->ExpandoState()) {
|
||||
@@ -304,23 +317,18 @@ TTeamMenuItem::DrawContent()
|
||||
void
|
||||
TTeamMenuItem::DrawExpanderArrow()
|
||||
{
|
||||
BMenu* menu = Menu();
|
||||
BRect frame = Frame();
|
||||
BRect rect(0.0f, 0.0f, kSwitchWidth, kHPad + 2.0f);
|
||||
|
||||
rect.OffsetTo(BPoint(frame.right - rect.Width(),
|
||||
ContentLocation().y + ((frame.Height() - rect.Height()) / 2)));
|
||||
|
||||
float colorTint = B_DARKEN_3_TINT;
|
||||
|
||||
rgb_color bgColor = ui_color(B_MENU_BACKGROUND_COLOR);
|
||||
if (bgColor.red + bgColor.green + bgColor.blue <= 128 * 3) {
|
||||
if (bgColor.red + bgColor.green + bgColor.blue <= 128 * 3)
|
||||
colorTint = B_LIGHTEN_2_TINT;
|
||||
}
|
||||
|
||||
be_control_look->DrawArrowShape(menu, rect, rect,
|
||||
bgColor, fArrowDirection, 0,
|
||||
colorTint);
|
||||
be_control_look->DrawArrowShape(Menu(), rect, Menu()->Frame(),
|
||||
bgColor, fArrowDirection, 0, colorTint);
|
||||
}
|
||||
|
||||
|
||||
@@ -372,8 +380,8 @@ TTeamMenuItem::ToggleExpandState(bool resizeWindow)
|
||||
int32 childIndex = parent->IndexOf(this) + 1;
|
||||
while (parent->SubmenuAt(childIndex) == NULL
|
||||
&& childIndex < parent->CountItems()) {
|
||||
windowItem
|
||||
= static_cast<TWindowMenuItem*>(parent->RemoveItem(childIndex));
|
||||
windowItem = static_cast<TWindowMenuItem*>(
|
||||
parent->RemoveItem(childIndex));
|
||||
sub->AddItem(windowItem, 0);
|
||||
windowItem->SetExpanded(false);
|
||||
}
|
||||
@@ -449,6 +457,7 @@ TTeamMenuItem::_Init(BList* team, BBitmap* icon, char* name, char* signature,
|
||||
font.GetHeight(&fontHeight);
|
||||
fLabelAscent = ceilf(fontHeight.ascent);
|
||||
fLabelDescent = ceilf(fontHeight.descent + fontHeight.leading);
|
||||
fLabelHeight = fLabelAscent + fLabelDescent;
|
||||
|
||||
fOverriddenSelected = false;
|
||||
|
||||
|
||||
@@ -44,6 +44,9 @@ All rights reserved.
|
||||
#include "TruncatableMenuItem.h"
|
||||
|
||||
|
||||
const float kSwitchWidth = 12.0f;
|
||||
|
||||
|
||||
class BBitmap;
|
||||
class TBarView;
|
||||
class TWindowMenuItem;
|
||||
@@ -108,6 +111,7 @@ private:
|
||||
float fLabelWidth;
|
||||
float fLabelAscent;
|
||||
float fLabelDescent;
|
||||
float fLabelHeight;
|
||||
|
||||
bool fOverriddenSelected;
|
||||
|
||||
|
||||
@@ -52,6 +52,9 @@ All rights reserved.
|
||||
#include <Window.h>
|
||||
|
||||
#include "BarApp.h"
|
||||
#include "BarView.h"
|
||||
#include "BarWindow.h"
|
||||
#include "StatusView.h"
|
||||
#include "CalendarMenuWindow.h"
|
||||
#include "StatusView.h"
|
||||
|
||||
@@ -185,16 +188,21 @@ TTimeView::FrameMoved(BPoint)
|
||||
void
|
||||
TTimeView::GetPreferredSize(float* width, float* height)
|
||||
{
|
||||
*height = fHeight;
|
||||
|
||||
float timeWidth = StringWidth(fCurrentTimeStr);
|
||||
|
||||
if (fOrientation) {
|
||||
// set the height based on the font size
|
||||
font_height fontHeight;
|
||||
GetFontHeight(&fontHeight);
|
||||
fHeight = fontHeight.ascent + fontHeight.descent;
|
||||
|
||||
if (Vertical()) {
|
||||
float appWidth = static_cast<TBarApp*>(be_app)->Settings()->width;
|
||||
*width = fMaxWidth
|
||||
= std::min(appWidth - (kDragRegionWidth + kHMargin) * 2, timeWidth);
|
||||
} else
|
||||
*width = fMaxWidth = timeWidth;
|
||||
|
||||
*height = fHeight;
|
||||
}
|
||||
|
||||
|
||||
@@ -418,7 +426,8 @@ TTimeView::UpdateTimeFormat()
|
||||
|
||||
delete fTimeFormat;
|
||||
fTimeFormat = new BDateTimeFormat(BLocale::Default());
|
||||
fTimeFormat->SetDateTimeFormat(B_SHORT_DATE_FORMAT, B_SHORT_TIME_FORMAT, fields);
|
||||
fTimeFormat->SetDateTimeFormat(B_SHORT_DATE_FORMAT, B_SHORT_TIME_FORMAT,
|
||||
fields);
|
||||
|
||||
delete fDateFormat;
|
||||
fDateFormat = new BDateFormat(BLocale::Default());
|
||||
@@ -454,8 +463,6 @@ TTimeView::GetCurrentDate()
|
||||
void
|
||||
TTimeView::CalculateTextPlacement()
|
||||
{
|
||||
BRect bounds(Bounds());
|
||||
|
||||
fDateLocation.x = 0.0;
|
||||
fTimeLocation.x = 0.0;
|
||||
|
||||
@@ -469,7 +476,8 @@ TTimeView::CalculateTextPlacement()
|
||||
font.GetBoundingBoxesForStrings(stringArray, 1, B_SCREEN_METRIC, &delta,
|
||||
rectArray);
|
||||
|
||||
fTimeLocation.y = fDateLocation.y = ceilf((bounds.Height()
|
||||
// center vertically
|
||||
fTimeLocation.y = fDateLocation.y = ceilf((Bounds().Height()
|
||||
- rectArray[0].Height() + 1.0) / 2.0 - rectArray[0].top);
|
||||
|
||||
if (fOrientation) {
|
||||
|
||||
@@ -66,7 +66,6 @@ const uint32 kShowTimeZone = 'SwTz';
|
||||
const uint32 kGetClockSettings = 'GCkS';
|
||||
|
||||
|
||||
|
||||
class BCountry;
|
||||
class BMessageRunner;
|
||||
class CalendarMenuWindow;
|
||||
|
||||
@@ -47,7 +47,6 @@ All rights reserved.
|
||||
|
||||
|
||||
const float kVPad = 2.0f;
|
||||
const float kSwitchWidth = 12.0f;
|
||||
|
||||
|
||||
// #pragma mark - TTruncatableMenuItem
|
||||
|
||||
Reference in New Issue
Block a user