HaikuDepot: A round of bug fixes gets the TextView working
This commit is contained in:
parent
0f71004390
commit
139bc0df15
@ -217,7 +217,7 @@ TextLayout::SetText(const BString& text)
|
||||
void
|
||||
TextLayout::SetFont(const BFont& font)
|
||||
{
|
||||
if (fDefaultFont != font) {
|
||||
if (fDefaultFont != font || fAscent == 0.0f) {
|
||||
fDefaultFont = font;
|
||||
|
||||
font_height fontHeight;
|
||||
@ -261,6 +261,16 @@ TextLayout::SetLineInset(float inset)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TextLayout::SetLineSpacing(float spacing)
|
||||
{
|
||||
if (fLineSpacing != spacing) {
|
||||
fLineSpacing = spacing;
|
||||
fLayoutValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TextLayout::SetWidth(float width)
|
||||
{
|
||||
@ -313,7 +323,9 @@ TextLayout::Draw(BView* view, const BPoint& offset)
|
||||
fText.CopyCharsInto(string, startOffset, endOffset - startOffset);
|
||||
|
||||
float x = fGlyphInfoBuffer[startOffset].x;
|
||||
float y = fGlyphInfoBuffer[startOffset].y + line.maxAscent;
|
||||
float y = fGlyphInfoBuffer[startOffset].y;
|
||||
|
||||
//printf("%p->%.1f,%.1f: '%s'\n", this, x, y, string.String());
|
||||
view->DrawString(string, BPoint(x, y));
|
||||
}
|
||||
}
|
||||
@ -510,8 +522,6 @@ void
|
||||
TextLayout::_FinalizeLine(int lineStart, int lineEnd, int lineIndex, float y,
|
||||
float& lineHeight)
|
||||
{
|
||||
printf("_FinalizeLine(%d, %d, %d, %.1f)\n", lineStart, lineEnd, lineIndex,
|
||||
y);
|
||||
lineHeight = 0.0f;
|
||||
float maxAscent = 0.0f;
|
||||
float maxDescent = 0.0f;
|
||||
|
@ -42,6 +42,10 @@ public:
|
||||
float LineInset() const
|
||||
{ return fLineInset; }
|
||||
|
||||
void SetLineSpacing(float spacing);
|
||||
float LineSpacing() const
|
||||
{ return fLineSpacing; }
|
||||
|
||||
void SetWidth(float width);
|
||||
float Width() const
|
||||
{ return fWidth; }
|
||||
|
@ -8,8 +8,13 @@
|
||||
|
||||
TextView::TextView(const char* name)
|
||||
:
|
||||
BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE)
|
||||
BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS)
|
||||
{
|
||||
fTextLayout.SetWidth(Bounds().Width());
|
||||
fTextLayout.SetLineSpacing(ceilf(fTextLayout.Font().Size() * 0.2));
|
||||
|
||||
SetViewColor(B_TRANSPARENT_COLOR);
|
||||
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
}
|
||||
|
||||
|
||||
@ -22,10 +27,21 @@ void
|
||||
TextView::Draw(BRect updateRect)
|
||||
{
|
||||
FillRect(updateRect, B_SOLID_LOW);
|
||||
|
||||
fTextLayout.SetWidth(Bounds().Width());
|
||||
fTextLayout.Draw(this, B_ORIGIN);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TextView::AttachedToWindow()
|
||||
{
|
||||
BView* parent = Parent();
|
||||
if (parent != NULL)
|
||||
SetLowColor(parent->ViewColor());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TextView::FrameResized(float width, float height)
|
||||
{
|
||||
@ -36,7 +52,7 @@ TextView::FrameResized(float width, float height)
|
||||
BSize
|
||||
TextView::MinSize()
|
||||
{
|
||||
return BSize(0.0f, 0.0f);
|
||||
return BSize(50.0f, 0.0f);
|
||||
}
|
||||
|
||||
|
||||
@ -68,7 +84,7 @@ TextView::GetHeightForWidth(float width, float* min, float* max,
|
||||
TextLayout layout(fTextLayout);
|
||||
layout.SetWidth(width);
|
||||
|
||||
float height = layout.Height();
|
||||
float height = layout.Height() + 1;
|
||||
|
||||
if (min != NULL)
|
||||
*min = height;
|
||||
|
@ -18,6 +18,7 @@ public:
|
||||
|
||||
virtual void Draw(BRect updateRect);
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
virtual void FrameResized(float width, float height);
|
||||
|
||||
virtual BSize MinSize();
|
||||
|
Loading…
x
Reference in New Issue
Block a user