Skip to content

Commit 75429c0

Browse files
authored
feat(gui): allow reset of surface limit (#2423)
* feat(gui): allow reset of surface limit * fix import order
1 parent 47d40a0 commit 75429c0

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

arcade/gui/surface.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,11 @@ def activate(self) -> Generator[Self, None, None]:
190190
# Restore blend function.
191191
self.ctx.blend_func = prev_blend_func
192192

193-
def limit(self, rect: Rect):
194-
"""Reduces the draw area to the given rect"""
193+
def limit(self, rect: Rect | None = None):
194+
"""Reduces the draw area to the given rect, or resets it to the full surface."""
195+
196+
if rect is None:
197+
rect = LBWH(0, 0, *self.size)
195198

196199
l, b, w, h = rect.lbwh
197200
w = max(w, 1)

tests/unit/gui/test_surface.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from arcade import load_texture
3+
from arcade import LBWH, load_texture
44
from arcade.gui import Surface, NinePatchTexture
55

66

@@ -25,3 +25,14 @@ def keywords_only(**kwargs):
2525

2626
with pytest.raises(NotImplementedError):
2727
keywords_only(alpha=10, angle=30.0)
28+
29+
30+
def test_limit_surface(window):
31+
surface = Surface(size=(100, 100))
32+
assert surface._cam.viewport == LBWH(0, 0, 100, 100)
33+
34+
surface.limit(LBWH(10, 10, 80, 80))
35+
assert surface._cam.viewport == LBWH(10, 10, 80, 80)
36+
37+
surface.limit(None)
38+
assert surface._cam.viewport == LBWH(0, 0, 100, 100)

0 commit comments

Comments
 (0)