mirror of
https://github.com/edubart/otclient.git
synced 2025-12-21 16:07:12 +01:00
merge total remake
This commit is contained in:
@@ -1,11 +1,39 @@
|
||||
#include <global.h>
|
||||
#include <ui/uilabel.h>
|
||||
#include <ui/uielementskin.h>
|
||||
#include "uilabel.h"
|
||||
#include <graphics/font.h>
|
||||
#include <otml/otmlnode.h>
|
||||
|
||||
void UILabel::setText(const std::string& text)
|
||||
UILabel::UILabel() : UIWidget(UITypeLabel)
|
||||
{
|
||||
m_text = text;
|
||||
// text size changed, reaplly skin
|
||||
if(getSkin())
|
||||
getSkin()->apply(this);
|
||||
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, getColor());
|
||||
}
|
||||
|
||||
void UILabel::resizeToText()
|
||||
{
|
||||
resize(getFont()->calculateTextRectSize(m_text));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user