Second part of a patch sent by Clemens zeidler:

* If in B_WIDTH_AS_USUAL mode, the strings in the tabs are nevertheless
  truncated to the available width.
* Pass the real area available for the string to BTab::DrawLabel(), resolved
  TODO in DrawLabel() about not having to calculate an offset to account
  for the slope.
* Fixed some too lines of code.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23869 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2008-02-05 08:07:21 +00:00
parent 00f378126a
commit 753fd45fc2
+50 -28
View File
@@ -6,14 +6,15 @@
* Marc Flerackers ([email protected]) * Marc Flerackers ([email protected])
* Jérôme Duval ([email protected]) * Jérôme Duval ([email protected])
*/ */
#include <TabView.h>
#include <string.h>
#include <List.h> #include <List.h>
#include <Message.h> #include <Message.h>
#include <PropertyInfo.h> #include <PropertyInfo.h>
#include <Rect.h> #include <Rect.h>
#include <TabView.h> #include <String.h>
//#include <Errors.h>
#include <string.h>
static property_info sPropertyList[] = { static property_info sPropertyList[] = {
@@ -204,24 +205,39 @@ BTab::DrawFocusMark(BView *owner, BRect frame)
owner->SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); owner->SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
// TODO: remove offset // TODO: remove offset
float offset = frame.Height() / 2.0; float offset = frame.Height() / 2.0;
owner->StrokeLine(BPoint((frame.left + frame.right - width + offset) / 2.0, frame.bottom - 3), owner->StrokeLine(BPoint((frame.left + frame.right - width + offset) / 2.0,
BPoint((frame.left + frame.right + width + offset) / 2.0, frame.bottom - 3)); frame.bottom - 3),
BPoint((frame.left + frame.right + width + offset) / 2.0,
frame.bottom - 3));
} }
void void
BTab::DrawLabel(BView *owner, BRect frame) BTab::DrawLabel(BView *owner, BRect frame)
{ {
const char *label = Label(); if (Label() == NULL)
if (label == NULL)
return; return;
BString label = Label();
float frameWidth = frame.Width();
float width = owner->StringWidth(label.String());
font_height fh;
if (width > frameWidth) {
BFont font;
owner->GetFont(&font);
font.TruncateString(&label, B_TRUNCATE_END, frameWidth);
width = frameWidth;
font.GetHeight(&fh);
} else {
owner->GetFontHeight(&fh);
}
owner->SetHighColor(ui_color(B_CONTROL_TEXT_COLOR)); owner->SetHighColor(ui_color(B_CONTROL_TEXT_COLOR));
float width = owner->StringWidth(label); owner->DrawString(label.String(),
// TODO: remove offset BPoint((frame.left + frame.right - width) / 2.0,
float offset = frame.Height() / 2.0; (frame.top + frame.bottom - fh.ascent - fh.descent) / 2.0
owner->DrawString(label, BPoint((frame.left + frame.right - width + offset) / 2.0, + fh.ascent));
frame.bottom - 4.0f - 2.0f));
} }
@@ -237,7 +253,11 @@ BTab::DrawTab(BView *owner, BRect frame, tab_position position, bool full)
owner->SetHighColor(darkenmax); owner->SetHighColor(darkenmax);
owner->SetLowColor(no_tint); owner->SetLowColor(no_tint);
DrawLabel(owner, frame); // NOTE: "frame" goes from the beginning of the left slope to the beginning
// of the right slope - "lableFrame" is the frame between both slopes
BRect lableFrame = frame;
lableFrame.left = lableFrame.left + frame.Height() / 2.0;
DrawLabel(owner, lableFrame);
owner->SetDrawingMode(B_OP_OVER); owner->SetDrawingMode(B_OP_OVER);
@@ -248,37 +268,39 @@ BTab::DrawTab(BView *owner, BRect frame, tab_position position, bool full)
if (position != B_TAB_ANY) { if (position != B_TAB_ANY) {
// full height left side // full height left side
owner->AddLine(BPoint(frame.left, frame.bottom), owner->AddLine(BPoint(frame.left, frame.bottom),
BPoint(frame.left + slopeWidth, frame.top), darken3); BPoint(frame.left + slopeWidth, frame.top), darken3);
owner->AddLine(BPoint(frame.left, frame.bottom + 1), owner->AddLine(BPoint(frame.left, frame.bottom + 1),
BPoint(frame.left + slopeWidth, frame.top + 1), lightenmax); BPoint(frame.left + slopeWidth, frame.top + 1), lightenmax);
} else { } else {
// upper half of left side // upper half of left side
owner->AddLine(BPoint(frame.left + slopeWidth / 2, frame.bottom - slopeWidth), owner->AddLine(BPoint(frame.left + slopeWidth / 2,
BPoint(frame.left + slopeWidth, frame.top), darken3); frame.bottom - slopeWidth),
owner->AddLine(BPoint(frame.left + slopeWidth / 2 + 2, frame.bottom - slopeWidth - 1), BPoint(frame.left + slopeWidth, frame.top), darken3);
BPoint(frame.left + slopeWidth, frame.top + 1), lightenmax); owner->AddLine(BPoint(frame.left + slopeWidth / 2 + 2,
frame.bottom - slopeWidth - 1),
BPoint(frame.left + slopeWidth, frame.top + 1), lightenmax);
} }
// lines along the top // lines along the top
owner->AddLine(BPoint(frame.left + slopeWidth, frame.top), owner->AddLine(BPoint(frame.left + slopeWidth, frame.top),
BPoint(frame.right, frame.top), darken3); BPoint(frame.right, frame.top), darken3);
owner->AddLine(BPoint(frame.left + slopeWidth, frame.top + 1), owner->AddLine(BPoint(frame.left + slopeWidth, frame.top + 1),
BPoint(frame.right, frame.top + 1), lightenmax); BPoint(frame.right, frame.top + 1), lightenmax);
if (full) { if (full) {
// full height right side // full height right side
owner->AddLine(BPoint(frame.right, frame.top), owner->AddLine(BPoint(frame.right, frame.top),
BPoint(frame.right + slopeWidth + 2, frame.bottom), darken2); BPoint(frame.right + slopeWidth + 2, frame.bottom), darken2);
owner->AddLine(BPoint(frame.right, frame.top + 1), owner->AddLine(BPoint(frame.right, frame.top + 1),
BPoint(frame.right + slopeWidth + 1, frame.bottom), darken4); BPoint(frame.right + slopeWidth + 1, frame.bottom), darken4);
} else { } else {
// upper half of right side // upper half of right side
owner->AddLine(BPoint(frame.right, frame.top), owner->AddLine(BPoint(frame.right, frame.top),
BPoint(frame.right + slopeWidth / 2 + 1, BPoint(frame.right + slopeWidth / 2 + 1,
frame.bottom - slopeWidth), darken2); frame.bottom - slopeWidth), darken2);
owner->AddLine(BPoint(frame.right, frame.top + 1), owner->AddLine(BPoint(frame.right, frame.top + 1),
BPoint(frame.right + slopeWidth / 2, BPoint(frame.right + slopeWidth / 2,
frame.bottom - slopeWidth), darken4); frame.bottom - slopeWidth), darken4);
} }
owner->EndLineArray(); owner->EndLineArray();