enable text-auto-resize for width

master
Eduardo Bart 12 years ago
parent 2c53d0b1dc
commit 1d2f6c7e9f

@ -18,5 +18,6 @@ Panel
text-align: center text-align: center
text-auto-resize: true text-auto-resize: true
width: 120 width: 120
padding: 2
color: #ffffff color: #ffffff
font: verdana-11px-monochrome font: verdana-11px-monochrome

@ -1318,8 +1318,6 @@ void UIWidget::onStyleApply(const std::string& styleName, const OTMLNodePtr& sty
void UIWidget::onGeometryChange(const Rect& oldRect, const Rect& newRect) void UIWidget::onGeometryChange(const Rect& oldRect, const Rect& newRect)
{ {
callLuaField("onGeometryChange", oldRect, newRect);
if(m_textWrap && oldRect.size() != newRect.size()) if(m_textWrap && oldRect.size() != newRect.size())
updateText(); updateText();
@ -1328,6 +1326,8 @@ void UIWidget::onGeometryChange(const Rect& oldRect, const Rect& newRect)
if(!child->isAnchored()) if(!child->isAnchored())
child->bindRectToParent(); child->bindRectToParent();
} }
callLuaField("onGeometryChange", oldRect, newRect);
} }
void UIWidget::onLayoutUpdate() void UIWidget::onLayoutUpdate()

@ -41,20 +41,14 @@ void UIWidget::updateText()
m_drawText = m_text; m_drawText = m_text;
// update rect size // update rect size
if(!m_rect.isValid()) { if(!m_rect.isValid() || m_textAutoResize) {
Size textSize = getTextSize(); Size textBoxSize = getTextSize();
Size newSize = getSize(); textBoxSize += Size(m_padding.left + m_padding.right, m_padding.top + m_padding.left);
if(newSize.width() <= 0)
newSize.setWidth(textSize.width());
if(newSize.height() <= 0)
newSize.setHeight(textSize.height());
setSize(newSize);
} else if(m_textAutoResize) {
Size textSize = getTextSize();
Size size = getSize(); Size size = getSize();
if(textSize.width() > size.width()) if(size.width() <= 0 || (m_textAutoResize && !m_textWrap))
size.setWidth(textSize.width()); size.setWidth(textBoxSize.width());
size.setHeight(textSize.height()); if(size.height() <= 0 || m_textAutoResize)
size.setHeight(textBoxSize.height());
setSize(size); setSize(size);
} }

Loading…
Cancel
Save