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.
53 lines
1.3 KiB
53 lines
1.3 KiB
#include "uilabel.h"
|
|
#include <framework/graphics/font.h>
|
|
#include <framework/otml/otmlnode.h>
|
|
|
|
void UILabel::setup()
|
|
{
|
|
UIWidget::setup();
|
|
setFocusable(false);
|
|
setAlign(AlignLeft);
|
|
}
|
|
|
|
void UILabel::render()
|
|
{
|
|
UIWidget::render();
|
|
Rect textRect = m_rect;
|
|
textRect.setTopLeft(textRect.topLeft() + m_offset);
|
|
m_font->renderText(m_text, textRect, m_align, m_foregroundColor);
|
|
}
|
|
|
|
void UILabel::setText(const std::string& text)
|
|
{
|
|
m_text = text;
|
|
|
|
// auto resize
|
|
if(!m_fixedSize && !m_rect.isValid()) {
|
|
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());
|
|
}
|
|
}
|
|
|
|
void UILabel::resizeToText()
|
|
{
|
|
resize(m_font->calculateTextRectSize(m_text));
|
|
}
|
|
|
|
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()));
|
|
else if(node->tag() == "offset") {
|
|
setOffset(node->value<Point>());
|
|
}
|
|
}
|
|
}
|