HaikuDepot: Switched TextView to use new ParagraphLayout
* The ParagraphStyle can be set as well.
This commit is contained in:
parent
822872d6c3
commit
8d0c791d5f
@ -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();
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,8 @@
|
||||
#include <String.h>
|
||||
#include <View.h>
|
||||
|
||||
#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
|
||||
|
Loading…
Reference in New Issue
Block a user