| 840 | } |
| 841 | |
| 842 | void Widget::attachToWidget(Widget* _parent, WidgetStyle _style, std::string_view _layer) |
| 843 | { |
| 844 | MYGUI_ASSERT(_parent, "parent must be valid"); |
| 845 | MYGUI_ASSERT(_parent != this, "cyclic attach (attaching to self)"); |
| 846 | |
| 847 | // attach to client if widget have it |
| 848 | if (_parent->getClientWidget()) |
| 849 | _parent = _parent->getClientWidget(); |
| 850 | |
| 851 | Widget* parent = _parent; |
| 852 | while (parent->getParent()) |
| 853 | { |
| 854 | MYGUI_ASSERT(parent != this, "cyclic attach"); |
| 855 | parent = parent->getParent(); |
| 856 | } |
| 857 | |
| 858 | detachFromWidget(); |
| 859 | |
| 860 | mWidgetStyle = _style; |
| 861 | |
| 862 | if (_style == WidgetStyle::Popup) |
| 863 | { |
| 864 | if (mParent == nullptr) |
| 865 | Gui::getInstance()._unlinkChildWidget(this); |
| 866 | else |
| 867 | mParent->_unlinkChildWidget(this); |
| 868 | |
| 869 | mParent = _parent; |
| 870 | mParent->_linkChildWidget(this); |
| 871 | |
| 872 | mCroppedParent = nullptr; |
| 873 | |
| 874 | if (!_layer.empty()) |
| 875 | { |
| 876 | LayerManager::getInstance().attachToLayerNode(_layer, this); |
| 877 | } |
| 878 | } |
| 879 | else if (_style == WidgetStyle::Child) |
| 880 | { |
| 881 | LayerManager::getInstance().detachFromLayer(this); |
| 882 | |
| 883 | if (mParent == nullptr) |
| 884 | Gui::getInstance()._unlinkChildWidget(this); |
| 885 | else |
| 886 | mParent->_unlinkChildWidget(this); |
| 887 | |
| 888 | mParent = _parent; |
| 889 | mParent->addChildItem(this); |
| 890 | mParent->_linkChildWidget(this); |
| 891 | |
| 892 | mCroppedParent = _parent; |
| 893 | mAbsolutePosition = _parent->getAbsolutePosition() + mCoord.point(); |
| 894 | |
| 895 | for (auto& widget : mWidgetChild) |
| 896 | widget->_updateAbsolutePoint(); |
| 897 | for (auto& widget : mWidgetChildSkin) |
| 898 | widget->_updateAbsolutePoint(); |
| 899 |
no test coverage detected