lifecycle & tree ctor -> mount <-> unmount -> destroy
| 6 | // lifecycle & tree |
| 7 | // ctor -> mount <-> unmount -> destroy |
| 8 | void Layer::mount(NotNull<Layer*> parent) SKR_NOEXCEPT |
| 9 | { |
| 10 | // validate |
| 11 | if (_parent != nullptr) |
| 12 | { |
| 13 | unmount(); |
| 14 | SKR_GUI_LOG_ERROR(u8"already mounted"); |
| 15 | } |
| 16 | { |
| 17 | Layer* node = parent; |
| 18 | while (node->_parent) |
| 19 | { |
| 20 | node = node->_parent; |
| 21 | if (node == this) |
| 22 | { |
| 23 | SKR_GUI_LOG_ERROR(u8"cycle in the tree"); |
| 24 | break; |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | // mount |
| 30 | _parent = parent; |
| 31 | if (parent->owner()) |
| 32 | { |
| 33 | struct _RecursiveHelper { |
| 34 | NotNull<BuildOwner*> owner; |
| 35 | |
| 36 | void operator()(NotNull<Layer*> obj) const SKR_NOEXCEPT |
| 37 | { |
| 38 | obj->attach(owner); |
| 39 | obj->visit_children(_RecursiveHelper{ owner }); |
| 40 | } |
| 41 | }; |
| 42 | _RecursiveHelper{ parent->owner() }(this); |
| 43 | } |
| 44 | } |
| 45 | void Layer::unmount() SKR_NOEXCEPT |
| 46 | { |
| 47 | // validate |
no outgoing calls
no test coverage detected