You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
860 B

#include "uilabel.h"
#include <framework/graphics/font.h>
#include <framework/otml/otmlnode.h>
UILabel::UILabel() : UIWidget(UITypeLabel)
{
m_align = AlignLeft;
}
UILabelPtr UILabel::create()
{
UILabelPtr label(new UILabel);
label->setStyle("Label");
return label;
}
void UILabel::loadStyleFromOTML(const OTMLNodePtr& styleNode)
{
UIWidget::loadStyleFromOTML(styleNode);
m_text = styleNode->readAt("text", m_text);
if(styleNode->hasChild("align"))
m_align = fw::translateAlignment(styleNode->readAt<std::string>("align"));
// auto resize if no size supplied
if(!m_text.empty() && !getGeometry().isValid())
resizeToText();
}
void UILabel::render()
{
m_font->renderText(m_text, m_rect, m_align, m_fontColor);
}
void UILabel::resizeToText()
{
resize(getFont()->calculateTextRectSize(m_text));
}