Implement VCanvas and Update TextElem

- Text now requires a font and is able to take an individual scale
- Container requires &ref for Elements to make sure they always exist
- SetViewport now sets the canvas as well
- SetBaseViewport Sets the Virtual Canvas Size
- Layout Now requires a Drawlist reference in Render function
- main.cpp: updated the template
This commit is contained in:
2026-04-03 12:43:49 +02:00
parent 1cf3b6f8e6
commit a776addf11
8 changed files with 97 additions and 60 deletions
+16 -2
View File
@@ -1,5 +1,6 @@
#pragma once
#include <functional>
#include <pd/lithium/lithium.hpp>
#include <pd/ultra/flags.hpp>
@@ -7,6 +8,7 @@ namespace PD {
namespace Ultra {
class Canvas;
class Container;
using EventFunc = std::function<void()>;
class PD_API ElementBase {
public:
ElementBase() {}
@@ -17,24 +19,36 @@ class PD_API ElementBase {
* Reset Function (for PD::Pool::FastReset)
*/
virtual void Reset() {}
void Update();
virtual void Update();
void SetAlignment(UltraAlignment a) { pAlignment = a; }
void SetPosition(const PD::fvec2& pos) { pPos = pos; }
void SetPosition(float x, float y) { pPos = PD::fvec2(x, y); }
void SetSize(const PD::fvec2& size) { pSize = size; }
void SetSize(float w, float h) { pSize = PD::fvec2(w, h); }
/**
* Executed every frame
* Elemnents can override / discard this func
*/
virtual void OnHover(EventFunc func) { pHover = func; }
/**
* Executrd on KeyUp event
* Elemnents can override / discard this func
*/
virtual void OnPress(EventFunc func) { pPress = func; }
protected:
friend class Container;
void SetParent(Container* c) { pParent = c; }
bool RevisionUpdate(PD::u32 req);
Container* pParent;
Container* pParent = nullptr;
PD::u32 pCanvasRev = 0;
UltraAlignment pAlignment = 0;
PD::fvec2 pPos;
PD::fvec2 pSize;
PD::Li::Rect pRenderspace;
EventFunc pHover = nullptr;
EventFunc pPress = nullptr;
};
} // namespace Ultra
} // namespace PD