# 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:
tobid7 2025-02-03 16:15:37 +01:00
parent f87c103d8d
commit f7d262b7b0
5 changed files with 49 additions and 3 deletions

View File

@ -28,6 +28,7 @@ class Container : public SmartCtor<Container> {
vec2 GetSize() { return size; }
bool Skippable() const { return skippable; }
bool Removable() const { return rem; }
void HandleScrolling(vec2 scrolling, vec4 viewport);
virtual void HandleInput(Hid::Ref inp) {}
@ -41,6 +42,8 @@ class Container : public SmartCtor<Container> {
protected:
/// used to skip Input/Render preocessing ot not
bool skippable = false;
bool rem = false;
u64 last_use = 0;
bool inp_done = false;
Screen::Ref screen;
vec2 pos;

View File

@ -140,6 +140,8 @@ class Menu : public SmartCtor<Menu> {
std::vector<Container::Ref> objects;
std::vector<Container::Ref> idobjs;
std::vector<Container*> join;
int count_btn = 0;
int count_cbx = 0;
// DrawLists
DrawList::Ref back;

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;

View File

@ -102,6 +102,30 @@ class Test : public PD::App {
void Deinit() override {}
void DrawFancyBG(float time) {
ren->DrawRect(vec2(0, 0), vec2(400, 240), 0xff64c9fd);
for (int i = 0; i < 44; i++) Append(i, vec2(0, 0), vec2(400, 240), time);
}
float Offset(float x) {
float y = cos(x) * 42;
return y - floor(y);
}
void Append(int index, vec2 position, vec2 size, float time) {
float offset = Offset(index) * 62;
float x_position = position.x() + size.x() / 8 * ((index % 11) - 1) +
cos(offset + time) * 10;
float y_position = position.y() + size.y() / 8 * (index / 11) + 40 +
sin(offset + time) * 10 + 30;
float color_effect = 1 - exp(-(index / 11) / 3.0f);
ren->DrawTriangle(
vec2(x_position, y_position), vec2(x_position + 300, y_position + (90)),
vec2(x_position - 300, y_position + (90)),
PD::Color(.94f - .17f * color_effect, .61f - .25f * color_effect,
.36f + .38f * color_effect));
}
private:
/// Shorter Acess to Renderer / Input
PD::LI::Renderer::Ref ren;