Rework Project Ultra

- Added container
- Made container the base of Layout
- Set Containers theirself as pParent for Elements on Push
This commit is contained in:
2026-03-29 04:28:45 +02:00
parent 4498c2c0fb
commit b5321ca1a1
10 changed files with 82 additions and 78 deletions
+38
View File
@@ -0,0 +1,38 @@
#pragma once
#include <pd/lithium/lithium.hpp>
#include <pd/ultra/elems/element.hpp>
namespace PD {
namespace Ultra {
class Container {
public:
Container() {}
Container(const PD::Li::Rect& r) : pRect(r) {}
virtual ~Container() {}
void Push(PD::Ultra::ElementBase* elem) {
elem->SetParent(this);
pElems.Push(elem);
}
void Reset() { pElems.ResetFast(); }
const PD::Li::Rect& GetRenderspace() const { return pRect; }
void SetViewport(const PD::fvec2& vp) { pRect = PD::fvec4(PD::fvec2(0), vp); }
const PD::fvec2 GetTopLeft() const { return pRect.TopLeft(); }
const PD::fvec2 GetTopRight() const { return pRect.TopRight(); }
const PD::fvec2 GetBotLeft() const { return pRect.BotLeft(); }
const PD::fvec2 GetBotRight() const { return pRect.BotRight(); }
const PD::fvec2 GetSize() const { return pRect.BotRight() - pRect.TopLeft(); }
const PD::fvec2 GetPosition() const { return pRect.TopLeft(); }
protected:
PD::Pool<PD::Ultra::ElementBase*>& GetElements() { return pElems; }
private:
PD::Li::Rect pRect;
PD::Pool<PD::Ultra::ElementBase*> pElems;
};
} // namespace Ultra
} // namespace PD
+4 -3
View File
@@ -6,6 +6,7 @@
namespace PD {
namespace Ultra {
class Canvas;
class Container;
class PD_API ElementBase {
public:
ElementBase() {}
@@ -16,7 +17,6 @@ class PD_API ElementBase {
* Reset Function (for PD::Pool::FastReset)
*/
virtual void Reset() {}
void Update(Canvas& c);
void SetAlignment(UltraAlignment a) { pAlignment = a; }
void SetPosition(const PD::fvec2& pos) { pPos = pos; }
@@ -25,13 +25,14 @@ class PD_API ElementBase {
void SetSize(float w, float h) { pSize = PD::fvec2(w, h); }
protected:
friend class Container;
void SetParent(Container* c) { pParent = c; }
bool RevisionUpdate(PD::u32 req);
Container* pParent;
PD::u32 pCanvasRev = 0;
PD::Li::Rect pRenderspace;
UltraAlignment pAlignment = 0;
PD::fvec2 pPos;
PD::fvec2 pSize;
ElementBase* pParent = nullptr;
};
} // namespace Ultra
} // namespace PD
+4
View File
@@ -28,10 +28,14 @@ class PD_API Rect : public ElementBase {
void SetColor(const PD::Color& color) { pColor = color; }
void SetRounding(float r) { pRounding = r; }
void SetLined(bool v) { pLined = v; }
void SetThickness(int v) { pThickness = v; }
private:
PD::Color pColor;
float pRounding = 0.f;
bool pLined = false;
int pThickness = 1.f;
};
} // namespace Ultra
+2 -7
View File
@@ -1,28 +1,23 @@
#pragma once
#include <pd/ultra/canvas.hpp>
#include <pd/ultra/container.hpp>
#include <pd/ultra/elems/element.hpp>
namespace PD {
namespace Ultra {
class PD_API Layout {
class PD_API Layout : public Container {
public:
Layout() {}
~Layout() {}
void Add(ElementBase& elem);
void SetFont(PD::Li::Font& font);
void Render();
const PD::Li::Drawlist& Data() const { return pList; }
Canvas& GetCanvas() { return pCanvas; }
const Canvas& GetCanvas() const { return pCanvas; }
private:
Canvas pCanvas;
PD::Pool<ElementBase*> pElements;
PD::Li::Drawlist pList;
};
} // namespace Ultra