From 97ca195e20a8ea2efd60bf3fc18f0adeee587864 Mon Sep 17 00:00:00 2001 From: CodingJellyfish Date: Sat, 27 Apr 2024 15:05:52 +0800 Subject: [PATCH] Fix dynamic ribbon widget being shown above a dialog after resized --- lib/irrlicht/include/IGUIElement.h | 28 ++++++++++++++++++- lib/irrlicht/include/IGUIEnvironment.h | 2 ++ lib/irrlicht/include/irrList.h | 1 + .../source/Irrlicht/CGUIEnvironment.h | 2 ++ .../widgets/dynamic_ribbon_widget.cpp | 2 ++ 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/irrlicht/include/IGUIElement.h b/lib/irrlicht/include/IGUIElement.h index 378c25c5b93..282840bf66f 100644 --- a/lib/irrlicht/include/IGUIElement.h +++ b/lib/irrlicht/include/IGUIElement.h @@ -573,6 +573,27 @@ class IGUIElement : public virtual io::IAttributeExchangingObject, public IEvent } + virtual bool setChildEnd(IGUIElement* end) + { + if (end == 0) + { + ChildEnd = core::list::Iterator(); + return true; + } + + core::list::Iterator it = Children.begin(); + for (; it != Children.end(); ++it) + { + if (*it == end) + { + ChildEnd = it; + return true; + } + } + return false; + } + + //! Finds the first element with the given id. /** \param id: Id to search for. \param searchchildren: Set this to true, if also children of this @@ -823,7 +844,10 @@ class IGUIElement : public virtual io::IAttributeExchangingObject, public IEvent child->remove(); // remove from old parent child->LastParentRect = getAbsolutePosition(); child->Parent = this; - Children.push_back(child); + if (ChildEnd.isValid()) + Children.insert_after(ChildEnd, child); + else + Children.push_back(child); } } @@ -1027,6 +1051,8 @@ class IGUIElement : public virtual io::IAttributeExchangingObject, public IEvent //! type of element EGUI_ELEMENT_TYPE Type; + + core::list::Iterator ChildEnd; }; diff --git a/lib/irrlicht/include/IGUIEnvironment.h b/lib/irrlicht/include/IGUIEnvironment.h index 84c40924345..c5cd83a0ba1 100644 --- a/lib/irrlicht/include/IGUIEnvironment.h +++ b/lib/irrlicht/include/IGUIEnvironment.h @@ -612,6 +612,8 @@ class IGUIEnvironment : public virtual IReferenceCounted virtual void readGUIElement(io::IXMLReader* reader, IGUIElement* node) =0; virtual void removeHovered(IGUIElement* element) = 0; + + virtual bool setChildEnd(IGUIElement* end) = 0; }; diff --git a/lib/irrlicht/include/irrList.h b/lib/irrlicht/include/irrList.h index 54eed83447e..8c1153318d7 100644 --- a/lib/irrlicht/include/irrList.h +++ b/lib/irrlicht/include/irrList.h @@ -73,6 +73,7 @@ class list T & operator * () { return Current->Element; } T * operator ->() { return &Current->Element; } + bool isValid() const { return Current != 0; } private: explicit Iterator(SKListNode* begin) : Current(begin) {} diff --git a/lib/irrlicht/source/Irrlicht/CGUIEnvironment.h b/lib/irrlicht/source/Irrlicht/CGUIEnvironment.h index efe055f2538..3e5fef8171e 100644 --- a/lib/irrlicht/source/Irrlicht/CGUIEnvironment.h +++ b/lib/irrlicht/source/Irrlicht/CGUIEnvironment.h @@ -257,6 +257,8 @@ class CGUIEnvironment : public IGUIEnvironment, public IGUIElement virtual void readGUIElement(io::IXMLReader* reader, IGUIElement* node); virtual void removeHovered(IGUIElement* element); + + virtual bool setChildEnd(IGUIElement* end) { return IGUIElement::setChildEnd(end); } private: IGUIElement* getNextElement(bool reverse=false, bool group=false); diff --git a/src/guiengine/widgets/dynamic_ribbon_widget.cpp b/src/guiengine/widgets/dynamic_ribbon_widget.cpp index d7057510276..06fc9109e99 100644 --- a/src/guiengine/widgets/dynamic_ribbon_widget.cpp +++ b/src/guiengine/widgets/dynamic_ribbon_widget.cpp @@ -197,9 +197,11 @@ void DynamicRibbonWidget::resize() for (unsigned i = 0; i < MAX_PLAYER_COUNT; i++) selected[i] = getSelectionIDString(i); Widget::resize(); + GUIEngine::getGUIEnv()->setChildEnd(m_left_widget->m_element); updateForResizing(); buildInternalStructure(); updateItemDisplay(); + GUIEngine::getGUIEnv()->setChildEnd(NULL); for (unsigned i = 0; i < MAX_PLAYER_COUNT; i++) { if (!selected[i].empty())