* ui系统完善

This commit is contained in:
2023-09-21 21:01:22 +08:00
parent e15ec110b7
commit 08c216bbfc
10 changed files with 99 additions and 17 deletions
+11
View File
@@ -241,6 +241,16 @@ public:
VectorAny& GetVectorAny() { return _vec; }
std::string GetName()
{
return _name;
}
//! 设置自定义名字
void SetName(std::string_view name)
{
_name = name;
}
private:
VectorAny _vec;
AnyType _any;
@@ -291,6 +301,7 @@ namespace Cpt
using Render = Function<std::function<void()>, str_uid("Render")>;//!< 绘制
using SetOrder = Function<std::function<void(float)>, str_uid("SetOrder")>;//!< 设置order
using DeleteThis = Function<std::function<void()>, str_uid("DeleteThis")>;//!< 删除自身
using Clone = Function<std::function<Components*()>, str_uid("Clone")>;//!< 克隆
//! 语言本地化
class Lang
+2
View File
@@ -210,4 +210,6 @@ private:
void _update_radio();
};
using ButtonMode = ButtonBase::Mode;
}
+1
View File
@@ -88,6 +88,7 @@ public:
{
_bg->SetOrder(order);
//_sprOver->SetOrder(Math::OffsetOrder(order, 0, 0, -2));
_item->SetOrder(Math::OffsetOrder(order, 0, 0, -1));
for (Panel* panel : _allItem)
{
panel->SetOrder(Math::OffsetOrder(order, 0, 0, -1));
+5
View File
@@ -74,6 +74,11 @@ dl::Locator::SL Manager::CreateLocator(std::string_view name)
return iter->second;
}
dl::UI::Text* Manager::CreateTextDefault()
{
return UI::Text::Create(g_factory->CreateTextDefault());
}
MsgBox* Manager::CreateMsgBoxDefault()
{
Background* bg = CreateBackgroundDefault();
+3 -3
View File
@@ -98,7 +98,7 @@ public:
CLOSE,
};
UI::Text* CreateTextDefault();
MsgBox* CreateMsgBoxDefault();
ButtonSprite* CreateButtonSpriteDefault(ButtonStyle style = ButtonStyle::NORMAL);
Background* CreateBackgroundDefault();
@@ -142,7 +142,7 @@ public:
* @brief Components克隆
* @note 由于类型信息丢失,只能枚举克隆
*/
Components* CloneCpt(Components* cpt)
/*Components* CloneCpt(Components* cpt)
{
if (auto p = cpt->Cast<UI::Text>())
return p->Clone()->GetCpt();
@@ -150,7 +150,7 @@ public:
return p->Clone()->GetCpt();
assert(0);
return nullptr;
}
}*/
/**
* @brief 绘制调试信息
+9 -2
View File
@@ -107,7 +107,8 @@ Panel* Panel::Clone()
ret->_coor = Coor::Create();
ret->_node = node;
ret->_bg = _bg->Clone();
if(_bg)
ret->_bg = _bg->Clone();
for (Panel* panel : _child)
{
@@ -115,7 +116,13 @@ Panel* Panel::Clone()
}
for (Components* cpt : _ele)
{
ret->_ele.push_back(g_ui->CloneCpt(cpt));
Cpt::Clone* comp = cpt->Get<Cpt::Clone>();
if (!comp)
{
log_err("可复制panel的元素必须包含Clone组件!");
continue;
}
ret->_ele.push_back(comp->Call());
}
return ret;
}
+25 -3
View File
@@ -132,7 +132,7 @@ public:
* @brief 返回被点击的元素
* @retval 没有返回-1
*/
size_t GetIndexCilck()
size_t GetClickIndex()
{
size_t i = 0;
for (auto& iter : _ele)
@@ -147,6 +147,29 @@ public:
return -1;
}
/**
* @brief 返回被选中的元素
* @retval 没有返回-1
*/
Components* GetSelect()
{
for (auto& iter : _ele)
{
if (auto cpt = iter->Get<Cpt::IsOpen>())
{
if (cpt->Call())
return iter;
}
}
return nullptr;
}
std::string GetSelectName()
{
Components* cpt = GetSelect();
return cpt ? cpt->GetName() : "";
}
/**
* @brief index元素是否open状态
* @retval 失败返回false,并输出日志
@@ -188,8 +211,7 @@ public:
//! 返回第一个text
UI::Text* GetText()
{
//Cpt::Get(_ele)
return nullptr;
return Cpt::GetFirst<UI::Text>(_ele);
}
//! 是否被鼠标选中
+9
View File
@@ -123,9 +123,15 @@ private:
Cpt::GetCoor _cptGetCoor;
Cpt::Lang _cptLang;
Cpt::ElementData _cptElemData;
Cpt::Clone _cptClone;
void _delete_this() { delete this; }
Components* _clone()
{
return Clone()->GetCpt();
}
void _init_cpt()
{
_cptDeleteThis = std::bind(&Text::_delete_this, this);
@@ -133,12 +139,15 @@ private:
_cptRender = std::bind(&Text::Render, this);
_cptGetCoor = std::bind(&Text::GetCoor, this);
_cptSetOrder = std::bind(&Text::SetOrder, this, std::placeholders::_1);
_cptClone = std::bind(&Text::_clone, this);
_cpt.PushBack(&_cptDeleteThis);
_cpt.PushBack(&_cptSetOrder);
_cpt.PushBack(&_cptRender);
_cpt.PushBack(&_cptGetCoor);
_cpt.PushBack(&_cptSetOrder);
_cpt.PushBack(&_cptClone);
_cpt.PushBack(&_cptElemData);
}
+1 -1
View File
@@ -90,7 +90,7 @@ void Run()
g_gfx->Triangle({ 400, 10, 0 }, { 10, 500, 0 }, { 750, 550, 0 });
g_gfx->TriangleSolid({ 0, 0, 0 }, { 100, 0, 0 }, { 10, 250, 0 });
g_gfx->Love();
//g_gfx->Love();
base->spr9->Render();
}
+33 -8
View File
@@ -29,8 +29,15 @@ public:
_panel->Add(txt->GetCpt());
}
std::array menu = {
"gfx", "sprite", "text"
};
for(auto& iter : menu)
{
UI::ButtonSprite* btn = g_ui->CreateButtonSpriteDefault();
btn->GetCpt()->SetName(iter);
btn->SetMode(UI::ButtonMode::RADIO);
btn->SetString(iter);
_panel->Add(btn->GetCpt());
}
@@ -44,22 +51,40 @@ public:
{
UI::Background* bg = g_ui->CreateBackgroundDefault();
UI::Panel* panel = g_ui->CreatePanel();
{
UI::Text* txt = g_ui->CreateTextDefault();
panel->Add(txt->GetCpt());
}
_lbx = UI::ListBox::Create(bg, panel);
UI::Panel* item = _lbx->PushBackItem();
UI::Text* txt = item->GetText();
if(txt)
txt->SetString("lbx0");
for (std::size_t i = 0; i < 10; ++i)
{
UI::Panel* item = _lbx->PushBackItem();
UI::Text* txt = item->GetText();
if (txt)
txt->SetString(fmt::format("lbx________________{}", i));
}
}
}
void Run()
{
_btn->Update();
_lbx->Update();
std::string name = _panel->GetSelectName();
if (name.empty())
{
_btn->Update();
_lbx->Update();
_btn->Render();
_lbx->Render();
_btn->Render();
_lbx->Render();
}
else if (name == "gfx")
{
}
}
~UIMain()
{