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

53 lines
1.3 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();
2011-08-26 20:44:18 +02:00
Rect textRect = m_rect;
textRect.setTopLeft(textRect.topLeft() + m_offset);
m_font->renderText(m_text, textRect, m_align, m_foregroundColor);
2011-08-23 17:09:50 +02:00
}
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
2011-08-26 20:00:22 +02:00
if(!m_fixedSize && !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()));
2011-08-26 20:44:18 +02:00
else if(node->tag() == "offset") {
setOffset(node->value<Point>());
}
}
}