diff --git a/doc/changelog.dox b/doc/changelog.dox index 6fc5ad32d..417be9494 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -66,6 +66,10 @@ See also: - Added @ref Math::fmod() (see [mosra/magnum#454](https://github.com/mosra/magnum/pull/454)) - Added @ref Math::binomialCoefficient() (see [mosra/magnum#461](https://github.com/mosra/magnum/pull/461)) +@subsubsection changelog-latest-new-scenegraph SceneGraph library + +- Added @ref SceneGraph::Object::move() + @subsection changelog-latest-changes Changes and improvements @subsubsection changelog-latest-changes-gl GL library diff --git a/src/Magnum/SceneGraph/Object.h b/src/Magnum/SceneGraph/Object.h index cb8c9389b..30e5c78f8 100644 --- a/src/Magnum/SceneGraph/Object.h +++ b/src/Magnum/SceneGraph/Object.h @@ -157,6 +157,23 @@ template class Object: public AbstractObject, Object>::list(); } + /** + * @brief Move a child object before another + * @return Reference to self (for method chaining) + * @m_since_latest + * + * Doesn't have any effect on draw order, only on the child order when + * iterating through @ref children(). The @p child is expected to be a + * child of this object, @p before is either a child of this object or + * @cpp nullptr @ce in which case the @p child is moved to the last + * position in the child list. + * @see @ref Corrade::Containers::LinkedList::move() + */ + Object& move(Object& child, Object* before) { + Containers::LinkedList>::move(&child, before); + return *this; + } + /** @brief Previous sibling object or `nullptr`, if this is the first object */ Object* previousSibling() { return Containers::LinkedListItem, Object>::previous(); diff --git a/src/Magnum/SceneGraph/Test/ObjectTest.cpp b/src/Magnum/SceneGraph/Test/ObjectTest.cpp index 55a9600fb..067a1e05c 100644 --- a/src/Magnum/SceneGraph/Test/ObjectTest.cpp +++ b/src/Magnum/SceneGraph/Test/ObjectTest.cpp @@ -40,6 +40,7 @@ struct ObjectTest: TestSuite::Tester { void parenting(); void addChild(); + void move(); void scene(); void setParentKeepTransformation(); void setParentKeepTransformationInvalid(); @@ -78,6 +79,7 @@ ObjectTest::ObjectTest() { &ObjectTest::parenting, &ObjectTest::addChild, + &ObjectTest::move, &ObjectTest::scene, &ObjectTest::setParentKeepTransformation, &ObjectTest::setParentKeepTransformationInvalid, @@ -154,6 +156,27 @@ void ObjectTest::addChild() { CORRADE_COMPARE(p.parent(), &o); } +void ObjectTest::move() { + Scene3D scene; + Object3D* a = new Object3D{&scene}; + Object3D* b = new Object3D{&scene}; + Object3D* c = new Object3D{&scene}; + + CORRADE_COMPARE(a->nextSibling(), b); + CORRADE_COMPARE(b->nextSibling(), c); + CORRADE_COMPARE(c->nextSibling(), nullptr); + + scene.move(*a, c); + CORRADE_COMPARE(b->nextSibling(), a); + CORRADE_COMPARE(a->nextSibling(), c); + CORRADE_COMPARE(c->nextSibling(), nullptr); + + scene.move(*a, nullptr); + CORRADE_COMPARE(b->nextSibling(), c); + CORRADE_COMPARE(c->nextSibling(), a); + CORRADE_COMPARE(a->nextSibling(), nullptr); +} + void ObjectTest::scene() { Scene3D scene; CORRADE_VERIFY(scene.scene() == &scene);