Add methods for getting the width and height of the widget

This commit is contained in:
Dave Pearson
2023-02-23 10:09:03 +00:00
parent a32a9fa6af
commit 2fbb64c27f

View File

@@ -172,6 +172,12 @@ class ToggleButton(Static, can_focus=True):
else Text.assemble(label, spacer, button)
)
def get_content_width(self, container: Size, viewport: Size) -> int:
return self._button.cell_len + (1 if self._label else 0) + self._label.cell_len
def get_content_height(self, container: Size, viewport: Size, width: int) -> int:
return 1
def toggle(self) -> None:
"""Toggle the value of the widget."""
self.value = not self.value