#include "uilabel.h" #include #include 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 = parseAlignment(styleNode->readAt("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)); }