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

50 lines
1.1 KiB
C++
Raw Normal View History

2011-08-14 04:09:11 +02:00
#include "uilabel.h"
2011-08-15 16:06:15 +02:00
#include <framework/graphics/font.h>
#include <framework/otml/otmlnode.h>
2011-04-23 22:04:49 +02:00
void UILabel::setup()
2011-04-23 22:04:49 +02:00
{
UIWidget::setup();
setFocusable(false);
setAlign(AlignLeft);
2011-08-23 17:09:50 +02:00
}
void UILabel::render()
{
UIWidget::render();
m_font->renderText(m_text, m_rect, m_align, m_foregroundColor);
}
2011-08-14 04:09:11 +02:00
2011-08-23 17:09:50 +02:00
void UILabel::setText(const std::string& text)
{
m_text = text;
2011-08-14 04:09:11 +02:00
// auto resize
if(!m_fixedSize)
resizeToText();
else if(!m_rect.isValid()) {
2011-08-20 22:30:41 +02:00
Size textSize = m_font->calculateTextRectSize(m_text);
if(m_rect.width() <= 0)
m_rect.setWidth(textSize.width());
if(m_rect.height() <= 0)
m_rect.setHeight(textSize.height());
}
2011-08-14 04:09:11 +02:00
}
void UILabel::resizeToText()
{
2011-08-20 22:30:41 +02:00
resize(m_font->calculateTextRectSize(m_text));
2011-04-23 22:04:49 +02:00
}
void UILabel::onStyleApply(const OTMLNodePtr& styleNode)
{
UIWidget::onStyleApply(styleNode);
for(const OTMLNodePtr& node : styleNode->children()) {
if(node->tag() == "text")
setText(node->value());
else if(node->tag() == "align")
setAlign(fw::translateAlignment(node->value()));
}
}