28 Paragraph&
setFont( std::shared_ptr<Font> font,
bool resetLeadingAndSpacing =
true );
149 for (
auto& token : word.styledTokens ) {
150 fontForStyle( token.style )->drawString( token.text, word.x + token.bounds.x, word.y );
154 if (
m_fbo.isAllocated() ) {
210 float lineHeight =
m_font->getSize();
214 auto spPosition = str.find(
" " );
215 auto nlPosition = str.find(
"\n" );
216 auto position = spPosition < nlPosition ? spPosition : nlPosition;
219 while ( position != std::string::npos ) {
220 std::string s = str.substr( 0, position );
226 str.erase( 0, position + 1 );
227 textPos += position + 1;
229 if ( position == nlPosition ) {
234 spPosition = str.find(
" " );
235 nlPosition = str.find(
"\n" );
236 position = spPosition < nlPosition ? spPosition : nlPosition;
247 float y = lineHeight * .85;
250 std::vector<Word*> line;
253 if ( word.
text ==
"\n" ) {
260 if ( line.size() > 0 ) {
265 }
else if ( x + word.
w <
m_size.x ) {
271 line.push_back( &word );
276 if ( line.size() > 0 )
281 if ( line.size() > 0 )
284 line.push_back( &word );
295 for (
auto* word : line ) {
296 lineWidth += word->
w;
298 lineWidth +=
m_spacing * ( line.size() - 1 );
300 float offset = (
m_size.x - lineWidth ) / 2;
301 for (
auto* word : line ) {
307 auto* lword = line.back();
309 int offset =
m_size.x - ( lword->x + lword->w );
310 for (
auto* word : line ) {
318 float yOffset = (
m_size.y - pHeight ) * .5;
324 float yOffset = (
m_size.y - pHeight );
Definition: component.h:11
Definition: paragraph_component.h:11
ga::Color getTextColor()
Definition: paragraph_component.h:59
bool m_isMarkdownFormatted
Definition: paragraph_component.h:174
ga::vec2 getSize()
Definition: paragraph_component.h:56
void calcWordRect(Word &word)
Definition: paragraph_component.cpp:224
Paragraph & setBoldItalicFont(std::shared_ptr< Font > font)
Definition: paragraph_component.cpp:48
Paragraph & setTextOffset(ga::vec2 textOffset)
Definition: paragraph_component.h:50
Paragraph & setFont(std::shared_ptr< Font > font, bool resetLeadingAndSpacing=true)
Definition: paragraph_component.cpp:21
VertAlignment
Definition: paragraph_component.h:20
ga::Fbo m_fbo
Definition: paragraph_component.h:176
bool getIsFboCacheEnabled()
Definition: paragraph_component.h:75
void cleanLayout()
Definition: paragraph_component.cpp:193
ga::Color m_textColor
Definition: paragraph_component.h:169
std::shared_ptr< Font > getBoldItalicFont()
Definition: paragraph_component.h:38
glm::vec3 m_offset
Definition: paragraph_component.h:166
std::shared_ptr< Font > getItalicFont()
Definition: paragraph_component.h:35
HorzAlignment
Definition: paragraph_component.h:14
float m_spacing
Definition: paragraph_component.h:173
std::string getText()
Definition: paragraph_component.h:41
FontStyle
Definition: paragraph_component.h:87
Paragraph()
Definition: paragraph_component.cpp:7
std::shared_ptr< Font > getBoldFont()
Definition: paragraph_component.h:32
int getNumberOfLines()
Definition: paragraph_component.cpp:187
Paragraph & setTextOffset(ga::vec3 textOffset)
Definition: paragraph_component.cpp:83
Paragraph & setVerticalAlignment(VertAlignment alignment)
Definition: paragraph_component.cpp:73
std::shared_ptr< Font > m_font
Definition: paragraph_component.h:164
std::shared_ptr< Font > m_boldItalicFont
Definition: paragraph_component.h:164
Paragraph & setText(std::string text)
Definition: paragraph_component.cpp:55
VertAlignment m_vAlignment
Definition: paragraph_component.h:171
ga::Rect m_fboRect
Definition: paragraph_component.h:177
Paragraph & setWordSpacing(float px)
Definition: paragraph_component.cpp:119
StyledText parseMarkdownStyles(const std::string &text)
Definition: paragraph_component.cpp:286
void calculateTextFlow()
Definition: paragraph_component.h:205
bool m_cacheToFbo
Definition: paragraph_component.h:180
HorzAlignment m_hAlignment
Definition: paragraph_component.h:170
Paragraph & setTextColor(const ga::Color textColor)
Definition: paragraph_component.cpp:100
std::vector< Word > m_words
Definition: paragraph_component.h:115
void drawParagraph(bool forceRedraw=false)
Definition: paragraph_component.h:141
HorzAlignment getHorizontalAlignment()
Definition: paragraph_component.h:45
float m_leading
Definition: paragraph_component.h:172
Paragraph & setLeading(float px)
Definition: paragraph_component.cpp:108
std::vector< std::vector< Word * > > m_lines
Definition: paragraph_component.h:116
std::vector< ga::Rect > getWordBounds()
Definition: paragraph_component.cpp:154
std::shared_ptr< Font > fontForStyle(FontStyle style)
Definition: paragraph_component.h:118
VertAlignment getVerticalAlignment()
Definition: paragraph_component.h:46
Paragraph & setFboCacheEnabled(bool enable)
Definition: paragraph_component.cpp:134
std::shared_ptr< Font > m_italicFont
Definition: paragraph_component.h:164
float getWordSpacing()
Definition: paragraph_component.h:67
Paragraph & setIsMarkdownText(bool isMarkdown)
Definition: paragraph_component.cpp:128
StyledText m_styledText
Definition: paragraph_component.h:163
Paragraph & setHorizontalAlignment(HorzAlignment alignment)
Definition: paragraph_component.cpp:64
std::string m_text
Definition: paragraph_component.h:162
std::shared_ptr< Font > m_boldFont
Definition: paragraph_component.h:164
Paragraph & setItalicFont(std::shared_ptr< Font > font)
Definition: paragraph_component.cpp:41
ga::vec3 getTextOffset()
Definition: paragraph_component.h:52
ga::Rect getParagraphBounds()
Definition: paragraph_component.cpp:171
glm::vec2 m_size
Definition: paragraph_component.h:167
Paragraph & setSize(ga::vec2 size)
Definition: paragraph_component.cpp:91
std::shared_ptr< Font > getFont()
Definition: paragraph_component.h:29
bool m_isLayoutDirty
Definition: paragraph_component.h:179
Paragraph & setBoldFont(std::shared_ptr< Font > font)
Definition: paragraph_component.cpp:34
void draw()
Definition: paragraph_component.cpp:140
bool getIsMarkdownText() const
Definition: paragraph_component.h:71
float getLeading()
Definition: paragraph_component.h:63
ga::vec4 Color
Definition: color.h:12
Definition: paragraph_component.h:95
std::string text
Definition: paragraph_component.h:96
std::vector< FontStyle > styles
Definition: paragraph_component.h:97
Definition: paragraph_component.h:101
std::string text
Definition: paragraph_component.h:102
ga::Rect bounds
Definition: paragraph_component.h:104
FontStyle style
Definition: paragraph_component.h:103
Definition: paragraph_component.h:108
std::vector< FontStyle > style
Definition: paragraph_component.h:111
std::string text
Definition: paragraph_component.h:109
float w
Definition: paragraph_component.h:110
std::vector< StyledToken > styledTokens
Definition: paragraph_component.h:112
float h
Definition: paragraph_component.h:110
float x
Definition: paragraph_component.h:110
float y
Definition: paragraph_component.h:110
A 2D axis-aligned rectangle, with x,y (float) position and w,h (float) size components.
Definition: math.h:64
float y
Definition: math.h:91
float x
Definition: math.h:91