Add a swap method for dynamic item's dispatching

This commit is contained in:
DA344
2025-08-21 00:52:31 +02:00
committed by GitHub
parent b2aab86ba1
commit 0309aac335
5 changed files with 26 additions and 3 deletions

View File

@ -50,6 +50,7 @@ if TYPE_CHECKING:
from ..components import Container as ContainerComponent
from ..interactions import Interaction
from .dynamic import DynamicItem
S = TypeVar('S', bound='Container', covariant=True)
V = TypeVar('V', bound='LayoutView', covariant=True)
@ -198,6 +199,10 @@ class Container(Item[V]):
def _has_children(self):
return True
def _swap_item(self, base: Item, new: DynamicItem, custom_id: str) -> None:
child_index = self._children.index(base)
self._children[child_index] = new # type: ignore
@property
def children(self) -> List[Item[V]]:
"""List[:class:`Item`]: The children of this container."""