HaikuDepot: Switched TextView to use new ParagraphLayout

* The ParagraphStyle can be set as well.
This commit is contained in:
Stephan Aßmus 2013-09-06 10:02:33 +02:00
parent 822872d6c3
commit 8d0c791d5f
2 changed files with 32 additions and 7 deletions

View File

@ -10,11 +10,16 @@ TextView::TextView(const char* name)
: :
BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS) 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); SetViewColor(B_TRANSPARENT_COLOR);
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
BFont font;
GetFont(&font);
ParagraphStyle style;
style.SetLineSpacing(ceilf(font.Size() * 0.2));
SetParagraphStyle(style);
} }
@ -81,7 +86,7 @@ void
TextView::GetHeightForWidth(float width, float* min, float* max, TextView::GetHeightForWidth(float width, float* min, float* max,
float* preferred) float* preferred)
{ {
TextLayout layout(fTextLayout); ParagraphLayout layout(fTextLayout);
layout.SetWidth(width); layout.SetWidth(width);
float height = layout.Height() + 1; float height = layout.Height() + 1;
@ -98,6 +103,23 @@ TextView::GetHeightForWidth(float width, float* min, float* max,
void void
TextView::SetText(const BString& text) TextView::SetText(const BString& text)
{ {
fTextLayout.SetText(text); fText.Clear();
CharacterStyle regularStyle;
fText.Append(TextSpan(text, regularStyle));
fTextLayout.SetParagraph(fText);
InvalidateLayout();
}
void
TextView::SetParagraphStyle(const ParagraphStyle& style)
{
fText.SetStyle(style);
fTextLayout.SetParagraph(fText);
InvalidateLayout();
} }

View File

@ -8,7 +8,8 @@
#include <String.h> #include <String.h>
#include <View.h> #include <View.h>
#include "TextLayout.h" #include "Paragraph.h"
#include "ParagraphLayout.h"
class TextView : public BView { class TextView : public BView {
@ -30,9 +31,11 @@ public:
float* max, float* preferred); float* max, float* preferred);
void SetText(const BString& text); void SetText(const BString& text);
void SetParagraphStyle(const ParagraphStyle& style);
private: private:
TextLayout fTextLayout; Paragraph fText;
ParagraphLayout fTextLayout;
}; };
#endif // TEXT_VIEW_H #endif // TEXT_VIEW_H