143 lines
2.7 KiB
C++
143 lines
2.7 KiB
C++
/**
|
|
* @file DND.UI.Text.ixx
|
|
* @brief UI之文本
|
|
*
|
|
*
|
|
* @version 1.0
|
|
* @author lveyou
|
|
* @date 22-10-05
|
|
*
|
|
* @note 包含一个gcText,和整体对齐
|
|
*/
|
|
#pragma once
|
|
|
|
#include <string>
|
|
|
|
#include "render/dl_text.h"
|
|
#include "misc/dl_language.h"
|
|
#include "misc/dl_component.h"
|
|
|
|
namespace dl::UI
|
|
{
|
|
class Panel;
|
|
//! ui文本
|
|
class Text
|
|
{
|
|
public:
|
|
static Text* Create(gcText txt)
|
|
{
|
|
Text* ret = new Text;
|
|
ret->_txt = txt;
|
|
ret->SetElementData(Align::LT);
|
|
ret->SetOrder(Z_DEFAULT_UI);
|
|
return ret;
|
|
}
|
|
/**
|
|
* @brief 复制一个,注意有些组件属性需要复制
|
|
*/
|
|
Text* Clone();
|
|
|
|
void Render()
|
|
{
|
|
_txt->Render();
|
|
}
|
|
|
|
bool IsPickup()
|
|
{
|
|
return _txt->IsPickup();
|
|
}
|
|
|
|
//! 设置绘制顺序
|
|
void SetOrder(float order)
|
|
{
|
|
_txt->SetOrder(order);
|
|
}
|
|
|
|
Coor* GetCoor() { return _txt->GetCoor(); }
|
|
|
|
/**
|
|
* @brief 设置语言
|
|
* @note 设置后在修改语言时,可以自动更新
|
|
*/
|
|
void SetLang(std::string_view tag, std::string_view name)
|
|
{
|
|
_cptLang._str = { std::string{tag}, std::string{name} };
|
|
_cptLang._func = std::bind(&Text::_refresh_lang, this, std::placeholders::_1, std::placeholders::_2);
|
|
_cpt.PushBack(&_cptLang);
|
|
|
|
_refresh_lang(tag, name);
|
|
}
|
|
|
|
void SetString(std::string_view str)
|
|
{
|
|
if(_txt->SetString(str))
|
|
_refresh_element_data();
|
|
}
|
|
/**
|
|
* @brief 返回文本对象,注意在大小变化后,不会更新ui的元素数据
|
|
* @note 优先使用SetString设置内容,或手动调用RefreshElementData
|
|
*/
|
|
gcText GetText() { return _txt; }
|
|
|
|
void SetElementData(const Align::Direction2& hv);
|
|
Components* GetCpt() { return &_cpt; }
|
|
private:
|
|
Text() :
|
|
_panel{ nullptr },
|
|
_cpt{ this }
|
|
{
|
|
_init_cpt();
|
|
}
|
|
|
|
gcText _txt;
|
|
Panel* _panel;
|
|
Components _cpt;
|
|
Cpt::DeleteThis _cptDeleteThis;
|
|
Cpt::SetOrder _cptSetOrder;
|
|
Cpt::Render _cptRender;
|
|
Cpt::GetCoor _cptGetCoor;
|
|
Cpt::Lang _cptLang;
|
|
Cpt::ElementData _cptElemData;
|
|
Cpt::Clone _cptClone;
|
|
|
|
void _delete_this() { delete this; }
|
|
|
|
Components* _clone()
|
|
{
|
|
return Clone()->GetCpt();
|
|
}
|
|
|
|
void _init_cpt()
|
|
{
|
|
_cptDeleteThis = std::bind(&Text::_delete_this, this);
|
|
_cptSetOrder = std::bind(&Text::SetOrder, this, std::placeholders::_1);
|
|
_cptRender = std::bind(&Text::Render, this);
|
|
_cptGetCoor = std::bind(&Text::GetCoor, this);
|
|
_cptSetOrder = std::bind(&Text::SetOrder, this, std::placeholders::_1);
|
|
_cptClone = std::bind(&Text::_clone, this);
|
|
|
|
_cpt.PushBack(&_cptDeleteThis);
|
|
_cpt.PushBack(&_cptSetOrder);
|
|
_cpt.PushBack(&_cptRender);
|
|
_cpt.PushBack(&_cptGetCoor);
|
|
_cpt.PushBack(&_cptSetOrder);
|
|
_cpt.PushBack(&_cptClone);
|
|
_cpt.PushBack(&_panel);
|
|
|
|
|
|
_cpt.PushBack(&_cptElemData);
|
|
}
|
|
//回调
|
|
void _refresh_lang(std::string_view tag, std::string_view name)
|
|
{
|
|
SetString(lang(tag, name));
|
|
}
|
|
|
|
void _refresh_element_data()
|
|
{
|
|
SetElementData(_cptElemData._hv);
|
|
}
|
|
|
|
};
|
|
}
|