Tracker: Basic adjustments to InfoWindow to respect BControlLook.

Improves appearance under HiDPI.
This commit is contained in:
Augustin Cavalier
2022-08-26 17:32:18 -04:00
parent 0c973c9467
commit a57bf2191b
2 changed files with 40 additions and 41 deletions
+33 -29
View File
@@ -39,6 +39,7 @@ All rights reserved.
#include <Application.h>
#include <Catalog.h>
#include <ControlLook.h>
#include <Locale.h>
#include <NodeMonitor.h>
#include <PopUpMenu.h>
@@ -86,8 +87,7 @@ private:
} // namespace BPrivate
const float kBorderMargin = 15.0f;
const float kDrawMargin = 3.0f;
static float sBorderMargin, sDrawMargin = 0.0f;
const uint32 kSetPreferredApp = 'setp';
@@ -179,6 +179,10 @@ GeneralInfoView::GeneralInfoView(Model* model)
NULL
};
if (sDrawMargin == 0.0f) {
sDrawMargin = be_control_look->DefaultLabelSpacing() / 2.0f;
sBorderMargin = sDrawMargin * 5.0f;
}
SetFlags(Flags() | B_WILL_DRAW | B_PULSE_NEEDED | B_FRAME_EVENTS);
SetName(B_TRANSLATE("Information"));
@@ -200,7 +204,7 @@ GeneralInfoView::GeneralInfoView(Model* model)
float width = 0;
for (int i = 0; fieldNames[i] != 0; i++)
width = std::max(width, StringWidth(fieldNames[i]));
fDivider = width + kBorderMargin + 1;
fDivider = width + sBorderMargin + 1;
// Keep some free space for the stuff we print ourselves
float lineHeight = CurrentFontHeight();
@@ -209,7 +213,7 @@ GeneralInfoView::GeneralInfoView(Model* model)
lineCount += 1; // Add space for "Link to" line
if (model->IsExecutable())
lineCount += 2; // Add space for "Version" and "Description" lines
GroupLayout()->SetInsets(kBorderMargin, lineHeight * lineCount,
GroupLayout()->SetInsets(sBorderMargin, lineHeight * lineCount,
B_USE_WINDOW_SPACING, B_USE_WINDOW_SPACING);
// Add a preferred handler pop-up menu if this item
@@ -226,7 +230,7 @@ GeneralInfoView::GeneralInfoView(Model* model)
fDivider = currentFont.StringWidth(B_TRANSLATE("Opens with:"))
+ 5;
fPreferredAppMenu->SetDivider(fDivider);
fDivider += (kBorderMargin - 2);
fDivider += (sBorderMargin - 2);
fPreferredAppMenu->SetFont(&currentFont);
fPreferredAppMenu->SetHighUIColor(B_PANEL_TEXT_COLOR);
fPreferredAppMenu->SetLabel(B_TRANSLATE("Opens with:"));
@@ -308,9 +312,9 @@ GeneralInfoView::InitStrings(const Model* model)
// We'll do our own truncation later on in Draw()
WidgetAttributeText::AttrAsString(model, &fCreatedStr, kAttrStatCreated,
B_TIME_TYPE, drawBounds.Width() - kBorderMargin, this);
B_TIME_TYPE, drawBounds.Width() - sBorderMargin, this);
WidgetAttributeText::AttrAsString(model, &fModifiedStr, kAttrStatModified,
B_TIME_TYPE, drawBounds.Width() - kBorderMargin, this);
B_TIME_TYPE, drawBounds.Width() - sBorderMargin, this);
WidgetAttributeText::AttrAsString(model, &fPathStr, kAttrPath,
B_STRING_TYPE, 0, this);
@@ -446,10 +450,10 @@ GeneralInfoView::ModelChanged(Model* model, BMessage* message)
if (model->OpenNode() == B_OK) {
WidgetAttributeText::AttrAsString(model, &fCreatedStr,
kAttrStatCreated, B_TIME_TYPE, drawBounds.Width()
- kBorderMargin, this);
- sBorderMargin, this);
WidgetAttributeText::AttrAsString(model, &fModifiedStr,
kAttrStatModified, B_TIME_TYPE, drawBounds.Width()
- kBorderMargin, this);
- sBorderMargin, this);
// don't change the size if it's a directory
if (!model->IsDirectory()) {
@@ -581,7 +585,7 @@ GeneralInfoView::MouseMoved(BPoint where, uint32, const BMessage* dragMessage)
BFont font;
GetFont(&font);
float maxWidth = (Bounds().Width()
- (fDivider + kBorderMargin));
- (fDivider + sBorderMargin));
if (fPathRect.Contains(point)) {
if (fCurrentPathColorWhich != B_LINK_HOVER_COLOR)
@@ -838,14 +842,14 @@ GeneralInfoView::Draw(BRect)
DrawString(B_TRANSLATE("Size:"));
}
MovePenTo(BPoint(fDivider + kDrawMargin, lineBase));
MovePenTo(BPoint(fDivider + sDrawMargin, lineBase));
SetHighColor(attributeColor);
// Check for possible need of truncation
if (StringWidth(fSizeString.String())
> (Bounds().Width() - (fDivider + kBorderMargin))) {
> (Bounds().Width() - (fDivider + sBorderMargin))) {
BString tmpString(fSizeString.String());
TruncateString(&tmpString, B_TRUNCATE_MIDDLE,
Bounds().Width() - (fDivider + kBorderMargin));
Bounds().Width() - (fDivider + sBorderMargin));
DrawString(tmpString.String());
fSizeRect.right = fSizeRect.left + StringWidth(tmpString.String())
+ 3;
@@ -860,7 +864,7 @@ GeneralInfoView::Draw(BRect)
MovePenTo(BPoint(fDivider - (StringWidth(B_TRANSLATE("Created:"))),
lineBase));
DrawString(B_TRANSLATE("Created:"));
MovePenTo(BPoint(fDivider + kDrawMargin, lineBase));
MovePenTo(BPoint(fDivider + sDrawMargin, lineBase));
SetHighColor(attributeColor);
DrawString(fCreatedStr.String());
lineBase += lineHeight;
@@ -870,7 +874,7 @@ GeneralInfoView::Draw(BRect)
lineBase));
SetHighColor(labelColor);
DrawString(B_TRANSLATE("Modified:"));
MovePenTo(BPoint(fDivider + kDrawMargin, lineBase));
MovePenTo(BPoint(fDivider + sDrawMargin, lineBase));
SetHighColor(attributeColor);
DrawString(fModifiedStr.String());
lineBase += lineHeight;
@@ -880,7 +884,7 @@ GeneralInfoView::Draw(BRect)
lineBase));
SetHighColor(labelColor);
DrawString(B_TRANSLATE("Kind:"));
MovePenTo(BPoint(fDivider + kDrawMargin, lineBase));
MovePenTo(BPoint(fDivider + sDrawMargin, lineBase));
SetHighColor(attributeColor);
DrawString(fKindStr.String());
lineBase += lineHeight;
@@ -894,15 +898,15 @@ GeneralInfoView::Draw(BRect)
SetHighColor(labelColor);
DrawString(B_TRANSLATE("Location:"));
MovePenTo(BPoint(fDivider + kDrawMargin, lineBase));
MovePenTo(BPoint(fDivider + sDrawMargin, lineBase));
SetHighUIColor(fCurrentPathColorWhich);
// Check for truncation
if (StringWidth(fPathStr.String()) > (Bounds().Width()
- (fDivider + kBorderMargin))) {
- (fDivider + sBorderMargin))) {
BString nameString(fPathStr.String());
TruncateString(&nameString, B_TRUNCATE_MIDDLE,
Bounds().Width() - (fDivider + kBorderMargin));
Bounds().Width() - (fDivider + sBorderMargin));
DrawString(nameString.String());
} else
DrawString(fPathStr.String());
@@ -921,15 +925,15 @@ GeneralInfoView::Draw(BRect)
lineBase));
SetHighColor(labelColor);
DrawString(B_TRANSLATE("Link to:"));
MovePenTo(BPoint(fDivider + kDrawMargin, lineBase));
MovePenTo(BPoint(fDivider + sDrawMargin, lineBase));
SetHighUIColor(fCurrentLinkColorWhich);
// Check for truncation
if (StringWidth(fLinkToStr.String()) > (Bounds().Width()
- (fDivider + kBorderMargin))) {
- (fDivider + sBorderMargin))) {
BString nameString(fLinkToStr.String());
TruncateString(&nameString, B_TRUNCATE_MIDDLE,
Bounds().Width() - (fDivider + kBorderMargin));
Bounds().Width() - (fDivider + sBorderMargin));
DrawString(nameString.String());
} else
DrawString(fLinkToStr.String());
@@ -949,7 +953,7 @@ GeneralInfoView::Draw(BRect)
lineBase));
SetHighColor(labelColor);
DrawString(B_TRANSLATE("Version:"));
MovePenTo(BPoint(fDivider + kDrawMargin, lineBase));
MovePenTo(BPoint(fDivider + sDrawMargin, lineBase));
SetHighColor(attributeColor);
BString nameString;
if (fModel->GetVersionString(nameString, B_APP_VERSION_KIND) == B_OK)
@@ -963,14 +967,14 @@ GeneralInfoView::Draw(BRect)
lineBase));
SetHighColor(labelColor);
DrawString(B_TRANSLATE("Description:"));
MovePenTo(BPoint(fDivider + kDrawMargin, lineBase));
MovePenTo(BPoint(fDivider + sDrawMargin, lineBase));
SetHighColor(attributeColor);
// Check for truncation
if (StringWidth(fDescStr.String()) > (Bounds().Width()
- (fDivider + kBorderMargin))) {
- (fDivider + sBorderMargin))) {
BString nameString(fDescStr.String());
TruncateString(&nameString, B_TRUNCATE_MIDDLE,
Bounds().Width() - (fDivider + kBorderMargin));
Bounds().Width() - (fDivider + sBorderMargin));
DrawString(nameString.String());
} else
DrawString(fDescStr.String());
@@ -989,14 +993,14 @@ GeneralInfoView::Draw(BRect)
lineBase));
SetHighColor(labelColor);
DrawString(B_TRANSLATE("Filesystem:"));
MovePenTo(BPoint(fDivider + kDrawMargin, lineBase));
MovePenTo(BPoint(fDivider + sDrawMargin, lineBase));
SetHighColor(attributeColor);
// Check for truncation
if (StringWidth(fFileSystemStr.String()) > (Bounds().Width()
- (fDivider + kBorderMargin))) {
- (fDivider + sBorderMargin))) {
BString nameString(fFileSystemStr.String());
TruncateString(&nameString, B_TRUNCATE_MIDDLE,
Bounds().Width() - (fDivider + kBorderMargin));
Bounds().Width() - (fDivider + sBorderMargin));
DrawString(nameString.String());
} else
DrawString(fFileSystemStr.String());
+7 -12
View File
@@ -38,6 +38,7 @@ All rights reserved.
#include <Alert.h>
#include <Application.h>
#include <Catalog.h>
#include <ControlLook.h>
#include <Locale.h>
#include <PopUpMenu.h>
#include <ScrollView.h>
@@ -59,11 +60,6 @@ All rights reserved.
#define B_TRANSLATION_CONTEXT "InfoWindow"
// Offsets taken from TAlertView::Draw in BAlert.cpp
const float kIconHorizOffset = 18.0f;
const float kIconVertOffset = 6.0f;
const float kBorderWidth = 32.0f;
// Amount you have to move the mouse before a drag starts
const float kDragSlop = 3.0f;
@@ -80,11 +76,10 @@ HeaderView::HeaderView(Model* model)
fDoubleClick(false),
fDragging(false)
{
// Create the rect for displaying the icon
fIconRect.Set(0, 0, B_LARGE_ICON - 1, B_LARGE_ICON - 1);
// Offset taken from BAlert
fIconRect.OffsetBy(kIconHorizOffset, kIconVertOffset);
SetExplicitSize(BSize(B_SIZE_UNSET, B_LARGE_ICON + 2 * kIconVertOffset));
const float labelSpacing = be_control_look->DefaultLabelSpacing();
fIconRect = BRect(BPoint(labelSpacing * 3.0f, labelSpacing),
be_control_look->ComposeIconSize(B_LARGE_ICON));
SetExplicitSize(BSize(B_SIZE_UNSET, fIconRect.Width() + 2 * fIconRect.top));
// The title rect
// The magic numbers are used to properly calculate the rect so that
@@ -95,12 +90,12 @@ HeaderView::HeaderView(Model* model)
GetFont(&currentFont);
currentFont.GetHeight(&fontMetrics);
fTitleRect.left = fIconRect.right + 5;
fTitleRect.left = fIconRect.right + labelSpacing;
fTitleRect.top = 0;
fTitleRect.bottom = fontMetrics.ascent + 1;
fTitleRect.right = min_c(
fTitleRect.left + currentFont.StringWidth(fModel->Name()),
Bounds().Width() - 5);
Bounds().Width() - labelSpacing);
// Offset so that it centers with the icon
fTitleRect.OffsetBy(0,
fIconRect.top + ((fIconRect.Height() - fTitleRect.Height()) / 2));