Skip to content

Commit

Permalink
UI|Client|LabelWidget: Allow using a custom rich format style
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jan 2, 2014
1 parent d73cce2 commit 278ba9a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
8 changes: 8 additions & 0 deletions doomsday/client/include/ui/widgets/labelwidget.h
Expand Up @@ -130,6 +130,14 @@ class LabelWidget : public GuiWidget
*/
void setMaximumTextWidth(int pixels);

/**
* Sets an alternative style for text. By default, the rich text styling comes
* from Style.
*
* @param richStyle Rich text styling.
*/
void setTextStyle(de::Font::RichFormat::IStyle const *richStyle);

/**
* The image's actual size will be overridden by this size.
* @param size Image size.
Expand Down
20 changes: 19 additions & 1 deletion doomsday/client/src/ui/widgets/labelwidget.cpp
Expand Up @@ -56,6 +56,7 @@ public Font::RichFormat::IStyle
ColorBank::Color dimmedColor;
ColorBank::Color accentColor;
ColorBank::Color dimAccentColor;
Font::RichFormat::IStyle const *richStyle;

TextDrawable glText;
mutable Vector2ui latestTextSize;
Expand All @@ -79,6 +80,7 @@ public Font::RichFormat::IStyle
, imageColor (1, 1, 1, 1)
, maxTextWidth(0)
, gapId ("label.gap")
, richStyle (0)
, uMvpMatrix ("uMvpMatrix", GLUniform::Mat4)
, uColor ("uColor", GLUniform::Vec4)
{
Expand Down Expand Up @@ -138,11 +140,22 @@ public Font::RichFormat::IStyle
void richStyleFormat(int contentStyle, float &sizeFactor, Font::RichFormat::Weight &fontWeight,
Font::RichFormat::Style &fontStyle, int &colorIndex) const
{
return style().richStyleFormat(contentStyle, sizeFactor, fontWeight, fontStyle, colorIndex);
if(richStyle)
{
richStyle->richStyleFormat(contentStyle, sizeFactor, fontWeight, fontStyle, colorIndex);
}
else
{
style().richStyleFormat(contentStyle, sizeFactor, fontWeight, fontStyle, colorIndex);
}
}

Font const *richStyleFont(Font::RichFormat::Style fontStyle) const
{
if(richStyle)
{
return richStyle->richStyleFont(fontStyle);
}
return style().richStyleFont(fontStyle);
}

Expand Down Expand Up @@ -528,6 +541,11 @@ void LabelWidget::setMaximumTextWidth(int pixels)
requestGeometry();
}

void LabelWidget::setTextStyle(Font::RichFormat::IStyle const *richStyle)
{
d->richStyle = richStyle;
}

void LabelWidget::setOverrideImageSize(Vector2f const &size)
{
d->overrideImageSize = size;
Expand Down

0 comments on commit 278ba9a

Please sign in to comment.