2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
7 #include "TableCellValueRendererUtils.h"
14 static const float kTextMargin
= 8;
18 TableCellValueRendererUtils::DrawString(BView
* view
, BRect rect
,
19 const char* string
, bool valueChanged
, enum alignment alignment
,
22 // get font height info
23 font_height fontHeight
;
24 view
->GetFontHeight(&fontHeight
);
26 // truncate, if requested
27 BString truncatedString
;
29 truncatedString
= string
;
30 view
->TruncateString(&truncatedString
, B_TRUNCATE_END
,
31 rect
.Width() - 2 * kTextMargin
+ 2);
32 string
= truncatedString
.String();
35 // compute horizontal position according to alignment
40 x
= rect
.left
+ kTextMargin
;
44 x
= rect
.left
+ (rect
.Width() - view
->StringWidth(string
)) / 2;
48 x
= rect
.right
- kTextMargin
- view
->StringWidth(string
);
52 // compute vertical position (base line)
54 + (rect
.Height() - (fontHeight
.ascent
+ fontHeight
.descent
55 + fontHeight
.leading
)) / 2
56 + (fontHeight
.ascent
+ fontHeight
.descent
) - 2;
57 // TODO: This is the computation BColumnListView (respectively
58 // BTitledColumn) is using, which I find somewhat weird.
62 view
->SetHighColor((rgb_color
){255, 0, 0, 255});
65 view
->DrawString(string
, BPoint(x
, y
));
73 TableCellValueRendererUtils::PreferredStringWidth(BView
* view
,
76 return view
->StringWidth(string
) + 2 * kTextMargin
;