From 8d0c791d5f3ad6837ea6d0c695e46ed6b6e298c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Fri, 6 Sep 2013 10:02:33 +0200 Subject: [PATCH] HaikuDepot: Switched TextView to use new ParagraphLayout * The ParagraphStyle can be set as well. --- src/apps/haiku-depot/textview/TextView.cpp | 32 ++++++++++++++++++---- src/apps/haiku-depot/textview/TextView.h | 7 +++-- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/apps/haiku-depot/textview/TextView.cpp b/src/apps/haiku-depot/textview/TextView.cpp index cd41dec400..836b401de3 100644 --- a/src/apps/haiku-depot/textview/TextView.cpp +++ b/src/apps/haiku-depot/textview/TextView.cpp @@ -10,11 +10,16 @@ TextView::TextView(const char* name) : 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)); + + 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, float* preferred) { - TextLayout layout(fTextLayout); + ParagraphLayout layout(fTextLayout); layout.SetWidth(width); float height = layout.Height() + 1; @@ -98,6 +103,23 @@ TextView::GetHeightForWidth(float width, float* min, float* max, void 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(); } diff --git a/src/apps/haiku-depot/textview/TextView.h b/src/apps/haiku-depot/textview/TextView.h index 6f31f2c225..109a0111f7 100644 --- a/src/apps/haiku-depot/textview/TextView.h +++ b/src/apps/haiku-depot/textview/TextView.h @@ -8,7 +8,8 @@ #include #include -#include "TextLayout.h" +#include "Paragraph.h" +#include "ParagraphLayout.h" class TextView : public BView { @@ -30,9 +31,11 @@ public: float* max, float* preferred); void SetText(const BString& text); + void SetParagraphStyle(const ParagraphStyle& style); private: - TextLayout fTextLayout; + Paragraph fText; + ParagraphLayout fTextLayout; }; #endif // TEXT_VIEW_H