Skip to content

Commit

Permalink
HaikuDepot: A round of bug fixes gets the TextView working
Browse files Browse the repository at this point in the history
  • Loading branch information
stippi committed Aug 14, 2013
1 parent 0f71004 commit 139bc0d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
18 changes: 14 additions & 4 deletions src/apps/haiku-depot/textview/TextLayout.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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));
}
}
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/apps/haiku-depot/textview/TextLayout.h
Expand Up @@ -42,6 +42,10 @@ class TextLayout : public BReferenceable {
float LineInset() const
{ return fLineInset; }

void SetLineSpacing(float spacing);
float LineSpacing() const
{ return fLineSpacing; }

void SetWidth(float width);
float Width() const
{ return fWidth; }
Expand Down
22 changes: 19 additions & 3 deletions src/apps/haiku-depot/textview/TextView.cpp
Expand Up @@ -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));
}


Expand All @@ -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)
{
Expand All @@ -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);
}


Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/apps/haiku-depot/textview/TextView.h
Expand Up @@ -18,6 +18,7 @@ class TextView : public BView {

virtual void Draw(BRect updateRect);

virtual void AttachedToWindow();
virtual void FrameResized(float width, float height);

virtual BSize MinSize();
Expand Down

0 comments on commit 139bc0d

Please sign in to comment.