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

@@ -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;
}