BTabView: Draw bottom tab border in DrawTabs()
...instead of DrawBox(). Also use ceilf when calculating tab height to prevent non-integral height. Fixes #12683 More Todo: You have to understand way too much about how this class draws if you want to have any hope of overriding one of its Draw... methods and have it do what you expect. e.g. The BeBook implies that the tabs are drawn first, then the box, but, we draw them in the opposite order. Probably better this way but not intuitive. There are a number of remaining questions: 1. Why don't we need to draw the bottom of tabs if B_FANCY_BORDER? 2. Why do we need to expand tab border horizontally if B_PLAIN_BORDER? 3. Why is the bottom border color (152, 152, 152) instead of (151, 151, 151)? Add a bunch of TODOs for these questions and more. There can be some unitiutive gaps between the box border and view depending on if you choose B_FANCY_BORDER or B_PLAIN_BORDER. You don't notice the gaps unless the view draws right on it's edge. Some views, including in Devices and Media Prefs do this though. Media Prefs further complicates matters by overriding BTabView.
This commit is contained in:
parent
76b2ce77bf
commit
65d0cbfdaf
@ -15,6 +15,8 @@
|
||||
#include <TabViewPrivate.h>
|
||||
|
||||
#include <new>
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CardLayout.h>
|
||||
@ -354,7 +356,7 @@ BTabView::BTabView(BMessage* archive)
|
||||
if (archive->FindFloat("_high", &fTabHeight) != B_OK) {
|
||||
font_height fh;
|
||||
GetFontHeight(&fh);
|
||||
fTabHeight = fh.ascent + fh.descent + fh.leading + 8.0f;
|
||||
fTabHeight = ceilf(fh.ascent + fh.descent + fh.leading + 8.0f);
|
||||
}
|
||||
|
||||
if (archive->FindInt32("_sel", &fSelection) != B_OK)
|
||||
@ -798,40 +800,75 @@ BTabView::Draw(BRect updateRect)
|
||||
BRect
|
||||
BTabView::DrawTabs()
|
||||
{
|
||||
// TODO: Rewrite this method
|
||||
|
||||
// draw an inactive tab frame behind all tabs
|
||||
BRect frame(Bounds());
|
||||
frame.bottom = fTabHeight;
|
||||
BRect bounds(Bounds());
|
||||
bounds.bottom = fTabHeight;
|
||||
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
|
||||
uint32 borders = BControlLook::B_TOP_BORDER
|
||||
| BControlLook::B_BOTTOM_BORDER;
|
||||
uint32 borders = BControlLook::B_TOP_BORDER | BControlLook::B_BOTTOM_BORDER;
|
||||
if (fBorderStyle == B_NO_BORDER) {
|
||||
// removes left border that is an artifact of DrawInactiveTab()
|
||||
frame.left -= 1.0f;
|
||||
bounds.left -= 1;
|
||||
} else
|
||||
borders |= BControlLook::B_LEFT_BORDER | BControlLook::B_RIGHT_BORDER;
|
||||
|
||||
be_control_look->DrawInactiveTab(this, frame, frame, base, 0, borders);
|
||||
// TODO: Why do we have to do this?
|
||||
if (fBorderStyle == B_PLAIN_BORDER) {
|
||||
bounds.left -= 1;
|
||||
bounds.right += 1;
|
||||
}
|
||||
|
||||
// draw the tabs on top of the inactive tab frame
|
||||
// TODO: Doesn't draw bottom border, why?
|
||||
be_control_look->DrawInactiveTab(this, bounds, bounds, base, 0, borders);
|
||||
|
||||
// draw the tabs on top of the inactive tab bounds
|
||||
float right = 0.0f;
|
||||
BRect activeTabFrame;
|
||||
int32 tabCount = CountTabs();
|
||||
for (int32 i = 0; i < tabCount; i++) {
|
||||
BRect tabFrame = TabFrame(i);
|
||||
if (i == fSelection)
|
||||
activeTabFrame = tabFrame;
|
||||
|
||||
TabAt(i)->DrawTab(this, tabFrame,
|
||||
i == fSelection ? B_TAB_FRONT : (i == 0) ? B_TAB_FIRST : B_TAB_ANY,
|
||||
i + 1 != fSelection);
|
||||
right = tabFrame.right;
|
||||
}
|
||||
|
||||
if (right < frame.right) {
|
||||
if (right < bounds.right) {
|
||||
// draw a 1px right border on the last tab
|
||||
frame = Bounds();
|
||||
frame.left = frame.right = right;
|
||||
frame.bottom = fTabHeight;
|
||||
be_control_look->DrawInactiveTab(this, frame, frame, base, 0,
|
||||
bounds = Bounds();
|
||||
bounds.left = bounds.right = right;
|
||||
bounds.bottom = fTabHeight;
|
||||
borders = BControlLook::B_TOP_BORDER;
|
||||
be_control_look->DrawInactiveTab(this, bounds, bounds, base, 0,
|
||||
BControlLook::B_TOP_BORDER | BControlLook::B_BOTTOM_BORDER);
|
||||
}
|
||||
|
||||
// TODO: Why do we have to do this?
|
||||
// TODO: Why don't we have to do this for B_FANCY_BORDER?
|
||||
// TODO: Why does this draw the wrong color (152 instead of 151)
|
||||
if (fBorderStyle != B_FANCY_BORDER) {
|
||||
// draw the bottom border of the tabs
|
||||
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
|
||||
|
||||
// draw the bottom border left of the active tab
|
||||
bounds = Bounds();
|
||||
bounds.top = bounds.bottom = fTabHeight;
|
||||
bounds.right = activeTabFrame.left;
|
||||
be_control_look->DrawBorder(this, bounds, bounds, base, B_PLAIN_BORDER,
|
||||
0, BControlLook::B_TOP_BORDER | BControlLook::B_BOTTOM_BORDER);
|
||||
|
||||
// draw the bottom border right of the active tab
|
||||
bounds = Bounds();
|
||||
bounds.top = bounds.bottom = fTabHeight;
|
||||
bounds.left = activeTabFrame.right;
|
||||
be_control_look->DrawBorder(this, bounds, bounds, base, B_PLAIN_BORDER,
|
||||
0, BControlLook::B_TOP_BORDER | BControlLook::B_BOTTOM_BORDER);
|
||||
}
|
||||
|
||||
return fSelection < CountTabs() ? TabFrame(fSelection) : BRect();
|
||||
}
|
||||
|
||||
@ -840,18 +877,16 @@ void
|
||||
BTabView::DrawBox(BRect selectedTabRect)
|
||||
{
|
||||
BRect rect(Bounds());
|
||||
rect.top = selectedTabRect.bottom;
|
||||
if (fBorderStyle != B_FANCY_BORDER)
|
||||
rect.top += 1.0f;
|
||||
rect.top = fTabHeight;
|
||||
|
||||
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
|
||||
if (fBorderStyle == B_FANCY_BORDER)
|
||||
be_control_look->DrawGroupFrame(this, rect, rect, base);
|
||||
else {
|
||||
else if (fBorderStyle == B_PLAIN_BORDER) {
|
||||
be_control_look->DrawBorder(this, rect, rect, base, B_PLAIN_BORDER,
|
||||
0, fBorderStyle == B_PLAIN_BORDER ? BControlLook::B_ALL_BORDERS
|
||||
: BControlLook::B_TOP_BORDER);
|
||||
}
|
||||
0, BControlLook::B_ALL_BORDERS);
|
||||
} else
|
||||
; // B_NO_BORDER draws no box
|
||||
}
|
||||
|
||||
|
||||
@ -1215,7 +1250,7 @@ BTabView::_InitObject(bool layouted, button_width width)
|
||||
|
||||
font_height fh;
|
||||
GetFontHeight(&fh);
|
||||
fTabHeight = fh.ascent + fh.descent + fh.leading + 8.0f;
|
||||
fTabHeight = ceilf(fh.ascent + fh.descent + fh.leading + 8.0f);
|
||||
|
||||
fContainerView = NULL;
|
||||
_InitContainerView(layouted);
|
||||
|
Loading…
x
Reference in New Issue
Block a user