dl
dl_ui_text.h
浏览该文件的文档.
1
12#pragma once
13
14#ifndef DL_DISABLE_RENDER
15#include <string>
16
17#include "render/dl_text.h"
18#include "misc/dl_language.h"
19#include "misc/dl_component.h"
20
21namespace dl::UI
22{
23class Panel;
25class Text
26{
27public:
28 static Text* Create(gcText txt)
29 {
30 Text* ret = new Text;
31 ret->_txt = txt;
34 return ret;
35 }
36
39 Text* Clone();
40
41 void Render()
42 {
43 _txt->Render();
44 }
45
46 bool IsPickup()
47 {
48 return _txt->IsPickup();
49 }
50
52 void SetOrder(float order)
53 {
54 _txt->SetOrder(order);
55 }
56
57 Coor* GetCoor() { return _txt->GetCoor(); }
58
63 void SetLang(std::string_view tag, std::string_view name)
64 {
65 _cptLang._str = { std::string{tag}, std::string{name} };
66 _cptLang._func = std::bind(&Text::_refresh_lang, this, std::placeholders::_1, std::placeholders::_2);
67 _cpt.PushBack(&_cptLang);
68
69 _refresh_lang(tag, name);
70 }
71
72 void SetString(std::string_view str)
73 {
74 if(_txt->SetString(str))
75 _refresh_element_data();
76 }
77
82 gcText GetText() { return _txt; }
83
85 Components* GetCpt() { return &_cpt; }
86private:
87 Text() :
88 _panel{ nullptr },
89 _cpt{ this }
90 {
91 _init_cpt();
92 }
93
94 gcText _txt;
95 Panel* _panel;
96 Components _cpt;
97 Cpt::DeleteThis _cptDeleteThis;
98 Cpt::SetOrder _cptSetOrder;
99 Cpt::IsPickup _cptIsPickup;
100 Cpt::Render _cptRender;
101 Cpt::GetCoor _cptGetCoor;
102 Cpt::Lang _cptLang;
103 Cpt::ElementData _cptElemData;
104 Cpt::Clone _cptClone;
105
106 void _delete_this() { delete this; }
107
108 Components* _clone()
109 {
110 return Clone()->GetCpt();
111 }
112
113 void _init_cpt()
114 {
115 _cptDeleteThis = std::bind(&Text::_delete_this, this);
116 _cptSetOrder = std::bind(&Text::SetOrder, this, std::placeholders::_1);
117 _cptIsPickup = std::bind(&Text::IsPickup, this);
118 _cptRender = std::bind(&Text::Render, this);
119 _cptGetCoor = std::bind(&Text::GetCoor, this);
120 _cptSetOrder = std::bind(&Text::SetOrder, this, std::placeholders::_1);
121 _cptClone = std::bind(&Text::_clone, this);
122
123 _cpt.PushBack(&_cptDeleteThis);
124 _cpt.PushBack(&_cptSetOrder);
125 _cpt.PushBack(&_cptIsPickup);
126 _cpt.PushBack(&_cptRender);
127 _cpt.PushBack(&_cptGetCoor);
128 _cpt.PushBack(&_cptSetOrder);
129 _cpt.PushBack(&_cptClone);
130 _cpt.PushBack(&_panel);
131
132
133 _cpt.PushBack(&_cptElemData);
134 }
135 //回调
136 void _refresh_lang(std::string_view tag, std::string_view name)
137 {
138 SetString(lang(tag, name));
139 }
140
141 void _refresh_element_data()
142 {
143 SetElementData(_cptElemData._hv);
144 }
145
146};
147}
148
149#endif
2d坐标系
元素通用属性(默认左上对齐,便于理解)
语言本地化
Components * GetCpt()
void SetOrder(float order)
设置绘制顺序
void SetLang(std::string_view tag, std::string_view name)
设置语言
void SetString(std::string_view str)
void SetElementData(const Align::Direction2 &hv)
static Text * Create(gcText txt)
Text * Clone()
复制一个,注意有些组件属性需要复制
gcText GetText()
返回文本对象,注意在大小变化后,不会更新ui的元素数据
组件系统
本地化
文本绘制
std::array< Direction, 2 > Direction2
constexpr Direction2 LT
Function< std::function< void(float)>, str_uid("SetOrder")> SetOrder
设置order
Function< std::function< dl::Coor *()>, str_uid("GetCoor")> GetCoor
返回坐标系
Function< std::function< bool()>, str_uid("IsPickup")> IsPickup
---------------------------—具体组件----------------------------------—
Function< std::function< void()>, str_uid("Render")> Render
绘制
Function< std::function< void()>, str_uid("DeleteThis")> DeleteThis
删除自身
Function< std::function< Components *()>, str_uid("Clone")> Clone
克隆
constexpr float Z_DEFAULT_UI
std::string_view lang(std::string_view tag, std::string_view name)
返回一个语言配置的字符串,传入 menu、start
GC< Text > gcText