From 278ba9ab04d0634fb4c9b80fe178a32f8116cfea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Ker=C3=A4nen?= Date: Thu, 2 Jan 2014 23:18:21 +0200 Subject: [PATCH] UI|Client|LabelWidget: Allow using a custom rich format style --- .../client/include/ui/widgets/labelwidget.h | 8 ++++++++ .../client/src/ui/widgets/labelwidget.cpp | 20 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/doomsday/client/include/ui/widgets/labelwidget.h b/doomsday/client/include/ui/widgets/labelwidget.h index bd4d22a86b..0694643e33 100644 --- a/doomsday/client/include/ui/widgets/labelwidget.h +++ b/doomsday/client/include/ui/widgets/labelwidget.h @@ -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. diff --git a/doomsday/client/src/ui/widgets/labelwidget.cpp b/doomsday/client/src/ui/widgets/labelwidget.cpp index ac70028e36..72edba97cf 100644 --- a/doomsday/client/src/ui/widgets/labelwidget.cpp +++ b/doomsday/client/src/ui/widgets/labelwidget.cpp @@ -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; @@ -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) { @@ -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); } @@ -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;