diff --git a/doomsday/libappfw/include/de/widgets/labelwidget.h b/doomsday/libappfw/include/de/widgets/labelwidget.h index 87fce7026c..3af1668a94 100644 --- a/doomsday/libappfw/include/de/widgets/labelwidget.h +++ b/doomsday/libappfw/include/de/widgets/labelwidget.h @@ -170,6 +170,28 @@ class LIBAPPFW_PUBLIC LabelWidget : public GuiWidget void setWidthPolicy(ui::SizePolicy policy); void setHeightPolicy(ui::SizePolicy policy); + enum AppearanceAnimation { + AppearInstantly, + AppearGrowHorizontally, + AppearGrowVertically + }; + + /** + * Sets the way the label's content affects its size. + * + * @param method Method of appearance: + * - AppearInstantly: The size is unaffected by the content's state. + * This is the default. + * - AppearGrowHorizontally: The widget's width is initially zero, but when the + * content is ready for drawing, the width will animate + * to the appropriate width in the specified time span. + * - AppearGrowVertically: The widget's height is initially zero, but when the + * content is ready for drawing, the height will animate + * to the appropriate height in the specified time span. + * @param span Animation time span for the appearance. + */ + void setAppearanceAnimation(AppearanceAnimation method, TimeDelta const &span = 0.0); + // Events. void viewResized(); void update(); diff --git a/doomsday/libappfw/src/widgets/labelwidget.cpp b/doomsday/libappfw/src/widgets/labelwidget.cpp index 805e6636aa..e2862e1574 100644 --- a/doomsday/libappfw/src/widgets/labelwidget.cpp +++ b/doomsday/libappfw/src/widgets/labelwidget.cpp @@ -49,6 +49,9 @@ public Font::RichFormat::IStyle ConstantRule *width; ConstantRule *height; + ScalarRule *appearSize; + LabelWidget::AppearanceAnimation appearType; + TimeDelta appearSpan; // Style. Vector4i margin; @@ -83,6 +86,9 @@ public Font::RichFormat::IStyle , imageColor (1, 1, 1, 1) , textGLColor (1, 1, 1, 1) , maxTextWidth(0) + , appearSize (new ScalarRule(0)) + , appearType (AppearInstantly) + , appearSpan (0.0) , gapId ("label.gap") , richStyle (0) , uMvpMatrix ("uMvpMatrix", GLUniform::Mat4) @@ -99,6 +105,7 @@ public Font::RichFormat::IStyle { releaseRef(width); releaseRef(height); + releaseRef(appearSize); } void updateStyle() @@ -432,6 +439,18 @@ public Font::RichFormat::IStyle height->set(combined.height() + margin.y + margin.w); } + void updateAppearanceAnimation() + { + if(appearType != AppearInstantly) + { + float const target = (appearType == AppearGrowHorizontally? width->value() : height->value()); + if(!fequal(appearSize->animation().target(), target)) + { + appearSize->set(target, appearSpan); + } + } + } + void updateGeometry() { // Update the image on the atlas. @@ -591,6 +610,7 @@ void LabelWidget::update() GuiWidget::update(); d->updateSize(); + d->updateAppearanceAnimation(); } void LabelWidget::drawContent() @@ -678,6 +698,30 @@ void LabelWidget::setHeightPolicy(SizePolicy policy) } } +void LabelWidget::setAppearanceAnimation(AppearanceAnimation method, TimeDelta const &span) +{ + d->appearType = method; + d->appearSpan = span; + + switch(d->appearType) + { + case AppearInstantly: + if(d->horizPolicy == Expand) rule().setInput(Rule::Width, *d->width); + if(d->vertPolicy == Expand) rule().setInput(Rule::Height, *d->height); + break; + + case AppearGrowHorizontally: + if(d->horizPolicy == Expand) rule().setInput(Rule::Width, *d->appearSize); + if(d->vertPolicy == Expand) rule().setInput(Rule::Height, *d->height); + break; + + case AppearGrowVertically: + if(d->horizPolicy == Expand) rule().setInput(Rule::Width, *d->width); + if(d->vertPolicy == Expand) rule().setInput(Rule::Height, *d->appearSize); + break; + } +} + LabelWidget *LabelWidget::newWithText(String const &label, GuiWidget *parent) { LabelWidget *w = new LabelWidget;