# Stage 1.8.1

- Add Removable to containers (Only used for ID Objs)
- Add Counts for specific Object types to have for example multiple buttons with same name
- Readd Background as accidently deleted it
This commit is contained in:
2025-02-03 16:15:37 +01:00
parent f87c103d8d
commit f7d262b7b0
5 changed files with 49 additions and 3 deletions

View File

@ -1,8 +1,13 @@
#include <pd/common/sys.hpp>
#include <pd/ui7/container/container.hpp>
namespace PD {
namespace UI7 {
void Container::HandleScrolling(vec2 scrolling, vec4 viewport) {
if (last_use != 0 && Sys::GetTime() - last_use > 5000) {
rem = true;
}
last_use = Sys::GetTime();
pos -= vec2(0, scrolling.y());
if (!LI::Renderer::InBox(pos, size, viewport)) {
skippable = true;

View File

@ -14,7 +14,7 @@ void UI7::Menu::Label(const std::string& label) {
bool UI7::Menu::Button(const std::string& label) {
bool ret = false;
u32 id = Strings::FastHash("btn" + label);
u32 id = Strings::FastHash("btn" + label + std::to_string(count_btn++));
Container::Ref r = FindIDObj(id);
if (!r) {
r = ObjectPush(PD::New<UI7::Button>(label, Cursor(), this->back->ren));
@ -33,7 +33,7 @@ bool UI7::Menu::Button(const std::string& label) {
}
void UI7::Menu::Checkbox(const std::string& label, bool& v) {
u32 id = Strings::FastHash("cbx" + label);
u32 id = Strings::FastHash("cbx" + label + std::to_string(count_cbx++));
Container::Ref r = FindIDObj(id);
if (!r) {
r = ObjectPush(PD::New<UI7::Checkbox>(label, Cursor(), v, this->back->ren));
@ -81,7 +81,9 @@ void UI7::Menu::DebugLabels() {
void UI7::Menu::Update(float delta) {
TT::Scope st("MUPT_" + name);
for (auto& it : objects) {
std::vector<int> tbr;
for (int i = 0; i < (int)objects.size(); i++) {
auto& it = objects[i];
if (it->GetID() != 0 && !FindIDObj(it->GetID())) {
idobjs.push_back(it);
}
@ -92,6 +94,14 @@ void UI7::Menu::Update(float delta) {
it->Draw();
}
}
for (int i = 0; i < (int)idobjs.size(); i++) {
if (idobjs[i]->Removable()) {
tbr.push_back(i);
}
}
for (auto it : tbr) {
idobjs.erase(idobjs.begin() + it);
}
this->back->Process();
this->main->Process();
this->front->Process();
@ -116,6 +126,8 @@ void UI7::Menu::PreHandler(UI7MenuFlags flags) {
this->back->BaseLayer(30);
this->main->BaseLayer(40);
this->front->BaseLayer(50);
count_btn = 0;
count_cbx = 0;
Cursor(vec2(5, 5));
this->flags = flags;
this->scrolling[0] = flags & UI7MenuFlags_HzScrolling;