Sdk/BaseWidget: Add CenterHorizontal and CenterVertical() methods

This commit is contained in:
Jérôme Leclercq 2017-09-21 14:40:03 +02:00
parent bf98297233
commit 37896e2401
2 changed files with 20 additions and 0 deletions

View File

@ -38,6 +38,8 @@ namespace Ndk
inline void AddChild(std::unique_ptr<BaseWidget>&& widget);
inline void Center();
inline void CenterHorizontal();
inline void CenterVertical();
inline void Destroy();

View File

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