dl
dl_ui_window.h
浏览该文件的文档.
1
12#pragma once
13
14#ifndef DL_DISABLE_RENDER
16#include "ui/dl_ui_background.h"
17#include "ui/dl_ui_panel.h"
18
19namespace dl::UI
20{
22class Window
23{
24 friend class Manager;
25public:
30 virtual void Update()
31 {
32 if (!_bVisible)
33 return;
34 _panel->Update();
35 }
36
37 void Render()
38 { }
39
40 template<typename T>
42 {
43 return dynamic_cast<T*>(this);
44 }
45
46 bool IsPickup()
47 {
48 return _panel->IsPickup();
49 }
50
52 {
53 return _btnClose && _btnClose->IsClick();
54 }
55
56 float GetOrder() { return _panel->GetOrder(); }
57
59 void SetOrder(float order)
60 {
61 _panel->SetOrder(order);
62 if (_bg)
63 _bg->SetOrder(Math::OffsetOrder(order, 0, 0, 1));
64 if (_btnClose)
65 _btnClose->SetOrder(Math::OffsetOrder(order, 0, 0, -2));
66 }
67
69 void SetSize(const Position& size)
70 {
71 _panel->SetSize(size);
72 _cptElemData._size = size;
73 }
74
75 void Center()
76 {
77 _panel->SetPosScale({ 0.5f, 0.5f });
78 _panel->SetAlign(Align::CC);
79 }
80
86 void SetBackground(UI::Background* bg, bool auto_size = true);
87
88 UI::Background* GetBackground() { return _bg; }
89
95 UI::Button* GetButtonClose() { return _btnClose; }
96
102 void SetVisible(bool visible);
103 bool IsVisible() { return _bVisible; }
104
105
106 // 进入窗口管理器后有效
107 //void SetWindowFlag(std::string_view flag) { _flag = std::string{ flag }; }
108 void SetWindowCache(bool cache) { _bCache = cache; }
109 void SetWindowModal(bool modal) { _bModal = modal; }
110
111 Panel* GetPanel() { return _panel; }
112 Coor* GetCoor() { return _panel->GetCoor(); }
113
115 { }
116
120 void ExFastSet();
121
122 Components* GetCpt() { return &_cpt; }
123
124
125 virtual ~Window();
126protected:
128 _cpt{ this },
129 _bg{ nullptr },
130 _btnClose{ nullptr },
131 _bCache{ false },
132 _bModal{ false },
133 _bVisible{ true },
134 _bInManager{ false }
135 {
136 _init_cpt();
137 _init();
138 }
140private:
141 std::string _name; // 唯一名字(管理器内,同名字窗口显示会顶掉,空表示独立窗口)
142 bool _bCache; // 缓存窗口(提高显示速度)
143 bool _bModal; // 模态窗口(用户必须先处理自己,不会被顶掉)
144 bool _bVisible; // 是否可见
145 bool _bInManager; // 是否由g_ui管理
146
147 Background* _bg;
148 Button* _btnClose;
149 Cpt::Drag _drag;
150
151 Components _cpt;
152 Cpt::DeleteThis _cptDeleteThis;
153 Cpt::SetOrder _cptSetOrder;
154 Cpt::Update _cptUpdate;
155 Cpt::Render _cptRender;
156 Cpt::GetCoor _cptGetCoor;
157 Cpt::RenderDebug _cptRenderDebug;
158 Cpt::ElementData _cptElemData;
159
160 void _delete_this() { delete this; }
161
162 void _init_cpt()
163 {
164 _cptDeleteThis = std::bind(&Window::_delete_this, this);
165 _cptSetOrder = std::bind(&Window::SetOrder, this, std::placeholders::_1);
166 _cptUpdate = std::bind(&Window::Update, this);
167 _cptRender = std::bind(&Window::Render, this);
168 _cptGetCoor = std::bind(&Window::GetCoor, this);
169 _cptRenderDebug = std::bind(&Window::RenderDebug, this);
170
171 _cpt.PushBack(&_cptDeleteThis);
172 _cpt.PushBack(&_cptSetOrder);
173 _cpt.PushBack(&_cptUpdate);
174 _cpt.PushBack(&_cptRender);
175 _cpt.PushBack(&_cptGetCoor);
176 _cpt.PushBack(&_cptRenderDebug);
177
178 _cpt.PushBack(&_cptElemData);
179 }
180
181 void _init();
182
183 void _refresh_order_bg(float order)
184 {
185 if (_bg)
186 _bg->SetOrder(Math::OffsetOrder(order, 0, 0, 1));
187
188 }
189 void _refresh_order_btn_close(float order)
190 {
191 if (_btnClose)
192 _btnClose->SetOrder(Math::OffsetOrder(order, 0, 0, -2));
193 }
194};
195}
196
197#endif
void PushBack(AnyType any)
添加一个任意对象
2d坐标系
元素通用属性(默认左上对齐,便于理解)
void SetOrder(float order)
按钮(Button、Switch、Radio)
virtual void SetOrder(float order)=0
UI::Background * GetBackground()
virtual void Update()
帧函数 @info 子类重载后,需要调用 Window::Update()
void ExFastSet()
快速初始化到一般的样式,可作为用法参考
void SetWindowCache(bool cache)
void SetButtonClose(UI::Button *btn)
设置关闭按钮
void SetVisible(bool visible)
设置是否显示
UI::Button * GetButtonClose()
void SetBackground(UI::Background *bg, bool auto_size=true)
设置背景
void SetWindowModal(bool modal)
Components * GetCpt()
virtual ~Window()
friend class Manager
void SetSize(const Position &size)
设置大小
void SetOrder(float order)
设置绘制顺序
组件实例
作为绘图背景
ui之panel
constexpr Direction2 CC
Function< std::function< void(float)>, str_uid("SetOrder")> SetOrder
设置order
Function< std::function< void()>, str_uid("RenderD")> RenderDebug
调试绘图
Function< std::function< dl::Coor *()>, str_uid("GetCoor")> GetCoor
返回坐标系
Function< std::function< void()>, str_uid("Render")> Render
绘制
Function< std::function< void()>, str_uid("DeleteThis")> DeleteThis
删除自身
Function< std::function< void()>, str_uid("Update")> Update
逻辑
constexpr float OffsetOrder(float order, int u=1, int v=0, int w=0)
偏移order
Position2 Position