From 37896e240115bf019302d21b732720ca30e5badd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Thu, 21 Sep 2017 14:40:03 +0200 Subject: [PATCH] Sdk/BaseWidget: Add CenterHorizontal and CenterVertical() methods --- SDK/include/NDK/BaseWidget.hpp | 2 ++ SDK/include/NDK/BaseWidget.inl | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/SDK/include/NDK/BaseWidget.hpp b/SDK/include/NDK/BaseWidget.hpp index b4ea5b9d2..eb209a887 100644 --- a/SDK/include/NDK/BaseWidget.hpp +++ b/SDK/include/NDK/BaseWidget.hpp @@ -38,6 +38,8 @@ namespace Ndk inline void AddChild(std::unique_ptr&& widget); inline void Center(); + inline void CenterHorizontal(); + inline void CenterVertical(); inline void Destroy(); diff --git a/SDK/include/NDK/BaseWidget.inl b/SDK/include/NDK/BaseWidget.inl index e84a67a49..948769890 100644 --- a/SDK/include/NDK/BaseWidget.inl +++ b/SDK/include/NDK/BaseWidget.inl @@ -46,6 +46,24 @@ namespace Ndk SetPosition((parentSize.x - mySize.x) / 2.f, (parentSize.y - mySize.y) / 2.f); } + inline void BaseWidget::CenterHorizontal() + { + NazaraAssert(m_widgetParent, "Widget has no parent"); + + Nz::Vector2f parentSize = m_widgetParent->GetSize(); + Nz::Vector2f mySize = GetSize(); + SetPosition((parentSize.x - mySize.x) / 2.f, GetPosition(Nz::CoordSys_Local).y); + } + + inline void BaseWidget::CenterVertical() + { + NazaraAssert(m_widgetParent, "Widget has no parent"); + + Nz::Vector2f parentSize = m_widgetParent->GetSize(); + Nz::Vector2f mySize = GetSize(); + SetPosition(GetPosition(Nz::CoordSys_Local).x, (parentSize.y - mySize.y) / 2.f); + } + inline const Nz::Color& BaseWidget::GetBackgroundColor() const { return m_backgroundColor;