The dimensions (width and height) of a rectangular region. Example: ```python >>> from textual.geometry import Size >>> size = Size(2, 3) >>> size Size(width=2, height=3) >>> size.area 6 >>> size + Size(10, 20) Size(width=1
| 190 | |
| 191 | |
| 192 | class Size(NamedTuple): |
| 193 | """The dimensions (width and height) of a rectangular region. |
| 194 | |
| 195 | Example: |
| 196 | ```python |
| 197 | >>> from textual.geometry import Size |
| 198 | >>> size = Size(2, 3) |
| 199 | >>> size |
| 200 | Size(width=2, height=3) |
| 201 | >>> size.area |
| 202 | 6 |
| 203 | >>> size + Size(10, 20) |
| 204 | Size(width=12, height=23) |
| 205 | ``` |
| 206 | """ |
| 207 | |
| 208 | width: int = 0 |
| 209 | """The width in cells.""" |
| 210 | |
| 211 | height: int = 0 |
| 212 | """The height in cells.""" |
| 213 | |
| 214 | def __bool__(self) -> bool: |
| 215 | """A Size is Falsy if it has area 0.""" |
| 216 | return self.width * self.height != 0 |
| 217 | |
| 218 | @property |
| 219 | def area(self) -> int: |
| 220 | """The area occupied by a region of this size.""" |
| 221 | return self.width * self.height |
| 222 | |
| 223 | @property |
| 224 | def region(self) -> Region: |
| 225 | """A region of the same size, at the origin.""" |
| 226 | width, height = self |
| 227 | return Region(0, 0, width, height) |
| 228 | |
| 229 | @property |
| 230 | def line_range(self) -> range: |
| 231 | """A range object that covers values between 0 and `height`.""" |
| 232 | return range(self.height) |
| 233 | |
| 234 | def with_width(self, width: int) -> Size: |
| 235 | """Get a new Size with just the width changed. |
| 236 | |
| 237 | Args: |
| 238 | width: New width. |
| 239 | |
| 240 | Returns: |
| 241 | New Size instance. |
| 242 | """ |
| 243 | return Size(width, self.height) |
| 244 | |
| 245 | def with_height(self, height: int) -> Size: |
| 246 | """Get a new Size with just the height changed. |
| 247 | |
| 248 | Args: |
| 249 | height: New height. |
no outgoing calls
searching dependent graphs…