Totally refactored UILabel

This commit is contained in:
2023-03-05 23:42:15 -08:00
parent aeb5014a07
commit ee2dc931f2
15 changed files with 463 additions and 194 deletions

View File

@ -5,6 +5,7 @@
#include "UICanvas.hpp"
#include "game/DawnGame.hpp"
#include "UIComponent.hpp"
using namespace Dawn;
@ -13,10 +14,47 @@ UICanvas * UICanvas::create(Scene *scene) {
return item->addComponent<UICanvas>();
}
UICanvas::UICanvas(SceneItem *item) : SceneItemComponent(item) {
UICanvas::UICanvas(SceneItem *item) :
SceneItemComponent(item),
camera(nullptr)
{
}
float_t UICanvas::getWidth() {
return w;
}
float_t UICanvas::getHeight() {
return h;
}
float_t UICanvas::getContentWidth() {
return this->getWidth();
}
float_t UICanvas::getContentHeight() {
return this->getHeight();
}
void UICanvas::onStart() {
if(camera == nullptr) camera = getScene()->findComponent<Camera>();
useEffectWithTeardown([&]{
if(camera == nullptr) return evtRenderResize = [&] {};
this->w = camera->getRenderTarget()->getWidth();
this->h = camera->getRenderTarget()->getHeight();
return evtRenderResize = useEvent([&](float_t w, float_t h){
this->w = w;
this->h = h;
auto comps = this->item->findChildren<UIComponent>();
auto itComps = comps.begin();
while(itComps != comps.end()) {
(*itComps)->alignmentNeedsUpdating = true;
++itComps;
}
}, camera->eventRenderTargetResized);
}, camera)();
}
void UICanvas::onDispose() {