@@ -29,6 +29,17 @@ def __init__(self) -> None:
2929 """Shrink the grid to fit the container if it is larger."""
3030 self .auto_minimum : bool = False
3131 """If self.shrink is `True`, auto-detect and limit the width."""
32+ self ._grid_size : tuple [int , int ] | None = None
33+ """Grid size after last arrange call."""
34+
35+ @property
36+ def grid_size (self ) -> tuple [int , int ] | None :
37+ """The grid size after the last arrange call.
38+
39+ Returns:
40+ A tuple of (WIDTH, HEIGHT) or `None` prior to the first `arrange`.
41+ """
42+ return self ._grid_size
3243
3344 def arrange (
3445 self , parent : Widget , children : list [Widget ], size : Size , greedy : bool = True
@@ -60,6 +71,7 @@ def arrange(
6071 table_size_columns -= 1
6172
6273 table_size_rows = styles .grid_size_rows
74+
6375 viewport = parent .app .viewport_size
6476 keyline_style , _keyline_color = styles .keyline
6577 offset = (0 , 0 )
@@ -157,9 +169,9 @@ def repeat_scalars(scalars: Iterable[Scalar], count: int) -> list[Scalar]:
157169 cell_coord = next_coord ()
158170
159171 column_scalars = repeat_scalars (column_scalars , table_size_columns )
160- row_scalars = repeat_scalars (
161- row_scalars , table_size_rows if table_size_rows else row + 1
162- )
172+ table_size_rows = table_size_rows if table_size_rows else row + 1
173+ row_scalars = repeat_scalars ( row_scalars , table_size_rows )
174+ self . _grid_size = ( table_size_columns , table_size_rows )
163175
164176 def apply_width_limits (widget : Widget , width : int ) -> int :
165177 """Apply min and max widths to dimension.
0 commit comments