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