diff --git a/arcade/gui/surface.py b/arcade/gui/surface.py index 4f2f17b5c..d96dbc2d9 100644 --- a/arcade/gui/surface.py +++ b/arcade/gui/surface.py @@ -190,8 +190,11 @@ def activate(self) -> Generator[Self, None, None]: # Restore blend function. self.ctx.blend_func = prev_blend_func - def limit(self, rect: Rect): - """Reduces the draw area to the given rect""" + def limit(self, rect: Rect | None = None): + """Reduces the draw area to the given rect, or resets it to the full surface.""" + + if rect is None: + rect = LBWH(0, 0, *self.size) l, b, w, h = rect.lbwh w = max(w, 1) diff --git a/tests/unit/gui/test_surface.py b/tests/unit/gui/test_surface.py index 14501380b..fdfbb3a6b 100644 --- a/tests/unit/gui/test_surface.py +++ b/tests/unit/gui/test_surface.py @@ -1,6 +1,6 @@ import pytest -from arcade import load_texture +from arcade import LBWH, load_texture from arcade.gui import Surface, NinePatchTexture @@ -25,3 +25,14 @@ def keywords_only(**kwargs): with pytest.raises(NotImplementedError): keywords_only(alpha=10, angle=30.0) + + +def test_limit_surface(window): + surface = Surface(size=(100, 100)) + assert surface._cam.viewport == LBWH(0, 0, 100, 100) + + surface.limit(LBWH(10, 10, 80, 80)) + assert surface._cam.viewport == LBWH(10, 10, 80, 80) + + surface.limit(None) + assert surface._cam.viewport == LBWH(0, 0, 100, 100)