MCPcopy
hub / github.com/Textualize/textual / Size

Class Size

src/textual/geometry.py:192–317  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

190
191
192class 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.

Callers 15

resize_terminalMethod · 0.90
from_dimensionsMethod · 0.90
get_content_widthMethod · 0.90
get_content_heightMethod · 0.90
apply_dimensionsMethod · 0.90
WidgetClass · 0.90
__init__Method · 0.90
sizeMethod · 0.90
arrangeMethod · 0.90
get_content_heightMethod · 0.90
arrangeMethod · 0.90
arrangeMethod · 0.90

Calls

no outgoing calls

Tested by 15

test_borderFunction · 0.72
test_paddingFunction · 0.72
test_padding_borderFunction · 0.72
test_outlineFunction · 0.72
test_cropFunction · 0.72
test_dirty_cacheFunction · 0.72
test_content_boxFunction · 0.72
test_widthFunction · 0.72
test_heightFunction · 0.72
test_maxFunction · 0.72
test_minFunction · 0.72
test_resolve_emptyFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…