diff --git a/SDK/include/NDK/Components/CollisionComponent2D.hpp b/SDK/include/NDK/Components/CollisionComponent2D.hpp index 9e7356b63..0e9c49898 100644 --- a/SDK/include/NDK/Components/CollisionComponent2D.hpp +++ b/SDK/include/NDK/Components/CollisionComponent2D.hpp @@ -39,7 +39,7 @@ namespace Ndk void SetGeomOffset(const Nz::Vector2f& geomOffset); CollisionComponent2D& operator=(Nz::Collider2DRef geom); - CollisionComponent2D& operator=(CollisionComponent2D&& collision) = default; + CollisionComponent2D& operator=(CollisionComponent2D&& collision) = delete; static ComponentIndex componentIndex; diff --git a/SDK/include/NDK/Components/LightComponent.hpp b/SDK/include/NDK/Components/LightComponent.hpp index a7f72d0eb..50a9699be 100644 --- a/SDK/include/NDK/Components/LightComponent.hpp +++ b/SDK/include/NDK/Components/LightComponent.hpp @@ -24,8 +24,6 @@ namespace Ndk LightComponent(const LightComponent& light) = default; ~LightComponent() = default; - LightComponent& operator=(const LightComponent& light) = default; - static ComponentIndex componentIndex; }; } diff --git a/SDK/include/NDK/Widgets/BoxLayout.hpp b/SDK/include/NDK/Widgets/BoxLayout.hpp index d27616814..698b5b2f8 100644 --- a/SDK/include/NDK/Widgets/BoxLayout.hpp +++ b/SDK/include/NDK/Widgets/BoxLayout.hpp @@ -10,34 +10,27 @@ #include #include #include -#include +#include namespace Ndk { class NDK_API BoxLayout : public BaseWidget { public: - inline BoxLayout(BaseWidget* parent, BoxLayoutOrientation orientation); + BoxLayout(BaseWidget* parent, BoxLayoutOrientation orientation); BoxLayout(const BoxLayout&) = delete; - BoxLayout(BoxLayout&&) = default; - ~BoxLayout() = default; + BoxLayout(BoxLayout&&) = delete; + ~BoxLayout(); void Layout() override; BoxLayout& operator=(const BoxLayout&) = delete; - BoxLayout& operator=(BoxLayout&&) = default; + BoxLayout& operator=(BoxLayout&&) = delete; private: - struct ChildInfo - { - BaseWidget* widget; - bool isConstrained; - float maximumSize; - float minimumSize; - float size; - }; + struct State; - std::vector m_childInfos; + std::unique_ptr m_state; BoxLayoutOrientation m_orientation; float m_spacing; }; diff --git a/SDK/include/NDK/Widgets/BoxLayout.inl b/SDK/include/NDK/Widgets/BoxLayout.inl index 72dfaaf5f..9d016e2bc 100644 --- a/SDK/include/NDK/Widgets/BoxLayout.inl +++ b/SDK/include/NDK/Widgets/BoxLayout.inl @@ -6,10 +6,4 @@ namespace Ndk { - BoxLayout::BoxLayout(BaseWidget* parent, BoxLayoutOrientation orientation) : - BaseWidget(parent), - m_orientation(orientation), - m_spacing(5.f) - { - } } diff --git a/SDK/src/NDK/Widgets/BoxLayout.cpp b/SDK/src/NDK/Widgets/BoxLayout.cpp index 89564ed08..caf4720a1 100644 --- a/SDK/src/NDK/Widgets/BoxLayout.cpp +++ b/SDK/src/NDK/Widgets/BoxLayout.cpp @@ -4,25 +4,43 @@ #include #include -#include +#include +#include #include +#include namespace Ndk { + struct BoxLayout::State + { + std::vector sizeVar; + kiwi::Solver solver; + }; + + BoxLayout::BoxLayout(BaseWidget* parent, BoxLayoutOrientation orientation) : + BaseWidget(parent), + m_orientation(orientation), + m_spacing(5.f) + { + m_state = std::make_unique(); + } + + BoxLayout::~BoxLayout() = default; + void BoxLayout::Layout() { - std::size_t axis1, axis2; + BaseWidget::Layout(); + + std::size_t axis; switch (m_orientation) { case BoxLayoutOrientation_Horizontal: - axis1 = 0; //< x - axis2 = 1; //< y + axis = 0; //< x break; case BoxLayoutOrientation_Vertical: - axis1 = 1; //< y - axis2 = 0; //< x + axis = 1; //< y break; default: @@ -30,7 +48,21 @@ namespace Ndk break; } - m_childInfos.clear(); + //TODO: Keep solver state when widgets don't change + std::size_t widgetChildCount = GetWidgetChildCount(); + if (widgetChildCount == 0) + return; + + m_state->solver.reset(); + + m_state->sizeVar.clear(); + m_state->sizeVar.reserve(widgetChildCount); + + kiwi::Expression sizeSum; + + Nz::Vector2f layoutSize = GetSize(); + float availableSpace = layoutSize[axis] - m_spacing * (widgetChildCount - 1); + float perfectSpacePerWidget = availableSpace / widgetChildCount; // Handle size ForEachWidgetChild([&](BaseWidget* child) @@ -38,73 +70,55 @@ namespace Ndk if (!child->IsVisible()) return; - m_childInfos.emplace_back(); - auto& info = m_childInfos.back(); - info.isConstrained = false; - info.maximumSize = child->GetMaximumSize()[axis1]; - info.minimumSize = child->GetMinimumSize()[axis1]; - info.size = info.minimumSize; - info.widget = child; + float maximumSize = child->GetMaximumSize()[axis]; + float minimumSize = child->GetMinimumSize()[axis]; + + m_state->sizeVar.emplace_back(); + auto& sizeVar = m_state->sizeVar.back(); + + m_state->solver.addConstraint({ sizeVar >= minimumSize | kiwi::strength::required }); + + if (maximumSize < std::numeric_limits::infinity()) + m_state->solver.addConstraint({ sizeVar <= maximumSize | kiwi::strength::required }); + + m_state->solver.addConstraint({ sizeVar == perfectSpacePerWidget | kiwi::strength::medium }); + + sizeSum = sizeSum + sizeVar; }); - Nz::Vector2f layoutSize = GetSize(); + kiwi::Variable targetSize("LayoutSize"); + + m_state->solver.addConstraint(sizeSum <= targetSize | kiwi::strength::strong); + + m_state->solver.addEditVariable(targetSize, kiwi::strength::strong); + m_state->solver.suggestValue(targetSize, availableSpace); + + m_state->solver.updateVariables(); + + std::size_t varIndex = 0; - float availableSpace = layoutSize[axis1] - m_spacing * (m_childInfos.size() - 1); float remainingSize = availableSpace; - for (auto& info : m_childInfos) - remainingSize -= info.minimumSize; - // Okay this algorithm is FAR from perfect but I couldn't figure a way other than this one - std::size_t unconstrainedChildCount = m_childInfos.size(); - - bool hasUnconstrainedChilds = false; - for (std::size_t i = 0; i < m_childInfos.size(); ++i) + ForEachWidgetChild([&](BaseWidget* child) { - if (remainingSize <= 0.0001f) - break; + if (!child->IsVisible()) + return; - float evenSize = remainingSize / unconstrainedChildCount; + Nz::Vector2f newSize = layoutSize; + newSize[axis] = m_state->sizeVar[varIndex].value(); - for (auto& info : m_childInfos) - { - if (info.isConstrained) - continue; + child->Resize(newSize); + remainingSize -= newSize[axis]; - float previousSize = info.size; + varIndex++; + }); - info.size += evenSize; - if (info.size > info.maximumSize) - { - unconstrainedChildCount--; - - evenSize += (info.size - info.maximumSize) / unconstrainedChildCount; - info.isConstrained = true; - info.size = info.maximumSize; - } - else - hasUnconstrainedChilds = true; - - remainingSize -= info.size - previousSize; - } - - if (!hasUnconstrainedChilds) - break; - } - - float spacing = m_spacing + remainingSize / (m_childInfos.size() - 1); - - for (auto& info : m_childInfos) - { - Nz::Vector2f newSize = info.widget->GetSize(); - newSize[axis1] = info.size; - - info.widget->Resize(newSize); - } + float spacing = m_spacing + remainingSize / (widgetChildCount - 1); // Handle position float cursor = 0.f; bool first = true; - for (auto& info : m_childInfos) + ForEachWidgetChild([&](BaseWidget* child) { if (first) first = false; @@ -112,11 +126,11 @@ namespace Ndk cursor += spacing; Nz::Vector2f position = Nz::Vector2f(0.f, 0.f); - position[axis1] = cursor; + position[axis] = cursor; - info.widget->SetPosition(position); + child->SetPosition(position); - cursor += info.size; - }; + cursor += child->GetSize()[axis]; + }); } } diff --git a/include/Nazara/Graphics/AbstractBackground.hpp b/include/Nazara/Graphics/AbstractBackground.hpp index fb0bc3df8..ebd3c0a4d 100644 --- a/include/Nazara/Graphics/AbstractBackground.hpp +++ b/include/Nazara/Graphics/AbstractBackground.hpp @@ -26,7 +26,7 @@ namespace Nz { public: AbstractBackground() = default; - AbstractBackground(const AbstractBackground&) = default; + AbstractBackground(const AbstractBackground&) = delete; AbstractBackground(AbstractBackground&&) = delete; virtual ~AbstractBackground(); @@ -34,7 +34,7 @@ namespace Nz virtual BackgroundType GetBackgroundType() const = 0; - AbstractBackground& operator=(const AbstractBackground&) = default; + AbstractBackground& operator=(const AbstractBackground&) = delete; AbstractBackground& operator=(AbstractBackground&&) = delete; private: diff --git a/include/Nazara/Math/Angle.inl b/include/Nazara/Math/Angle.inl index 036ed5943..cb3a237c2 100644 --- a/include/Nazara/Math/Angle.inl +++ b/include/Nazara/Math/Angle.inl @@ -126,7 +126,7 @@ namespace Nz template void SinCos(std::enable_if_t::value, long double> x, long double* s, long double* c) { - ::sincosl(x, sin, cos); + ::sincosl(x, s, c); } #else // Naive implementation, hopefully optimized by the compiler diff --git a/include/Nazara/Network/AbstractSocket.hpp b/include/Nazara/Network/AbstractSocket.hpp index ca69d7713..c03c1079d 100644 --- a/include/Nazara/Network/AbstractSocket.hpp +++ b/include/Nazara/Network/AbstractSocket.hpp @@ -22,7 +22,7 @@ namespace Nz AbstractSocket(AbstractSocket&& abstractSocket) noexcept; virtual ~AbstractSocket(); - void Close(); + void Close() noexcept; void EnableBlocking(bool blocking); @@ -41,7 +41,7 @@ namespace Nz void SetSendBufferSize(std::size_t size); AbstractSocket& operator=(const AbstractSocket&) = delete; - AbstractSocket& operator=(AbstractSocket&& abstractSocket); + AbstractSocket& operator=(AbstractSocket&& abstractSocket) noexcept; // Signals: NazaraSignal(OnStateChanged, const AbstractSocket* /*socket*/, SocketState /*oldState*/, SocketState /*newState*/); diff --git a/include/Nazara/Network/UdpSocket.hpp b/include/Nazara/Network/UdpSocket.hpp index 47a3a3bbc..eff1af662 100644 --- a/include/Nazara/Network/UdpSocket.hpp +++ b/include/Nazara/Network/UdpSocket.hpp @@ -46,6 +46,9 @@ namespace Nz bool SendMultiple(const IpAddress& to, const NetBuffer* buffers, std::size_t bufferCount, std::size_t* sent); bool SendPacket(const IpAddress& to, const NetPacket& packet); + UdpSocket& operator=(const UdpSocket& udpSocket) = delete; + UdpSocket& operator=(UdpSocket && udpSocket) noexcept = default; + private: void OnClose() override; void OnOpened() override; diff --git a/src/Nazara/Network/AbstractSocket.cpp b/src/Nazara/Network/AbstractSocket.cpp index 64bdd0e0d..9bfeba066 100644 --- a/src/Nazara/Network/AbstractSocket.cpp +++ b/src/Nazara/Network/AbstractSocket.cpp @@ -71,7 +71,7 @@ namespace Nz * \brief Closes the socket */ - void AbstractSocket::Close() + void AbstractSocket::Close() noexcept { if (m_handle != SocketImpl::InvalidHandle) { @@ -237,7 +237,7 @@ namespace Nz * \param abstractSocket AbstractSocket to move in this */ - AbstractSocket& AbstractSocket::operator=(AbstractSocket&& abstractSocket) + AbstractSocket& AbstractSocket::operator=(AbstractSocket&& abstractSocket) noexcept { Close();