Widgets: Reimplement Hide/Show

This commit is contained in:
Jérôme Leclercq 2021-11-24 22:24:14 +01:00
parent d2cfc5fdf5
commit 6c97f538a1
4 changed files with 15 additions and 30 deletions

View File

@ -29,7 +29,7 @@ namespace Nz
LabelWidget& operator=(LabelWidget&&) = default;
private:
entt::entity m_textEntity;
entt::entity m_entity;
std::shared_ptr<TextSprite> m_textSprite;
};
}

View File

@ -184,11 +184,14 @@ namespace Nz
else
UnregisterFromCanvas();
auto& registry = GetRegistry();
for (WidgetEntity& entity : m_entities)
{
if (entity.isEnabled)
{
//entity.handle->Enable(show); //< This will override isEnabled, so reset it next line
if (GraphicsComponent* gfx = registry.try_get<GraphicsComponent>(entity.handle))
gfx->Show(show);
entity.isEnabled = true;
}
}
@ -200,29 +203,10 @@ namespace Nz
entt::entity BaseWidget::CreateEntity()
{
entt::entity newEntity = m_registry->create();
//newEntity->Enable(m_visible);
m_entities.emplace_back();
WidgetEntity& newWidgetEntity = m_entities.back();
newWidgetEntity.handle = newEntity;
/*newWidgetEntity.onDisabledSlot.Connect(newEntity->OnEntityDisabled, [this](Entity* entity)
{
auto it = std::find_if(m_entities.begin(), m_entities.end(), [&](const WidgetEntity& widgetEntity) { return widgetEntity.handle == entity; });
NazaraAssert(it != m_entities.end(), "Entity does not belong to this widget");
it->isEnabled = false;
});
newWidgetEntity.onEnabledSlot.Connect(newEntity->OnEntityEnabled, [this](Entity* entity)
{
auto it = std::find_if(m_entities.begin(), m_entities.end(), [&](const WidgetEntity& widgetEntity) { return widgetEntity.handle == entity; });
NazaraAssert(it != m_entities.end(), "Entity does not belong to this widget");
if (!IsVisible())
entity->Disable(); // Next line will override isEnabled status
it->isEnabled = true;
});*/
return newEntity;
}

View File

@ -26,12 +26,7 @@ namespace Nz
entt::registry& registry = GetRegistry();
UInt32 renderMask = GetCanvas()->GetRenderMask();
m_gradientMaterialPass = std::make_shared<MaterialPass>(BasicMaterial::GetSettings());
auto gradientMaterial = std::make_shared<Material>();
gradientMaterial->AddPass("ForwardPass", m_gradientMaterialPass);
m_gradientSprite = std::make_shared<Sprite>(gradientMaterial);
m_gradientSprite = std::make_shared<Sprite>(Widgets::Instance()->GetOpaqueMaterial());
m_gradientSprite->SetColor(m_color);
m_gradientSprite->SetCornerColor(RectCorner::LeftBottom, m_cornerColor);
m_gradientSprite->SetCornerColor(RectCorner::RightBottom, m_cornerColor);

View File

@ -17,9 +17,15 @@ namespace Nz
{
m_textSprite = std::make_shared<TextSprite>(Widgets::Instance()->GetTransparentMaterial());
m_textEntity = CreateEntity();
GetRegistry().emplace<GraphicsComponent>(m_textEntity).AttachRenderable(m_textSprite, GetCanvas()->GetRenderMask());
GetRegistry().emplace<NodeComponent>(m_textEntity).SetParent(this);
auto& registry = GetRegistry();
m_entity = CreateEntity();
auto& gfxComponent = registry.emplace<GraphicsComponent>(m_entity, IsVisible());
gfxComponent.AttachRenderable(m_textSprite, GetCanvas()->GetRenderMask());
auto& nodeComponent = registry.emplace<NodeComponent>(m_entity);
nodeComponent.SetParent(this);
Layout();
}