From c343de60314ed00d1924075654ac28606c0c9f3e Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Fri, 21 Mar 2025 10:45:07 +0700 Subject: [PATCH] Parenting callbacks in panels --- .../mc/otm/client/screen/panels/EditablePanel.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt index eb2c0aa02..530c92222 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt @@ -847,6 +847,12 @@ open class EditablePanel( childrenSortingInvalidated = true } + protected open fun onChildrenAdded(child: EditablePanel<*>) {} + protected open fun onChildrenRemoved(child: EditablePanel<*>) {} + + protected open fun onParented(parent: EditablePanel<*>) {} + protected open fun onUnParented(parent: EditablePanel<*>) {} + private fun onParent(child: EditablePanel<*>) { if (childrenInternal.contains(child)) throw IllegalStateException("Already containing $child") childrenInternal.add(child) @@ -864,11 +870,15 @@ open class EditablePanel( else updateVisibility = true } + + onChildrenAdded(child) + child.onParented(this) } private fun onUnParent(child: EditablePanel<*>) { val indexOf = childrenInternal.indexOf(child) if (indexOf == -1) throw IllegalStateException("Already not containing $child") + child.onUnParented(this) childrenInternal.removeAt(indexOf) invalidateChildrenSorting() @@ -880,6 +890,8 @@ open class EditablePanel( if (child.isVisible() != isVisible()) { updateVisible() } + + onChildrenRemoved(child) } private fun sortChildren() {