Fix The rest of UI7 Mem leaks
Throw OneFrame living objs into a pool
This commit is contained in:
@@ -111,6 +111,25 @@ class PD_API Container {
|
||||
virtual void Draw() {}
|
||||
/** Template function to update internal data (if needed) */
|
||||
virtual void Update() {}
|
||||
/** Template as well as base func for Pool based Containers */
|
||||
virtual void Reset() {
|
||||
pos = 0;
|
||||
size = 0;
|
||||
parent = nullptr;
|
||||
id = 0;
|
||||
pFlags = 0;
|
||||
skippable = false;
|
||||
rem = false;
|
||||
inp_done = false;
|
||||
pSelected = false;
|
||||
pPressed = false;
|
||||
pPressedTwice = false;
|
||||
pCLipRectUsed = false;
|
||||
pClipRect = 0;
|
||||
io = nullptr;
|
||||
list = nullptr;
|
||||
last_use = 0;
|
||||
}
|
||||
|
||||
/** Internal function */
|
||||
void PreDraw();
|
||||
|
||||
@@ -38,6 +38,7 @@ namespace UI7 {
|
||||
*/
|
||||
class PD_API DynObj : public Container {
|
||||
public:
|
||||
DynObj() {}
|
||||
/**
|
||||
* Button Object constructor
|
||||
* @param label Label of the Button
|
||||
@@ -69,6 +70,14 @@ class PD_API DynObj : public Container {
|
||||
/** Function to Update Size if framepadding changes */
|
||||
void Update() override;
|
||||
|
||||
void Reset() override {
|
||||
Container::Reset();
|
||||
color = UI7Color_Button;
|
||||
pressed = false;
|
||||
pRenFun = nullptr;
|
||||
pInp = nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
UI7Color color = UI7Color_Button; ///< current button color
|
||||
bool pressed = false; ///< ispressed value
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace UI7 {
|
||||
*/
|
||||
class PD_API Image : public Container {
|
||||
public:
|
||||
Image() {}
|
||||
/**
|
||||
* Constructor for the Image Object
|
||||
* @param img Image Texture Reference
|
||||
@@ -57,6 +58,13 @@ class PD_API Image : public Container {
|
||||
* */
|
||||
void Draw() override;
|
||||
|
||||
void Reset() override {
|
||||
Container::Reset();
|
||||
img = Li::Texture();
|
||||
newsize = 0.f;
|
||||
cuv = Li::Rect();
|
||||
}
|
||||
|
||||
private:
|
||||
Li::Texture img; ///< Texture
|
||||
fvec2 newsize = 0.f; ///< New Size
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace UI7 {
|
||||
*/
|
||||
class PD_API Label : public Container {
|
||||
public:
|
||||
Label() {}
|
||||
/**
|
||||
* Constructor for Label Object
|
||||
* @param label Label [Text] to Draw
|
||||
@@ -54,6 +55,13 @@ class PD_API Label : public Container {
|
||||
*/
|
||||
void Update() override;
|
||||
|
||||
void Reset() override {
|
||||
Container::Reset();
|
||||
tdim = 0;
|
||||
color = UI7Color_Text;
|
||||
label.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
fvec2 tdim; ///< Text Size
|
||||
UI7Color color = UI7Color_Text; ///< Color
|
||||
|
||||
+10
-7
@@ -31,16 +31,14 @@ SOFTWARE.
|
||||
#include <pd/ui7/viewport.hpp>
|
||||
|
||||
namespace PD {
|
||||
class Context;
|
||||
namespace UI7 {
|
||||
class Label;
|
||||
class Image;
|
||||
class DynObj;
|
||||
class PD_API IO {
|
||||
public:
|
||||
IO() : DeltaStats(60), CurrentViewPort("", 0) {
|
||||
/** Probably not the best solution i guess */
|
||||
// CurrentViewPort =
|
||||
// ViewPort::New("Default", ivec4(ivec2(0, 0), pCtx.Gfx()->ViewPort));
|
||||
}
|
||||
~IO() {}
|
||||
IO();
|
||||
~IO();
|
||||
|
||||
/**
|
||||
* IO Update Internal Variables
|
||||
@@ -84,6 +82,11 @@ class PD_API IO {
|
||||
u32 NumIndices = 0; ///< Debug Indices Num
|
||||
std::vector<u32> MenuOrder;
|
||||
|
||||
// Pools
|
||||
PD::Pool<UI7::Label> LabelPool;
|
||||
PD::Pool<UI7::Image> ImagePool;
|
||||
PD::Pool<UI7::DynObj> DynObjPool;
|
||||
|
||||
// DrawlistApi
|
||||
void RegisterDrawlist(const UI7::ID& id, Li::Drawlist* v) {
|
||||
DrawlistRegestry.push_back(std::make_pair(id, v));
|
||||
|
||||
@@ -53,17 +53,18 @@ PD_API void ColorEdit::Draw() {
|
||||
layout = new UI7::Layout(GetID(), *io);
|
||||
}
|
||||
layout->SetPosition(FinalPos());
|
||||
layout->AddObjectEx(
|
||||
new DynObj([=, this](UI7::IO* io, Li::Drawlist* l, Container* thiz) {
|
||||
DynObj* r = io->DynObjPool.Allocate();
|
||||
*r = UI7::DynObj([=, this](UI7::IO* io, Li::Drawlist* l, Container* thiz) {
|
||||
thiz->SetSize(layout->GetSize());
|
||||
// l->Layer(30);
|
||||
l->PathRect(thiz->GetPos(), thiz->GetPos() + thiz->GetSize(),
|
||||
io->FrameRounding);
|
||||
l->PathFill(io->Theme.Get(UI7Color_FrameBackground));
|
||||
}),
|
||||
UI7LytAdd_Front | UI7LytAdd_NoCursorUpdate | UI7LytAdd_NoScrollHandle);
|
||||
auto obj =
|
||||
new DynObj([=, this](UI7::IO* io, Li::Drawlist* l, Container* thiz) {
|
||||
});
|
||||
layout->AddObjectEx(r, UI7LytAdd_Front | UI7LytAdd_NoCursorUpdate |
|
||||
UI7LytAdd_NoScrollHandle);
|
||||
r = io->DynObjPool.Allocate();
|
||||
*r = UI7::DynObj([=, this](UI7::IO* io, Li::Drawlist* l, Container* thiz) {
|
||||
l->PathRect(thiz->FinalPos(), thiz->FinalPos() + io->ItemRowHeight,
|
||||
io->FrameRounding);
|
||||
l->PathFill(*color_ref);
|
||||
@@ -71,8 +72,8 @@ PD_API void ColorEdit::Draw() {
|
||||
thiz->FinalPos() + fvec2(io->ItemSpace.x + io->ItemRowHeight, 0),
|
||||
label.c_str(), io->Theme.Get(UI7Color_Text));
|
||||
});
|
||||
obj->SetSize(PD::fvec2(200, io->ItemRowHeight));
|
||||
layout->AddObject(obj);
|
||||
r->SetSize(PD::fvec2(200, io->ItemRowHeight));
|
||||
layout->AddObject(r);
|
||||
layout->Label("RGBA: ({}, {}, {}, {})", *((u8*)color_ref),
|
||||
*(((u8*)color_ref) + 1), *(((u8*)color_ref) + 2),
|
||||
*(((u8*)color_ref) + 3));
|
||||
|
||||
@@ -23,9 +23,22 @@ SOFTWARE.
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/drivers/drivers.hpp>
|
||||
#include <pd/ui7/containers.hpp>
|
||||
#include <pd/ui7/io.hpp>
|
||||
|
||||
namespace PD {
|
||||
|
||||
PD_API UI7::IO::IO() : DeltaStats(60), CurrentViewPort("", 0) {
|
||||
/** Probably not the best solution i guess */
|
||||
// CurrentViewPort =
|
||||
// ViewPort::New("Default", ivec4(ivec2(0, 0), pCtx.Gfx()->ViewPort));
|
||||
// Start a little larger on these
|
||||
LabelPool.Init(512);
|
||||
DynObjPool.Init(512);
|
||||
}
|
||||
|
||||
PD_API UI7::IO::~IO() {}
|
||||
|
||||
PD_API void UI7::IO::Update() {
|
||||
/** Todo: find out if we even still use the Drawlist regestry */
|
||||
u64 current = PD::Os::GetTimeNano();
|
||||
@@ -41,5 +54,8 @@ PD_API void UI7::IO::Update() {
|
||||
// RegisterDrawList("CtxBackList", Back);
|
||||
NumIndices = 0; // FDL.pNumIndices;
|
||||
NumVertices = 0; // FDL.pNumVertices;
|
||||
LabelPool.ResetFast();
|
||||
DynObjPool.ResetFast();
|
||||
ImagePool.ResetFast();
|
||||
}
|
||||
} // namespace PD
|
||||
@@ -161,7 +161,8 @@ PD_API void Layout::Update() {
|
||||
|
||||
PD_API void Layout::Label(const std::string& label) {
|
||||
// Layout API
|
||||
auto r = new UI7::Label(label, IO);
|
||||
auto r = IO.LabelPool.Allocate();
|
||||
*r = UI7::Label(label, IO);
|
||||
r->SetClipRect(fvec4(GetPosition(), GetPosition() + GetSize()));
|
||||
AddObject(r);
|
||||
}
|
||||
@@ -192,7 +193,8 @@ PD_API void Layout::Checkbox(const std::string& label, bool& v) {
|
||||
}
|
||||
|
||||
PD_API void Layout::Image(Li::Texture img, fvec2 size, Li::Rect uv) {
|
||||
Container* r = new UI7::Image(img, size, uv);
|
||||
auto r = IO.ImagePool.Allocate();
|
||||
*r = UI7::Image(img, size, uv);
|
||||
AddObject(r);
|
||||
}
|
||||
|
||||
|
||||
+19
-12
@@ -36,7 +36,8 @@ Menu::Menu(const ID& id, IO& io) : pIO(io), pID(id), pLayout(id, io) {
|
||||
|
||||
PD_API void Menu::Label(const std::string& label) {
|
||||
// Layout API
|
||||
auto r = new UI7::Label(label, pIO);
|
||||
auto r = pIO.LabelPool.Allocate();
|
||||
*r = UI7::Label(label, pIO);
|
||||
pLayout.AddObject(r);
|
||||
}
|
||||
|
||||
@@ -68,7 +69,8 @@ PD_API void Menu::Checkbox(const std::string& label, bool& v) {
|
||||
}
|
||||
|
||||
PD_API void Menu::Image(Li::Texture img, fvec2 size, Li::Rect uv) {
|
||||
Container* r = new UI7::Image(img, size, uv);
|
||||
auto r = pIO.ImagePool.Allocate();
|
||||
*r = UI7::Image(img, size, uv);
|
||||
pLayout.AddObject(r);
|
||||
}
|
||||
|
||||
@@ -84,8 +86,9 @@ PD_API void Menu::ColorEdit(const std::string& label, u32& clr) {
|
||||
|
||||
PD_API void Menu::Separator() {
|
||||
// Dynamic Objects are very simple...
|
||||
Container* r =
|
||||
new DynObj([=, this](UI7::IO* io, Li::Drawlist* l, UI7::Container* self) {
|
||||
DynObj* r = pIO.DynObjPool.Allocate();
|
||||
*r = UI7::DynObj(
|
||||
[=, this](UI7::IO* io, Li::Drawlist* l, UI7::Container* self) {
|
||||
l->DrawRectFilled(self->FinalPos(), self->GetSize(),
|
||||
pIO.Theme.Get(UI7Color_TextDead));
|
||||
});
|
||||
@@ -98,7 +101,8 @@ PD_API void Menu::Separator() {
|
||||
|
||||
PD_API void Menu::SeparatorText(const std::string& label) {
|
||||
// Also note to use [=] instead of [&] to not undefined access label
|
||||
Container* r = new DynObj([=, this](UI7::IO* io, Li::Drawlist* l,
|
||||
DynObj* r = pIO.DynObjPool.Allocate();
|
||||
*r = UI7::DynObj([=, this](UI7::IO* io, Li::Drawlist* l,
|
||||
UI7::Container* self) {
|
||||
fvec2 size = self->GetSize();
|
||||
fvec2 tdim = io->Font->GetTextBounds(label.c_str(), io->FontScale);
|
||||
@@ -251,8 +255,8 @@ PD_API void Menu::DrawBaseLayout() {
|
||||
if (pIsOpen) {
|
||||
/** Resize Sym (Render on Top of Everything) */
|
||||
if (!(Flags & UI7MenuFlags_NoResize)) {
|
||||
Container* r =
|
||||
new DynObj([](IO* io, Li::Drawlist* l, UI7::Container* self) {
|
||||
DynObj* r = pIO.DynObjPool.Allocate();
|
||||
*r = UI7::DynObj([](IO* io, Li::Drawlist* l, UI7::Container* self) {
|
||||
// //l->Layer(1);
|
||||
l->PathAdd(self->FinalPos() + self->GetSize() - fvec2(0, 20));
|
||||
l->PathAdd(self->FinalPos() + self->GetSize());
|
||||
@@ -267,8 +271,8 @@ PD_API void Menu::DrawBaseLayout() {
|
||||
}
|
||||
|
||||
/** Background */
|
||||
Container* r = new DynObj([](IO* io, Li::Drawlist* l,
|
||||
UI7::Container* self) {
|
||||
DynObj* r = pIO.DynObjPool.Allocate();
|
||||
*r = UI7::DynObj([](IO* io, Li::Drawlist* l, UI7::Container* self) {
|
||||
// l->Layer(0);
|
||||
l->PathRectEx(self->FinalPos(), self->FinalPos() + self->GetSize(), 10.f,
|
||||
LiPathRectFlags_KeepTop | LiPathRectFlags_KeepBot);
|
||||
@@ -284,7 +288,8 @@ PD_API void Menu::DrawBaseLayout() {
|
||||
UI7LytAdd_Front);
|
||||
}
|
||||
if (!(Flags & UI7MenuFlags_NoTitlebar)) {
|
||||
Container* r = new DynObj(
|
||||
DynObj* r = pIO.DynObjPool.Allocate();
|
||||
*r = UI7::DynObj(
|
||||
[=, this](UI7::IO* io, Li::Drawlist* l, UI7::Container* self) {
|
||||
// l->Layer(20);
|
||||
/** Header Bar */
|
||||
@@ -307,7 +312,8 @@ PD_API void Menu::DrawBaseLayout() {
|
||||
|
||||
/** Collapse Sym */
|
||||
if (!(Flags & UI7MenuFlags_NoCollapse)) {
|
||||
r = new DynObj([=, this](UI7::IO* io, Li::Drawlist* l,
|
||||
DynObj* r = pIO.DynObjPool.Allocate();
|
||||
*r = UI7::DynObj([=, this](UI7::IO* io, Li::Drawlist* l,
|
||||
UI7::Container* self) {
|
||||
/** This sym actually requires layer 21 (i dont know why) */
|
||||
// l->Layer(21);
|
||||
@@ -383,7 +389,8 @@ PD_API bool Menu::BeginTreeNode(const ID& id) {
|
||||
}
|
||||
|
||||
// Object
|
||||
auto r = new DynObj([=, this](IO* io, Li::Drawlist* l, Container* self) {
|
||||
DynObj* r = pIO.DynObjPool.Allocate();
|
||||
*r = UI7::DynObj([=, this](IO* io, Li::Drawlist* l, Container* self) {
|
||||
fvec2 ts = self->FinalPos() + fvec2(0, 7);
|
||||
fvec2 pl[2] = {fvec2(10, 5), fvec2(0, 10)};
|
||||
if (n->second) {
|
||||
|
||||
Reference in New Issue
Block a user