Sdk/BaseWidget: Cleanup canvas index

This commit is contained in:
Lynix
2017-01-19 23:09:23 +01:00
parent e4b6f8e126
commit 6ba35700bf
4 changed files with 27 additions and 11 deletions

View File

@@ -15,6 +15,7 @@
#include <Nazara/Utility/Event.hpp>
#include <Nazara/Utility/Mouse.hpp>
#include <Nazara/Utility/Node.hpp>
#include <limits>
namespace Ndk
{
@@ -95,11 +96,14 @@ namespace Ndk
inline void DestroyChild(BaseWidget* widget);
void DestroyChildren();
void RegisterToCanvas();
inline bool IsRegisteredToCanvas() const;
inline void NotifyParentResized(const Nz::Vector2f& newSize);
void RegisterToCanvas();
inline void UpdateCanvasIndex(std::size_t index);
void UnregisterFromCanvas();
static constexpr std::size_t InvalidCanvasIndex = std::numeric_limits<std::size_t>::max();
std::size_t m_canvasIndex;
std::vector<EntityOwner> m_entities;
std::vector<std::unique_ptr<BaseWidget>> m_children;

View File

@@ -5,12 +5,11 @@
#include <NDK/BaseWidget.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Math/Algorithm.hpp>
#include <limits>
namespace Ndk
{
inline BaseWidget::BaseWidget() :
m_canvasIndex(std::numeric_limits<std::size_t>::max()),
m_canvasIndex(InvalidCanvasIndex),
m_backgroundColor(Nz::Color(230, 230, 230, 255)),
m_canvas(nullptr),
m_contentSize(50.f, 50.f),
@@ -98,6 +97,11 @@ namespace Ndk
Layout();
}
inline bool BaseWidget::IsRegisteredToCanvas() const
{
return m_canvas && m_canvasIndex != InvalidCanvasIndex;
}
inline void BaseWidget::NotifyParentResized(const Nz::Vector2f& newSize)
{
for (const auto& widgetPtr : m_children)

View File

@@ -36,7 +36,7 @@ namespace Ndk
DestroyChildren();
// Prevent our parent from trying to call us
m_canvasIndex = std::numeric_limits<std::size_t>::max();
m_canvasIndex = InvalidCanvasIndex;
}
inline const WorldHandle& Canvas::GetWorld() const