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"
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;
32 ret->_txt->SetUI(true);
35 return ret;
36 }
37
40 Text* Clone();
41
42 void Render()
43 {
44 _txt->Render();
45 }
46
47 bool IsPickup()
48 {
49 return _txt->IsPickup();
50 }
51
53 void SetOrder(float order)
54 {
55 _txt->SetOrder(order);
56 }
57
58 Coor* GetCoor() { return _txt->GetCoor(); }
59
64 void SetLang(std::string_view tag, std::string_view name)
65 {
66 _cptLang._str = { std::string{tag}, std::string{name} };
67 _cptLang._func = std::bind(&Text::_refresh_lang, this, std::placeholders::_1, std::placeholders::_2);
68 _cpt.PushBack(&_cptLang);
69
70 _refresh_lang(tag, name);
71 }
72
73 void SetString(std::string_view str)
74 {
75 if(_txt->SetString(str))
76 _refresh_element_data();
77 }
78
83 gcText GetText() { return _txt; }
84
85 void SetElementData(const Align::Direction2& hv, const Position& pos = {});
86
87
88 Components* GetCpt() { return &_cpt; }
89private:
90 Text() :
91 _panel{ nullptr },
92 _cpt{ this }
93 {
94 _init_cpt();
95 }
96
97 Panel* _panel;
98 gcText _txt;
99 Components _cpt;
100 Cpt::DeleteThis _cptDeleteThis;
101 Cpt::SetOrder _cptSetOrder;
102 Cpt::IsPickup _cptIsPickup;
103 Cpt::Render _cptRender;
104 Cpt::GetCoor _cptGetCoor;
105 Cpt::Lang _cptLang;
106 Cpt::ElementData _cptElemData;
107 Cpt::Clone _cptClone;
108
109 void _delete_this() { delete this; }
110
111 Components* _clone()
112 {
113 return Clone()->GetCpt();
114 }
115
116 void _init_cpt()
117 {
118 _cptDeleteThis = std::bind(&Text::_delete_this, this);
119 _cptSetOrder = std::bind(&Text::SetOrder, this, std::placeholders::_1);
120 _cptIsPickup = std::bind(&Text::IsPickup, this);
121 _cptRender = std::bind(&Text::Render, this);
122 _cptGetCoor = std::bind(&Text::GetCoor, this);
123 _cptSetOrder = std::bind(&Text::SetOrder, this, std::placeholders::_1);
124 _cptClone = std::bind(&Text::_clone, this);
125
126 _cpt.PushBack(&_cptDeleteThis);
127 _cpt.PushBack(&_cptSetOrder);
128 _cpt.PushBack(&_cptIsPickup);
129 _cpt.PushBack(&_cptRender);
130 _cpt.PushBack(&_cptGetCoor);
131 _cpt.PushBack(&_cptSetOrder);
132 _cpt.PushBack(&_cptClone);
133 _cpt.PushBack(&_panel);
134
135
136 _cpt.PushBack(&_cptElemData);
137 }
138 //回调
139 void _refresh_lang(std::string_view tag, std::string_view name)
140 {
141 SetString(lang(tag, name));
142 }
143
144 void _refresh_element_data()
145 {
146 SetElementData(_cptElemData._hv, _cptElemData._pos);
147 }
148
149};
150}
151
152#endif
2d坐标系
元素通用属性(默认左上对齐,便于理解)
void SetUI(bool ui)
设置是否是ui(影响穿透)
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, const Position &pos={})
static Text * Create(gcText txt)
Text * Clone()
复制一个,注意有些组件属性需要复制
gcText GetText()
返回文本对象,注意在大小变化后,不会更新ui的元素数据
组件实例
本地化
文本绘制
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
克隆
Position2 Position
std::string_view lang(std::string_view tag_name)
返回一个语言配置的字符串,传入 menu.start
constexpr float Z_DEFAULT_UI
GC< Text > gcText