ProcessController: fix bars height computation

The previous code used a fixed margin, which would lead to too small
bars with small font sizes (the bar content would not even be visible).

Instead, use the font height as the base for the bar height, which
allows us to use the same code everywhere, no matter the menu item
height (which can vary depending on if there is an icon, etc)

Fixes #15391.
This commit is contained in:
Adrien Destugues 2019-11-24 13:07:30 +01:00
parent 5de2f989bc
commit 32bc3e2c0f
8 changed files with 47 additions and 20 deletions

View File

@ -72,10 +72,11 @@ KernelMemoryBarMenuItem::DrawBar(bool force)
BMenu* menu = Menu();
rgb_color highColor = menu->HighColor();
// draw the bar itself
BRect cadre (frame.right - kMargin - kBarWidth, frame.top + kBarPadding,
frame.right - kMargin, frame.bottom - kBarPadding);
BFont font;
menu->GetFont(&font);
BRect cadre = bar_rect(frame, &font);
// draw the bar itself
if (fLastSum < 0)
force = true;
if (force) {

View File

@ -116,10 +116,11 @@ MemoryBarMenuItem::DrawBar(bool force)
BMenu* menu = Menu();
rgb_color highColor = menu->HighColor();
// draw the bar itself
BFont font;
menu->GetFont(&font);
BRect rect = bar_rect(frame, &font);
BRect rect(frame.right - kMargin - kBarWidth, frame.top + kBarPadding,
frame.right - kMargin, frame.bottom - kBarPadding);
// draw the bar itself
if (fWriteMemory < 0)
return;

View File

@ -22,6 +22,7 @@
#include "Catalog.h"
#include "Colors.h"
#include "ProcessController.h"
#include "Utilities.h"
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "ProcessController"
@ -52,10 +53,11 @@ NoiseBarMenuItem::DrawBar(bool force)
BRect frame = Frame();
BMenu* menu = Menu();
rgb_color highColor = menu->HighColor();
frame.right -= 24;
frame.left = frame.right - kBarWidth;
frame.top += kBarPadding;
frame.bottom -= kBarPadding;
BFont font;
menu->GetFont(&font);
frame = bar_rect(frame, &font);
if (fBusyWaiting < 0)
return;

View File

@ -92,6 +92,5 @@ extern bool gInDeskbar;
#define kBarWidth 100
#define kMargin 12
#define kBarPadding 7
#endif // _PCVIEW_H_

View File

@ -24,6 +24,7 @@
#include "ProcessController.h"
#include "ThreadBarMenu.h"
#include "ThreadBarMenuItem.h"
#include "Utilities.h"
#include <Bitmap.h>
@ -124,10 +125,10 @@ TeamBarMenuItem::DrawBar(bool force)
BRect frame = Frame();
BMenu* menu = Menu ();
rgb_color highColor = menu->HighColor();
frame.right -= 24;
frame.left = frame.right-kBarWidth;
frame.top += kBarPadding;
frame.bottom -= kBarPadding;
BFont font;
menu->GetFont(&font);
frame = bar_rect(frame, &font);
if (fKernel < 0)
return;

View File

@ -22,6 +22,7 @@
#include "Colors.h"
#include "PriorityMenu.h"
#include "ProcessController.h"
#include "Utilities.h"
#include <stdio.h>
@ -57,10 +58,11 @@ ThreadBarMenuItem::DrawBar(bool force)
BRect frame = Frame();
BMenu* menu = Menu();
rgb_color highColor = menu->HighColor();
frame.right -= 24;
frame.left = frame.right - kBarWidth;
frame.top += kBarPadding;
frame.bottom -= kBarPadding;
BFont font;
menu->GetFont(&font);
frame = bar_rect(frame, &font);
if (fKernel < 0)
return;

View File

@ -176,3 +176,20 @@ make_window_visible(BWindow* window, bool mayResize)
window->MoveBy(0, screen.top-frame.top);
}
BRect
bar_rect(BRect& frame, BFont* font)
{
BRect rect(frame);
font_height metrics;
font->GetHeight(&metrics);
float barHeight = metrics.ascent;
rect.top = frame.top + (frame.Height() - barHeight) / 2;
rect.bottom = frame.top + (frame.Height() + barHeight) / 2;
rect.left = frame.right - kMargin - kBarWidth;
rect.right = frame.right - kMargin;
return rect;
}

View File

@ -20,8 +20,10 @@
#define UTILITIES_H
#include <OS.h>
#include <Font.h>
#include <GraphicsDefs.h>
#include <Rect.h>
#include <OS.h>
class BDeskbar;
@ -43,6 +45,8 @@ void find_self(entry_ref& ref);
void move_to_deskbar(BDeskbar& deskbar);
void make_window_visible(BWindow* window, bool mayResize = false);
BRect bar_rect(BRect& frame, BFont* font);
extern const uchar k_cpu_mini[];
#endif // UTILITIES_H