|
|
|
@ -8,23 +8,30 @@ UILabel::UILabel()
|
|
|
|
|
m_focusable = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UILabelPtr UILabel::create()
|
|
|
|
|
{
|
|
|
|
|
UILabelPtr label(new UILabel);
|
|
|
|
|
return label;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UILabel::onStyleApply(const OTMLNodePtr& styleNode)
|
|
|
|
|
{
|
|
|
|
|
UIWidget::onStyleApply(styleNode);
|
|
|
|
|
|
|
|
|
|
m_text = styleNode->valueAt("text", m_text);
|
|
|
|
|
for(const OTMLNodePtr& node : styleNode->children()) {
|
|
|
|
|
if(node->tag() == "text")
|
|
|
|
|
setText(node->value());
|
|
|
|
|
else if(node->tag() == "align")
|
|
|
|
|
setAlign(fw::translateAlignment(styleNode->value()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UILabel::render()
|
|
|
|
|
{
|
|
|
|
|
UIWidget::render();
|
|
|
|
|
m_font->renderText(m_text, m_rect, m_align, m_foregroundColor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(styleNode->hasChildAt("align"))
|
|
|
|
|
m_align = fw::translateAlignment(styleNode->valueAt("align"));
|
|
|
|
|
void UILabel::setText(const std::string& text)
|
|
|
|
|
{
|
|
|
|
|
m_text = text;
|
|
|
|
|
|
|
|
|
|
// auto resize if needed
|
|
|
|
|
if(!m_text.empty() && !m_rect.isValid()) {
|
|
|
|
|
// auto resize if the current rect is invalid
|
|
|
|
|
if(!m_rect.isValid()) {
|
|
|
|
|
Size textSize = m_font->calculateTextRectSize(m_text);
|
|
|
|
|
if(m_rect.width() <= 0)
|
|
|
|
|
m_rect.setWidth(textSize.width());
|
|
|
|
@ -33,12 +40,6 @@ void UILabel::onStyleApply(const OTMLNodePtr& styleNode)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UILabel::render()
|
|
|
|
|
{
|
|
|
|
|
UIWidget::render();
|
|
|
|
|
m_font->renderText(m_text, m_rect, m_align, m_foregroundColor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UILabel::resizeToText()
|
|
|
|
|
{
|
|
|
|
|
resize(m_font->calculateTextRectSize(m_text));
|
|
|
|
|