tibia-client/src/framework/ui/uilabel.cpp

40 lines
842 B
C++
Raw Normal View History

2011-08-14 04:09:11 +02:00
#include "uilabel.h"
#include <graphics/font.h>
#include <otml/otmlnode.h>
2011-04-23 22:04:49 +02:00
2011-08-14 04:09:11 +02:00
UILabel::UILabel() : UIWidget(UITypeLabel)
2011-04-23 22:04:49 +02:00
{
2011-08-14 04:09:11 +02:00
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<std::string>("align"));
// auto resize if no size supplied
if(!m_text.empty() && !getGeometry().isValid())
resizeToText();
}
void UILabel::render()
{
getFont()->renderText(m_text, getGeometry(), m_align, m_fontColor);
2011-08-14 04:09:11 +02:00
}
void UILabel::resizeToText()
{
resize(getFont()->calculateTextRectSize(m_text));
2011-04-23 22:04:49 +02:00
}