Sdk/Widgets: Make the canvas aware of itself as a widget

This commit is contained in:
Lynix
2017-01-18 23:35:43 +01:00
parent c1dfc5c4b8
commit 36bcdcdb8c
5 changed files with 35 additions and 14 deletions

View File

@@ -21,13 +21,12 @@ namespace Ndk
m_widgetParent = parent;
m_world = m_canvas->GetWorld();
m_canvasIndex = m_canvas->RegisterWidget(this);
RegisterToCanvas();
}
BaseWidget::~BaseWidget()
{
if (m_canvasIndex != std::numeric_limits<std::size_t>::max())
m_canvas->UnregisterWidget(m_canvasIndex);
UnregisterFromCanvas();
}
void BaseWidget::Destroy()
@@ -88,6 +87,11 @@ namespace Ndk
{
m_visible = show;
if (m_visible)
RegisterToCanvas();
else
UnregisterFromCanvas();
for (const EntityHandle& entity : m_entities)
entity->Enable(show);
@@ -182,4 +186,20 @@ namespace Ndk
{
m_children.clear();
}
void BaseWidget::RegisterToCanvas()
{
NazaraAssert(m_canvasIndex == std::numeric_limits<std::size_t>::max(), "Widget is already registered to canvas");
m_canvasIndex = m_canvas->RegisterWidget(this);
}
void BaseWidget::UnregisterFromCanvas()
{
if (m_canvasIndex != std::numeric_limits<std::size_t>::max())
{
m_canvas->UnregisterWidget(m_canvasIndex);
m_canvasIndex = std::numeric_limits<std::size_t>::max();
}
}
}

View File

@@ -14,14 +14,6 @@ namespace Ndk
{
}
void Canvas::Layout()
{
if (m_backgroundEntity)
{
m_backgroundSprite->SetSize(m_contentSize.x + m_padding.left + m_padding.right, m_contentSize.y + m_padding.top + m_padding.bottom);
}
}
void Canvas::NotifyWidgetUpdate(std::size_t index)
{
WidgetBox& entry = m_widgetBoxes[index];