NLabel
接口:
| 接口名称 | 返回值 | 接口作用 |
|---|---|---|
| LoadCustomizedSDFFontAtlas | bool | 加载sdf字体资源 |
| SetFontFile | void | 设置字体 |
| GetFont | std::string& | 获取字体 |
| SetFontSize | void | 设置字体大小 |
| GetFontSize | const int& | 获取字体大小 |
| SetColor | void | 设置字体颜色 |
| GetColor | Color32 | 获取字体颜色 |
| SetIsUnderline | void | 设置开启下划线 |
| GetIsUnderline | const bool& | 获取下划线状态 |
| SetIsBold | void | 设置开启粗体 |
| GetIsBold | const bool& | 获取粗体状态 |
| SetIsOutLine | void | 设置开启描边 |
| GetIsOutLine | const bool& | 获取是否描边 |
| SetIsItalic | void | 设置开启斜体 |
| GetIsItalic | const bool& | 获取斜体状态 |
| SetText | void | 设置文本 |
| GetText | std::string | 获取文本内容 |
| SetHAlignment | void | 设置水平布局 |
| GetHAlignment | const TextHAlignment& | 获取水平布局 |
| SetVAlignment | void | 设置垂直布局 |
| GetVAlignment | const TextVAlignment& | 获取垂直布局 |
| SetWordSpace | void | 设置字间距 |
| GetWordSpace | float | 获取字间距 |
| SetLineSpace | void | 设置行间距 |
| GetLineSpace | const float& | 获取行间距 |
| SetLabelOverflow | void | 设置水平环绕方式 |
| SetVerticalOverflow | void | 设置垂直环绕方式 |
| GetLabelOverflow | TextHOverFlow | 获取水平环绕方式 |
| SetLoadListener | void | 设置加载监听函数 |
| GetLoadListener | std::function<void(NLabelPtr)> | 获取加载监听函数 |
| GetRealSize | Vector2 | 获取真实大小 |
| SetAlignTop | void | 设置顶部对齐 |
| SetLabelLayoutChanged | void | 注册文本布局变更监听 |
| SetMaterialShaderType | void | 设置字体类型 |
| GetMaterialShaderType | ELabelMaterialShaderType | 获取字体类型 |
| SetAlpha | void | 设置字体透明度 |
| GetAlpha | float | 获取字体透明度 |
| SetFixedWorldScale | void | 设置适应世界尺寸 |
| GetFixedWorldScale | bool | 获取适应世界尺寸 |
| SetOutLineWidth | void | 设置描边宽度 |
| SetOutLineColor | void | 设置描边颜色 |
| 代码示例: |
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.
}
