BTabView: Move first tab over by B_WINDOW_SPACING

BTabView::DrawTabs() got a makeover:
Draw the tab background across the whole view, then draw the tabs,
finally draw the rightmost tab's right border.
This commit is contained in:
John Scipione
2016-03-10 18:14:58 -08:00
parent 31c8f7b193
commit a0ea818b3f
+29 -35
View File
@@ -801,49 +801,41 @@ BTabView::Draw(BRect updateRect)
BRect BRect
BTabView::DrawTabs() BTabView::DrawTabs()
{ {
float left = 0; // draw an inactive tab frame behind all tabs
BRect frame(Bounds());
frame.bottom = fTabHeight;
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
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;
} else
borders |= BControlLook::B_LEFT_BORDER | BControlLook::B_RIGHT_BORDER;
for (int32 i = 0; i < CountTabs(); i++) { be_control_look->DrawInactiveTab(this, frame, frame, base, 0, borders);
// draw the tabs on top of the inactive tab frame
float right = 0.0f;
int32 tabCount = CountTabs();
for (int32 i = 0; i < tabCount; i++) {
BRect tabFrame = TabFrame(i); BRect tabFrame = TabFrame(i);
TabAt(i)->DrawTab(this, tabFrame, TabAt(i)->DrawTab(this, tabFrame,
i == fSelection ? B_TAB_FRONT : (i == 0) ? B_TAB_FIRST : B_TAB_ANY, i == fSelection ? B_TAB_FRONT : (i == 0) ? B_TAB_FIRST : B_TAB_ANY,
i + 1 != fSelection); i + 1 != fSelection);
left = tabFrame.right; right = tabFrame.right;
} }
BRect frame(Bounds()); if (tabCount > 1 && right < frame.right) {
if (fBorderStyle == B_PLAIN_BORDER) // draw a 1px right border on the last tab
frame.right += 1;
else if (fBorderStyle == B_NO_BORDER)
frame.right += 2;
if (left < frame.right) {
frame.left = left;
frame.bottom = fTabHeight;
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
uint32 borders = BControlLook::B_TOP_BORDER
| BControlLook::B_BOTTOM_BORDER | BControlLook::B_RIGHT_BORDER;
if (left == 0)
borders |= BControlLook::B_LEFT_BORDER;
be_control_look->DrawInactiveTab(this, frame, frame, base, 0,
borders);
}
if (fBorderStyle == B_NO_BORDER) {
// Draw a small inactive area before first tab.
frame = Bounds(); frame = Bounds();
frame.right = 0.0f; frame.left = frame.right = right;
// one pixel wide
frame.bottom = fTabHeight; frame.bottom = fTabHeight;
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
uint32 borders = BControlLook::B_TOP_BORDER
| BControlLook::B_BOTTOM_BORDER;
be_control_look->DrawInactiveTab(this, frame, frame, base, 0, be_control_look->DrawInactiveTab(this, frame, frame, base, 0,
borders); BControlLook::B_TOP_BORDER | BControlLook::B_BOTTOM_BORDER);
} }
if (fSelection < CountTabs()) return fSelection < CountTabs() ? TabFrame(fSelection) : BRect();
return TabFrame(fSelection);
return BRect();
} }
@@ -875,6 +867,8 @@ BTabView::TabFrame(int32 index) const
float width = 100.0f; float width = 100.0f;
float height = fTabHeight; float height = fTabHeight;
float borderOffset = 0.0f; float borderOffset = 0.0f;
float offset = BControlLook::ComposeSpacing(B_USE_WINDOW_SPACING);
// Do not use 2.0f for B_NO_BORDER, that will look yet different // Do not use 2.0f for B_NO_BORDER, that will look yet different
// again (handled in DrawTabs()). // again (handled in DrawTabs()).
if (fBorderStyle == B_PLAIN_BORDER) if (fBorderStyle == B_PLAIN_BORDER)
@@ -888,8 +882,8 @@ BTabView::TabFrame(int32 index) const
x += StringWidth(TabAt(i)->Label()) + 20.0f; x += StringWidth(TabAt(i)->Label()) + 20.0f;
} }
return BRect(x - borderOffset, 0.0f, return BRect(offset + x - borderOffset, 0.0f,
x + StringWidth(TabAt(index)->Label()) + 20.0f offset + x + StringWidth(TabAt(index)->Label()) + 20.0f
- borderOffset, - borderOffset,
height); height);
} }
@@ -905,8 +899,8 @@ BTabView::TabFrame(int32 index) const
case B_WIDTH_AS_USUAL: case B_WIDTH_AS_USUAL:
default: default:
return BRect(index * width - borderOffset, 0.0f, return BRect(offset + index * width - borderOffset, 0.0f,
index * width + width - borderOffset, height); offset + index * width + width - borderOffset, height);
} }
// TODO: fix to remove "offset" in DrawTab and DrawLabel ... // TODO: fix to remove "offset" in DrawTab and DrawLabel ...