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{
24public:
25 virtual void Update()
26 {
27 _panel->Update();
28 }
29
30 void Render()
31 { }
32
33 bool IsPickup()
34 {
35 return _panel->IsPickup();
36 }
37
39 {
40 return _btnClose && _btnClose->IsClick();
41 }
42
44 void SetOrder(float order)
45 {
46 _panel->SetOrder(order);
47 if (_bg)
48 _bg->SetOrder(Math::OffsetOrder(order, 0, 0, 1));
49 if (_btnClose)
50 _btnClose->SetOrder(Math::OffsetOrder(order, 0, 0, -2));
51 }
52
53
55 void SetSize(const Position& size)
56 {
57 _panel->SetSize(size);
58 _cptElemData._size = size;
59 }
60
61 void Center()
62 {
63 _panel->SetPosScale({ 0.5f, 0.5f });
64 _panel->SetAlign(Align::CC);
65 }
66
68 {
69 if (_bg)
70 _panel->Del(_bg);
71
72 _panel->Add(bg);
73 _bg = bg;
74 _bg->SetSize(_panel->GetSize());
75 _drag._bControlPanel = true;
76 _bg->GetCpt()->PushBack(&_drag);
77
78 _refresh_order_bg(_panel->GetOrder());
79 }
81 {
82 if (_btnClose)
83 _panel->Del(_btnClose);
84
85 _panel->Add(btn);
86 _btnClose = btn;
87
88 _refresh_order_btn_close(_panel->GetOrder());
89 }
90
91
92 Coor* GetCoor() { return _panel->GetCoor(); }
93
95 { }
96
97 UI::Panel* GetPanel() { return _panel; }
98
99 Components* GetCpt() { return &_cpt; }
100
101
102 virtual ~Window();
103protected:
105 _cpt{ this },
106 _bg{ nullptr },
107 _btnClose{ nullptr }
108 {
109 _init_cpt();
110 _init();
111 }
113private:
114 Background* _bg;
115 Button* _btnClose;
116 Cpt::Drag _drag;
117
118 Components _cpt;
119 Cpt::DeleteThis _cptDeleteThis;
120 Cpt::SetOrder _cptSetOrder;
121 Cpt::Update _cptUpdate;
122 Cpt::Render _cptRender;
123 Cpt::GetCoor _cptGetCoor;
124 Cpt::RenderDebug _cptRenderDebug;
125 Cpt::ElementData _cptElemData;
126
127 void _delete_this() { delete this; }
128
129 void _init_cpt()
130 {
131 _cptDeleteThis = std::bind(&Window::_delete_this, this);
132 _cptSetOrder = std::bind(&Window::SetOrder, this, std::placeholders::_1);
133 _cptUpdate = std::bind(&Window::Update, this);
134 _cptRender = std::bind(&Window::Render, this);
135 _cptGetCoor = std::bind(&Window::GetCoor, this);
136 _cptRenderDebug = std::bind(&Window::RenderDebug, this);
137
138 _cpt.PushBack(&_cptDeleteThis);
139 _cpt.PushBack(&_cptSetOrder);
140 _cpt.PushBack(&_cptUpdate);
141 _cpt.PushBack(&_cptRender);
142 _cpt.PushBack(&_cptGetCoor);
143 _cpt.PushBack(&_cptRenderDebug);
144
145 _cpt.PushBack(&_cptElemData);
146 }
147
148 void _init();
149
150 void _refresh_order_bg(float order)
151 {
152 if (_bg)
153 _bg->SetOrder(Math::OffsetOrder(order, 0, 0, 1));
154
155 }
156 void _refresh_order_btn_close(float order)
157 {
158 if (_btnClose)
159 _btnClose->SetOrder(Math::OffsetOrder(order, 0, 0, -2));
160 }
161};
162}
163
164#endif
void PushBack(AnyType any)
添加一个任意对象
2d坐标系
元素通用属性(默认左上对齐,便于理解)
void SetSize(const Position &size)
设置大小,若设置了填充属性,则作为额外大小使用
void SetOrder(float order)
按钮(Button、Switch、Radio)
virtual void SetOrder(float order)=0
virtual void Update()
void SetButtonClose(UI::Button *btn)
void SetBackground(UI::Background *bg)
UI::Panel * GetPanel()
Components * GetCpt()
virtual ~Window()
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