2 * Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
9 TextView::TextView(const char* name
)
11 BView(name
, B_WILL_DRAW
| B_FULL_UPDATE_ON_RESIZE
| B_FRAME_EVENTS
)
16 ::ParagraphStyle style
;
17 style
.SetLineSpacing(ceilf(font
.Size() * 0.2));
19 SetParagraphStyle(style
);
29 TextView::Draw(BRect updateRect
)
31 FillRect(updateRect
, B_SOLID_LOW
);
33 fTextLayout
.SetWidth(Bounds().Width());
34 fTextLayout
.Draw(this, B_ORIGIN
);
39 TextView::AttachedToWindow()
46 TextView::FrameResized(float width
, float height
)
48 fTextLayout
.SetWidth(width
);
55 return BSize(50.0f
, 0.0f
);
62 return BSize(B_SIZE_UNLIMITED
, B_SIZE_UNLIMITED
);
67 TextView::PreferredSize()
69 return BSize(B_SIZE_UNLIMITED
, B_SIZE_UNLIMITED
);
74 TextView::HasHeightForWidth()
81 TextView::GetHeightForWidth(float width
, float* min
, float* max
,
84 ParagraphLayout
layout(fTextLayout
);
85 layout
.SetWidth(width
);
87 float height
= layout
.Height() + 1;
93 if (preferred
!= NULL
)
99 TextView::SetText(const BString
& text
)
103 CharacterStyle regularStyle
;
104 fText
.Append(TextSpan(text
, regularStyle
));
106 fTextLayout
.SetParagraph(fText
);
114 TextView::SetParagraphStyle(const ::ParagraphStyle
& style
)
116 fText
.SetStyle(style
);
117 fTextLayout
.SetParagraph(fText
);