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 }
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 }
81 gcText GetText() { return _txt; }
82
84 Components* GetCpt() { return &_cpt; }
85private:
86 Text() :
87 _panel{ nullptr },
88 _cpt{ this }
89 {
90 _init_cpt();
91 }
92
93 gcText _txt;
94 Panel* _panel;
95 Components _cpt;
96 Cpt::DeleteThis _cptDeleteThis;
97 Cpt::SetOrder _cptSetOrder;
98 Cpt::Render _cptRender;
99 Cpt::GetCoor _cptGetCoor;
100 Cpt::Lang _cptLang;
101 Cpt::ElementData _cptElemData;
102 Cpt::Clone _cptClone;
103
104 void _delete_this() { delete this; }
105
106 Components* _clone()
107 {
108 return Clone()->GetCpt();
109 }
110
111 void _init_cpt()
112 {
113 _cptDeleteThis = std::bind(&Text::_delete_this, this);
114 _cptSetOrder = std::bind(&Text::SetOrder, this, std::placeholders::_1);
115 _cptRender = std::bind(&Text::Render, this);
116 _cptGetCoor = std::bind(&Text::GetCoor, this);
117 _cptSetOrder = std::bind(&Text::SetOrder, this, std::placeholders::_1);
118 _cptClone = std::bind(&Text::_clone, this);
119
120 _cpt.PushBack(&_cptDeleteThis);
121 _cpt.PushBack(&_cptSetOrder);
122 _cpt.PushBack(&_cptRender);
123 _cpt.PushBack(&_cptGetCoor);
124 _cpt.PushBack(&_cptSetOrder);
125 _cpt.PushBack(&_cptClone);
126 _cpt.PushBack(&_panel);
127
128
129 _cpt.PushBack(&_cptElemData);
130 }
131 //回调
132 void _refresh_lang(std::string_view tag, std::string_view name)
133 {
134 SetString(lang(tag, name));
135 }
136
137 void _refresh_element_data()
138 {
139 SetElementData(_cptElemData._hv);
140 }
141
142};
143}
144
145#endif
void PushBack(AnyType any)
添加一个任意对象
Definition: dl_component.h:246
2d坐标系
Definition: dl_coor.h:27
元素通用属性(默认左上对齐,便于理解)
Definition: dl_component.h:362
Align::Direction2 _hv
Definition: dl_component.h:394
语言本地化
Definition: dl_component.h:354
std::array< std::string, 2 > _str
Definition: dl_component.h:356
std::function< void(std::string_view, std::string_view)> _func
Definition: dl_component.h:357
void Render()
绘制
bool SetString(std::string_view str)
设置内容
bool IsPickup()
是否被光标选中
Coor * GetCoor()
返回坐标系
Definition: dl_text.h:250
void SetOrder(float order)
设置绘制顺序
ui文本
Definition: dl_ui_text.h:26
bool IsPickup()
Definition: dl_ui_text.h:46
void Render()
Definition: dl_ui_text.h:41
Coor * GetCoor()
Definition: dl_ui_text.h:57
Components * GetCpt()
Definition: dl_ui_text.h:84
void SetOrder(float order)
设置绘制顺序
Definition: dl_ui_text.h:52
void SetLang(std::string_view tag, std::string_view name)
设置语言
Definition: dl_ui_text.h:63
void SetString(std::string_view str)
Definition: dl_ui_text.h:72
void SetElementData(const Align::Direction2 &hv)
static Text * Create(gcText txt)
Definition: dl_ui_text.h:28
Text * Clone()
复制一个,注意有些组件属性需要复制
gcText GetText()
返回文本对象,注意在大小变化后,不会更新ui的元素数据
Definition: dl_ui_text.h:81
组件系统
本地化
文本绘制
std::array< Direction, 2 > Direction2
Definition: dl_align.h:31
constexpr Direction2 LT
Definition: dl_align.h:33
constexpr float Z_DEFAULT_UI
Definition: dl_sprite.h:26
std::string_view lang(std::string_view tag, std::string_view name)
返回一个语言配置的字符串,传入 menu、start
Definition: dl_language.h:119