Skip to content

NLabel

接口:

接口名称返回值接口作用
LoadCustomizedSDFFontAtlasbool加载sdf字体资源
SetFontFilevoid设置字体
GetFontstd::string&获取字体
SetFontSizevoid设置字体大小
GetFontSizeconst int&获取字体大小
SetColorvoid设置字体颜色
GetColorColor32获取字体颜色
SetIsUnderlinevoid设置开启下划线
GetIsUnderlineconst bool&获取下划线状态
SetIsBoldvoid设置开启粗体
GetIsBoldconst bool&获取粗体状态
SetIsOutLinevoid设置开启描边
GetIsOutLineconst bool&获取是否描边
SetIsItalicvoid设置开启斜体
GetIsItalicconst bool&获取斜体状态
SetTextvoid设置文本
GetTextstd::string获取文本内容
SetHAlignmentvoid设置水平布局
GetHAlignmentconst TextHAlignment&获取水平布局
SetVAlignmentvoid设置垂直布局
GetVAlignmentconst TextVAlignment&获取垂直布局
SetWordSpacevoid设置字间距
GetWordSpacefloat获取字间距
SetLineSpacevoid设置行间距
GetLineSpaceconst float&获取行间距
SetLabelOverflowvoid设置水平环绕方式
SetVerticalOverflowvoid设置垂直环绕方式
GetLabelOverflowTextHOverFlow获取水平环绕方式
SetLoadListenervoid设置加载监听函数
GetLoadListenerstd::function<void(NLabelPtr)>获取加载监听函数
GetRealSizeVector2获取真实大小
SetAlignTopvoid设置顶部对齐
SetLabelLayoutChangedvoid注册文本布局变更监听
SetMaterialShaderTypevoid设置字体类型
GetMaterialShaderTypeELabelMaterialShaderType获取字体类型
SetAlphavoid设置字体透明度
GetAlphafloat获取字体透明度
SetFixedWorldScalevoid设置适应世界尺寸
GetFixedWorldScalebool获取适应世界尺寸
SetOutLineWidthvoid设置描边宽度
SetOutLineColorvoid设置描边颜色
代码示例:
cpp
//获取文本,打印当前应用的FPS
void LabelCode::Start()
{
    auto m_Label = NActorManager::GetActor("Text_1")->GetLabel();
    m_Label->SetIsBold(true);
    m_Label->SetIsItalic(true);
    m_Label->SetIsOutLine(true);
}

void LabelCode::Update()
{
   auto m_Label = NActorManager::GetActor("Text_1")->GetLabel();
   m_Label->SetText(std::to_string(NApplication::GetFPS()));
   // Called every frame if actor is enabled.
}