Add content_length method to LayoutView and container items

This commit is contained in:
Rapptz
2025-08-18 14:33:15 -04:00
parent e00bb0b0f3
commit f08c042217
4 changed files with 27 additions and 0 deletions

View File

@ -128,6 +128,12 @@ class Section(Item[V]):
def _has_children(self):
return True
def content_length(self) -> int:
""":class:`int`: Returns the total length of all text content in this section."""
from .text_display import TextDisplay
return sum(len(item.content) for item in self._children if isinstance(item, TextDisplay))
def add_item(self, item: Union[str, Item[Any]]) -> Self:
"""Adds an item to this section.