Files
dl_old/dltest/ui_gui.h
T
2023-12-18 00:21:53 +08:00

74 lines
1.3 KiB
C++

#pragma once
#include <dl_ui.h>
using namespace dl;
class UIGui
{
public:
UIGui()
{
_coor = Coor::Create();
// 单独使用
{
_btn = UI::ButtonTextColor::Create(
g_factory->CreateText(0, 64), {}, {});
_btn->SetString("button");
}
{
_lbx = g_ui->CreateListBoxDefault();
for (std::size_t i = 0; i < 10; ++i)
{
UI::Panel* item = _lbx->PushBackItem();
UI::Button* btn = item->GetElement<UI::Button>();
UI::ButtonSprite* btn_spr = dynamic_cast<UI::ButtonSprite*>(btn);
if (btn_spr)
btn_spr->SetString(fmt::format("lbx________________{}", i));
}
}
{
_edt = g_ui->CreateEditBoxDefault();
}
_btn->GetCoor()->SetParent(_coor);
_btn->GetCoor()->SetPosition({ 0, 0 });
_lbx->GetCoor()->SetParent(_coor);
_lbx->GetCoor()->SetPosition({ 120, 0 });
_edt->GetCoor()->SetParent(_coor);
_edt->GetCoor()->SetPosition({ 340, 0 });
}
void Update()
{
_coor->SetPosition(POS_CONTENT * g_ui->GetScale());
_coor->SetScale(g_ui->GetScale());
_btn->Update();
_lbx->Update();
_edt->Update();
}
void Render()
{
_btn->Render();
_lbx->Render();
_edt->Render();
}
~UIGui()
{
delete _edt;
delete _btn;
delete _lbx;
delete _coor;
}
private:
//! 不使用panel,单独使用
Coor* _coor;
UI::ButtonTextColor* _btn;
UI::ListBox* _lbx;
UI::EditBox* _edt;
};