Skip to content

Commit

Permalink
libappfw|LabelWidget: Specify maximum text width with a Rule
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jun 20, 2014
1 parent 77015d2 commit 053aeba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions doomsday/libappfw/include/de/widgets/labelwidget.h
Expand Up @@ -141,6 +141,8 @@ class LIBAPPFW_PUBLIC LabelWidget : public GuiWidget, public AssetGroup
*/
void setMaximumTextWidth(int pixels);

void setMaximumTextWidth(Rule const &pixels);

/**
* Sets an alternative style for text. By default, the rich text styling comes
* from Style.
Expand Down
14 changes: 10 additions & 4 deletions doomsday/libappfw/src/widgets/labelwidget.cpp
Expand Up @@ -46,7 +46,7 @@ public Font::RichFormat::IStyle
float imageScale;
Vector4f imageColor;
Vector4f textGLColor;
int maxTextWidth;
Rule const *maxTextWidth;

ConstantRule *width;
ConstantRule *height;
Expand Down Expand Up @@ -112,6 +112,7 @@ public Font::RichFormat::IStyle
releaseRef(width);
releaseRef(height);
releaseRef(appearSize);
releaseRef(maxTextWidth);
}

void updateStyle()
Expand Down Expand Up @@ -451,9 +452,9 @@ public Font::RichFormat::IStyle
}
}
// Apply an optional manual constraint to the text width.
if(maxTextWidth > 0)
if(maxTextWidth)
{
return de::min(maxTextWidth, w);
return de::min(maxTextWidth->valuei(), w);
}
return w;
}
Expand Down Expand Up @@ -651,7 +652,12 @@ void LabelWidget::setImageFit(ContentFit const &fit)

void LabelWidget::setMaximumTextWidth(int pixels)
{
d->maxTextWidth = pixels;
setMaximumTextWidth(Const(pixels));
}

void de::LabelWidget::setMaximumTextWidth(Rule const &pixels)
{
changeRef(d->maxTextWidth, pixels);
requestGeometry();
}

Expand Down

0 comments on commit 053aeba

Please sign in to comment.