From 63c810f401fe080ccf0da01f8da00f68d4f51e14 Mon Sep 17 00:00:00 2001 From: eduardodoria Date: Mon, 7 Aug 2023 09:07:21 -0300 Subject: [PATCH] UI layout improvements --- engine/core/subsystem/UISystem.cpp | 107 +++++++++++++++-------------- engine/core/subsystem/UISystem.h | 2 + 2 files changed, 57 insertions(+), 52 deletions(-) diff --git a/engine/core/subsystem/UISystem.cpp b/engine/core/subsystem/UISystem.cpp index e1ce8f72..cff49731 100644 --- a/engine/core/subsystem/UISystem.cpp +++ b/engine/core/subsystem/UISystem.cpp @@ -724,6 +724,58 @@ void UISystem::destroy(){ void UISystem::draw(){ } +void UISystem::createOrUpdateUiComponent(double dt, UILayoutComponent& layout, Entity entity, Signature signature){ + if (signature.test(scene->getComponentType())){ + UIComponent& ui = scene->getComponent(entity); + + // Texts + if (signature.test(scene->getComponentType())){ + TextComponent& text = scene->getComponent(entity); + + createOrUpdateText(text, ui, layout); + } + + // UI Polygons + if (signature.test(scene->getComponentType())){ + PolygonComponent& polygon = scene->getComponent(entity); + + createOrUpdatePolygon(polygon, ui, layout); + } + + // Images + if (signature.test(scene->getComponentType())){ + ImageComponent& img = scene->getComponent(entity); + + createOrUpdateImage(img, ui, layout); + + // Buttons + if (signature.test(scene->getComponentType())){ + ButtonComponent& button = scene->getComponent(entity); + + if (button.needUpdateButton){ + updateButton(entity, button, img, ui, layout); + + button.needUpdateButton = false; + } + } + + // Textedits + if (signature.test(scene->getComponentType())){ + TextEditComponent& textedit = scene->getComponent(entity); + + if (textedit.needUpdateTextEdit){ + updateTextEdit(entity, textedit, img, ui, layout); + + textedit.needUpdateTextEdit = false; + } + + blinkCursorTextEdit(dt, textedit, ui); + } + } + + } +} + void UISystem::update(double dt){ // need to be ordered by Transform @@ -735,6 +787,8 @@ void UISystem::update(double dt){ Entity entity = layouts->getEntity(i); Signature signature = scene->getSignature(entity); + createOrUpdateUiComponent(dt, layout, entity, signature); + if (signature.test(scene->getComponentType())){ UIContainerComponent& container = scene->getComponent(entity); // configuring all container boxes @@ -758,9 +812,6 @@ void UISystem::update(double dt){ } } - //TODO: Fix when container child is an image not loaded yet and size is 0. - // Container size is setted without this image size and it keeps small. - // To test: Use a container with defined size image and other non defined size. layout.width = (layout.width > 0)? layout.width : genWidth; layout.height = (layout.height > 0)? layout.height : genHeight; @@ -913,55 +964,7 @@ void UISystem::update(double dt){ layout.needUpdateSizes = false; } - if (signature.test(scene->getComponentType())){ - UIComponent& ui = scene->getComponent(entity); - - // Texts - if (signature.test(scene->getComponentType())){ - TextComponent& text = scene->getComponent(entity); - - createOrUpdateText(text, ui, layout); - } - - // UI Polygons - if (signature.test(scene->getComponentType())){ - PolygonComponent& polygon = scene->getComponent(entity); - - createOrUpdatePolygon(polygon, ui, layout); - } - - // Images - if (signature.test(scene->getComponentType())){ - ImageComponent& img = scene->getComponent(entity); - - createOrUpdateImage(img, ui, layout); - - // Buttons - if (signature.test(scene->getComponentType())){ - ButtonComponent& button = scene->getComponent(entity); - - if (button.needUpdateButton){ - updateButton(entity, button, img, ui, layout); - - button.needUpdateButton = false; - } - } - - // Textedits - if (signature.test(scene->getComponentType())){ - TextEditComponent& textedit = scene->getComponent(entity); - - if (textedit.needUpdateTextEdit){ - updateTextEdit(entity, textedit, img, ui, layout); - - textedit.needUpdateTextEdit = false; - } - - blinkCursorTextEdit(dt, textedit, ui); - } - } - - } + createOrUpdateUiComponent(dt, layout, entity, signature); if (signature.test(scene->getComponentType())){ UIContainerComponent& container = scene->getComponent(entity); diff --git a/engine/core/subsystem/UISystem.h b/engine/core/subsystem/UISystem.h index b1c53f03..84ec309b 100644 --- a/engine/core/subsystem/UISystem.h +++ b/engine/core/subsystem/UISystem.h @@ -26,6 +26,8 @@ namespace Supernova{ std::string eventId; + void createOrUpdateUiComponent(double dt, UILayoutComponent& layout, Entity entity, Signature signature); + //Image bool createImagePatches(ImageComponent& img, UIComponent& ui, UILayoutComponent& layout);