* Move the node above the provided node in the parent's layout. * * @remarks * The node will be moved above the provided node and from then on will be * rendered on top of it. By default, if the node is already positioned * higher than the sibling node, it will not get moved. *
(node: Node, directlyAbove = false)
| 930 | * already positioned above the sibling. |
| 931 | */ |
| 932 | public moveAbove(node: Node, directlyAbove = false): this { |
| 933 | const parent = this.parent(); |
| 934 | if (!parent) { |
| 935 | return this; |
| 936 | } |
| 937 | |
| 938 | if (node.parent() !== parent) { |
| 939 | useLogger().error( |
| 940 | "Cannot position nodes relative to each other if they don't belong to the same parent.", |
| 941 | ); |
| 942 | return this; |
| 943 | } |
| 944 | |
| 945 | const children = parent.children(); |
| 946 | const ownIndex = children.indexOf(this); |
| 947 | const otherIndex = children.indexOf(node); |
| 948 | |
| 949 | if (!directlyAbove && ownIndex > otherIndex) { |
| 950 | // Nothing to do if the node is already positioned above the target node. |
| 951 | // We could move the node so it's directly above the sibling node, but |
| 952 | // that might suddenly move it below other nodes. This is likely not what |
| 953 | // the user wanted to happen when calling this method. |
| 954 | return this; |
| 955 | } |
| 956 | |
| 957 | const by = otherIndex - ownIndex + 1; |
| 958 | |
| 959 | return this.move(by); |
| 960 | } |
| 961 | |
| 962 | /** |
| 963 | * Change the parent of this node while keeping the absolute transform. |